title: R client
Using Bareun from R
Use RBareun for morphological analysis, spelling and grammar correction, homonym sense disambiguation, and Urimalsaem (Open Korean Dictionary) phoneme search.
- Repository: RBareun
- Current version: 1.3.0
Installation
It is not on CRAN yet. Install it from GitHub.
install.packages(c("curl", "httr", "jsonlite"))
library(devtools)
devtools::install_github("bareun-nlp/RBareun")
What you need
- A running Bareun server. The default port is 5658 for a local install and 5656 for Docker.
- An API key. It starts with
koba-. How to get one
library(bareun)
set_api("koba-...", "localhost", 5656)
Spelling and grammar correction and Urimalsaem phoneme search work only on a server that includes the spell-check feature.
Morphological analysis
t <- tagger("결과를 문자열로 바꾼다.")
pos(t)
#> [[1]]
#> [1] "결과/NNG" "를/JKO" "문자열/NNG" "로/JKB" "바꾸/VV" "ㄴ다/EF" "./SF"
morphs(t)
#> [[1]]
#> [1] "결과" "를" "문자열" "로" "바꾸" "ㄴ다" "."
nouns(t)
#> [[1]]
#> [1] "결과" "문자열"
verbs(t)
#> [[1]]
#> [1] "바꾸"
Separate multiple sentences with line breaks.
t <- tagger("문장을 입력합니다.\n여러 문장을 넣습니다.")
Custom dictionary
t <- tagger("문장", custom_dict_names = c("mydict"))
When you pass several, the earlier one takes priority. To learn how to create a dictionary, see the custom dictionary API.
Spelling and grammar correction
r <- correct_grammar("이거 안되요. 학교에 갔읍니다.")
revised_text(r)
#> [1] "이거 안되요. 학교에 갔습니다."
revisions(r)
#> origin revised category help
#> 1 갔읍니다. 갔습니다. STANDARD STANDARD-읍니다
You can also pass options to the corrector.
correct_grammar("제목처럼 다룬다", treat_as_title = TRUE)
For details, see the spell check API.
Homonym sense disambiguation
When the same characters can have several meanings, it picks which meaning is intended.
t <- tagger("나는 밤에 밤을 먹었다.", with_sense = TRUE)
senses(t)
#> sentence morph tag sense_no meaning probability
#> 1 1 밤 NNG 2 밤나무의 열매. ... 0.5513565
#> 3 1 먹 VV 2 음식 따위를 입을 통하여 ... 0.9777783
Morphemes that carry no meaning, such as particles (josa) and endings (eomi), have no sense attached to begin with, so most morphemes do not appear in the table. See the homonym sense disambiguation API.
Urimalsaem phoneme search
With precomposed Hangul syllables, you cannot write a condition such as "a syllable whose initial consonant is ㅅ and whose final consonant is ㄴ".
dict_words(search_dict("{ㅅ//ㄴ}다", pos = "동사"))
#> [1] "신다"
dict_words(search_dict("아지", anchor = "suffix", limit = 5))
#> [1] "아지" "가아지" "강아지" "개아지" "갱아지"
Choose anchor from word (default), prefix, suffix, and contains.
For the pattern syntax, see the Urimalsaem phoneme search API.
Error handling
When a server call fails, a condition that tells the kinds apart is raised.
tryCatch(
correct_grammar("문장"),
bareun_auth_error = function(e) message("Check your API key"),
bareun_connection_error = function(e) message("Check the server address")
)
| Class | When |
|---|---|
bareun_connection_error | Could not reach the server: wrong address, server not running, firewall |
bareun_auth_error | The API key is missing or invalid, or the license has expired |
bareun_unimplemented_error | A feature the server does not provide |
bareun_server_error | Internal server error |
bareun_request_error | Any other request error |
bareun_argument_error | An argument is wrong. It is caught before the server is called |
What changed from 1.2.0
| 1.2.0 | 1.3.0 |
|---|---|
| Morphological analysis and custom dictionary | + correction, sense disambiguation, phoneme search |
| All errors look the same | Told apart by condition class |
| No tests | 50 testthat tests |
Existing functions are used the same way as before. tagger() gained the with_sense and
custom_dict_names arguments.
Frequently asked questions
Q. Can't I install it from CRAN?
A. It is not registered yet. Install it with devtools::install_github().
Q. I called the correction function and got a "not provided" error.
A. The server does not have the spell-check feature. Correction and phoneme search work only on a server
that includes the spell-check feature. You can tell this case apart with bareun_unimplemented_error.
Q. I used with_sense = TRUE but senses() is empty.
A. The server must have the sense disambiguation model loaded. Also, morphemes without ambiguity
get no sense attached, so the result can be empty for short sentences.