| Title: | Korean Morphological Analysis and Hangul Utilities |
|---|---|
| Description: | Provides Korean morphological analysis, part-of-speech (POS) tagging, noun extraction, Hangul (Korean script) conversion utilities, concordance search, mutual information statistics, and user dictionary management tools for Korean text research. The morphological analyzer backend is derived from the 'KoNLP' package and the 'HanNanum' analyzer, and is reimplemented in native C so that no Java runtime is required. Bundled dictionary and statistical resources allow analysis to work out of the box, and optional dictionaries can be loaded at runtime from the 'Sejong' and 'NIADic' packages when they are installed and loaded. |
| Authors: | Jonghyeon Park [aut, cre], Heewon Jeon [aut], Taekyung Kim [ctb], Semantic Web Research Center, KAIST [cph] (Copyright details and third-party contributors are documented in inst/COPYRIGHTS.) |
| Maintainer: | Jonghyeon Park <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-10-01 11:05:38 UTC |
| Source: | https://github.com/shapelayer/hannlp |
Backup the writable HanNLP user dictionary.
backupUsrDic(ask = TRUE)backupUsrDic(ask = TRUE)
ask |
ask to confirm backup |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible logical
Build the writable HanNLP user dictionary from user-supplied entries and optional external sources. The Sejong dictionary is read from the installed Sejong package or the path specified by HANNLP_SEJONG_HANDIC. The woorimalsam and insighter dictionaries require the optional NIADic package to be installed and loaded (library(NIADic)) in the current session; HanNLP does not bundle NIADic data.
buildDictionary( ext_dic = "", category_dic_nms = "", user_dic = data.frame(), replace_usr_dic = FALSE, verbose = FALSE )buildDictionary( ext_dic = "", category_dic_nms = "", user_dic = data.frame(), replace_usr_dic = FALSE, verbose = FALSE )
ext_dic |
optional external dictionary names: |
category_dic_nms |
retained for KoNLP API compatibility |
user_dic |
user dictionary data.frame with term and KAIST tag columns |
replace_usr_dic |
replace existing user dictionary instead of appending |
verbose |
print detail progress |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible data.frame of the resulting user dictionary
Return concordance text for an input file.
concordance_file(filename, pattern, encoding = getOption("encoding"), span = 5)concordance_file(filename, pattern, encoding = getOption("encoding"), span = 5)
filename |
file name |
pattern |
pattern of central words |
encoding |
file encoding |
span |
number of characters to include around each match |
character vector of matched concordance strings
Return concordance text for an input pattern and span.
concordance_str(string, pattern, span = 5)concordance_str(string, pattern, span = 5)
string |
input text as character vector or single character |
pattern |
pattern of central words |
span |
number of characters to include around each match |
list of matched concordance strings, with empty elements removed
Convert Hangul syllables to compatibility Jamo sequences.
convertHangulStringToJamos(hangul)convertHangulStringToJamos(hangul)
hangul |
Hangul string |
Jamo sequences
hangul <- intToUtf8(c(0xd55c, 0xae00)) convertHangulStringToJamos(hangul)hangul <- intToUtf8(c(0xd55c, 0xae00)) convertHangulStringToJamos(hangul)
Convert Hangul syllables to two-beolsik keystroke sequences.
convertHangulStringToKeyStrokes(hangul, isFullwidth = TRUE)convertHangulStringToKeyStrokes(hangul, isFullwidth = TRUE)
hangul |
Hangul sentence |
isFullwidth |
specify returned character will be Fullwidth ASCII or Halfwidth ASCII |
Keystroke sequence
Convert tags between KAIST and Sejong tag sets.
convertTag(fromTag, toTag, tag)convertTag(fromTag, toTag, tag)
fromTag |
tag set name to convert from, either |
toTag |
desired tag set name, either |
tag |
tag name to search |
converted tag vector
convertTag("K", "S", "ncn")convertTag("K", "S", "ncn")
KoNLP-compatible edit weight metadata. HanNLP does not use this table in runtime algorithms yet.
A 66 by 66 numeric matrix of edit (substitution) costs indexed by keystroke characters on both dimensions.
A 66 by 66 numeric matrix of keystroke edit costs.
Derived from the edit weight table distributed with 'KoNLP'.
Extract nouns from Korean sentences using the native HanNLP analyzer backend.
extractNoun(sentences, autoSpacing = FALSE)extractNoun(sentences, autoSpacing = FALSE)
sentences |
input character vector |
autoSpacing |
retained for KoNLP API compatibility; currently ignored |
character vector for one sentence, list for multiple sentences
local({ old <- Sys.getenv("HANNLP_USER_DATA_DIR", unset = NA) tmp <- tempfile("hannlp-user-data-") on.exit({ if (is.na(old)) Sys.unsetenv("HANNLP_USER_DATA_DIR") else Sys.setenv(HANNLP_USER_DATA_DIR = old) unlink(tmp, recursive = TRUE, force = TRUE) }) Sys.setenv(HANNLP_USER_DATA_DIR = tmp) text <- intToUtf8(c(0xd55c, 0xae00, 0x20, 0xd615, 0xd0dc, 0xc18c)) extractNoun(text) })local({ old <- Sys.getenv("HANNLP_USER_DATA_DIR", unset = NA) tmp <- tempfile("hannlp-user-data-") on.exit({ if (is.na(old)) Sys.unsetenv("HANNLP_USER_DATA_DIR") else Sys.setenv(HANNLP_USER_DATA_DIR = old) unlink(tmp, recursive = TRUE, force = TRUE) }) Sys.setenv(HANNLP_USER_DATA_DIR = tmp) text <- intToUtf8(c(0xd55c, 0xae00, 0x20, 0xd615, 0xd0dc, 0xc18c)) extractNoun(text) })
Return a HanNLP dictionary as a data.frame. The external Sejong dictionary requires an installed source package or a configured file path. The NIADic-based dictionaries require the loaded optional NIADic package.
get_dictionary(dic_name)get_dictionary(dic_name)
dic_name |
one of |
data.frame with dictionary terms and tags
Compose complete Hangul syllables from compatibility Jamo or two-beolsik keystroke sequences.
HangulAutomata(input, isKeystroke = FALSE, isForceConv = FALSE)HangulAutomata(input, isKeystroke = FALSE, isForceConv = FALSE)
input |
input Jamo sequences or two-beolsik keystrokes |
isKeystroke |
whether input is two-beolsik keystrokes instead of Jamo |
isForceConv |
force conversion for incomplete sequences |
complete Hangul syllable string
Check whether each input string contains only ASCII characters.
is.ascii(sentence)is.ascii(sentence)
sentence |
input characters |
logical vector
Check whether each input string contains only Hangul syllables or compatibility Jamo.
is.hangul(sentence)is.hangul(sentence)
sentence |
input characters |
logical vector
hangul <- intToUtf8(c(0xd55c, 0xae00)) is.hangul(c(hangul, "abc"))hangul <- intToUtf8(c(0xd55c, 0xae00)) is.hangul(c(hangul, "abc"))
Check whether each input string contains only Korean consonant Jamo.
is.jaeum(sentence)is.jaeum(sentence)
sentence |
input characters |
logical vector
Check whether each input string contains only compatibility Jamo.
is.jamo(sentence)is.jamo(sentence)
sentence |
input characters |
logical vector
Check whether each input string contains only Korean vowel Jamo.
is.moeum(sentence)is.moeum(sentence)
sentence |
input characters |
logical vector
KoNLP-compatible mapping from KAIST tags to Sejong tags.
A named character vector whose names are KAIST tag names and whose values are the corresponding Sejong tag names.
A named character vector mapping KAIST tags to Sejong tags.
Derived from the tag mapping distributed with 'KoNLP'.
Append to or replace the writable HanNLP user dictionary.
mergeUserDic(newUserDic, append = TRUE, verbose = FALSE, ask = FALSE)mergeUserDic(newUserDic, append = TRUE, verbose = FALSE, ask = FALSE)
newUserDic |
new user dictionary as data.frame |
append |
append to existing dictionary or replace it |
verbose |
retained for KoNLP API compatibility |
ask |
ask to backup current dictionary |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible data.frame of the resulting user dictionary
Analyze Korean sentences using the native HanNLP analyzer backend.
MorphAnalyzer(sentences, autoSpacing = FALSE)MorphAnalyzer(sentences, autoSpacing = FALSE)
sentences |
input character vector |
autoSpacing |
retained for KoNLP API compatibility; currently ignored |
named list of eojeol to morpheme/tag strings for one sentence, list for multiple sentences
text <- intToUtf8(c(0xd55c, 0xae00, 0x20, 0xd615, 0xd0dc, 0xc18c)) MorphAnalyzer(text)text <- intToUtf8(c(0xd55c, 0xae00, 0x20, 0xd615, 0xd0dc, 0xc18c)) MorphAnalyzer(text)
Return mutual information or t-scores for adjacent word bigrams.
mutualinformation(text, query = "", method = c("mutual", "tscores"))mutualinformation(text, query = "", method = c("mutual", "tscores"))
text |
input character vector |
query |
term to filter bigrams |
method |
calculation method, either |
named numeric vector
HanNLP loads dictionaries per analysis call, so this function is retained for KoNLP API compatibility.
reloadAllDic()reloadAllDic()
invisible TRUE
Compatibility wrapper for reloading user dictionaries.
reloadUserDic(whichDics)reloadUserDic(whichDics)
whichDics |
character vector of dictionary consumers |
invisible TRUE
Restore the writable HanNLP user dictionary from backup.
restoreUsrDic(ask = TRUE)restoreUsrDic(ask = TRUE)
ask |
ask to confirm restore |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible logical
Tag Korean sentences using 9 KAIST tags with the native HanNLP analyzer backend.
SimplePos09(sentences, autoSpacing = FALSE)SimplePos09(sentences, autoSpacing = FALSE)
sentences |
input character vector |
autoSpacing |
retained for KoNLP API compatibility; currently ignored |
named list of eojeol to morpheme/tag strings for one sentence, list for multiple sentences
Tag Korean sentences using 22 KAIST tags with the native HanNLP analyzer backend.
SimplePos22(sentences, autoSpacing = FALSE)SimplePos22(sentences, autoSpacing = FALSE)
sentences |
input character vector |
autoSpacing |
retained for KoNLP API compatibility; currently ignored |
named list of eojeol to morpheme/tag strings for one sentence, list for multiple sentences
Show summary, head, and tail of current or backup user dictionaries.
statDic(which = "current", n = 6)statDic(which = "current", n = 6)
which |
one of |
n |
number of rows for head and tail |
list containing summary, head, and tail
KoNLP-compatible mapping from Sejong tags to KAIST tags.
A named character vector whose names are Sejong tag names and whose values are the corresponding KAIST tag names.
A named character vector mapping Sejong tags to KAIST tags.
Derived from the tag mapping distributed with 'KoNLP'.
KoNLP-compatible KAIST/HanNanum tag names used by HanNLP dictionary utilities.
A named character vector mapping each supported tag name to itself, used to validate tag entries.
A named character vector of supported tag names.
Derived from the KAIST/HanNanum tag set distributed with 'KoNLP'.
Replace the writable user dictionary with NIADic entries. HanNLP does not bundle or distribute NIADic data because it is released under CC BY-SA, which is incompatible with the GPL. This function works only when the optional NIADic package is installed and its namespace is already loaded in the current R session (e.g. after library(NIADic)); otherwise it errors.
useNIADic( which_dic = c("woorimalsam", "insighter"), category_dic_nms = "all", backup = TRUE )useNIADic( which_dic = c("woorimalsam", "insighter"), category_dic_nms = "all", backup = TRUE )
which_dic |
NIADic dictionaries to load: |
category_dic_nms |
retained for KoNLP API compatibility |
backup |
backup current dictionary before switching |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible data.frame of the resulting user dictionary
Replace the writable user dictionary with Sejong dictionary entries from an installed Sejong package or HANNLP_SEJONG_HANDIC.
useSejongDic(backup = TRUE)useSejongDic(backup = TRUE)
backup |
backup current dictionary before switching |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible result
Restore the writable user dictionary to HanNLP's bundled default user dictionary.
useSystemDic(backup = TRUE)useSystemDic(backup = TRUE)
backup |
backup current dictionary before switching |
Before writing dictionary files, explicitly set the environment variable
HANNLP_USER_DATA_DIR to the desired directory. There is no default
writable directory. Backups are stored in its ‘backup’ subdirectory.
For temporary use, choose a directory under tempdir().
invisible TRUE