| Title: | Read and Parse Chinese Input-Method Dictionaries |
|---|---|
| Description: | Read Chinese input-method dictionary files into a common 'R' data model. The 'Rust' backend supports Sogou, QQ Pinyin, and Baidu dictionary formats and preserves source metadata, code components, and weights. This is useful for building a custom Chinese word segmentation dictionary. |
| Authors: | Hao Cheng [aut, cre, cph] |
| Maintainer: | Hao Cheng <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-08-27 01:12:09 UTC |
| Source: | https://github.com/Yousa-Mirage/r-cidian |
Convert a dictionary to a data frame
## S3 method for class 'cidian_dictionary' as.data.frame(x, ...)## S3 method for class 'cidian_dictionary' as.data.frame(x, ...)
x |
A |
... |
Must be empty. |
A base data.frame with word, code, and weight columns.
code is a list-column of character vectors and weight is numeric.
## Not run: dictionary <- read_cidian("computer.qcel") as.data.frame(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") as.data.frame(dictionary) ## End(Not run)
Extract dictionary entries
cidian_entries(x)cidian_entries(x)
x |
A |
A base data.frame with word, code, and weight columns.
code is a list-column of character vectors and weight is numeric.
## Not run: dictionary <- read_cidian("computer.qcel") cidian_entries(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") cidian_entries(dictionary) ## End(Not run)
List supported dictionary formats
cidian_formats()cidian_formats()
A character vector of format identifiers accepted by
read_cidian().
cidian_formats()cidian_formats()
Extract dictionary metadata
cidian_metadata(x)cidian_metadata(x)
x |
A |
A list with name, category, description, and extra fields.
## Not run: dictionary <- read_cidian("computer.qcel") cidian_metadata(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") cidian_metadata(dictionary) ## End(Not run)
Print a dictionary summary
## S3 method for class 'cidian_dictionary' print(x, ...)## S3 method for class 'cidian_dictionary' print(x, ...)
x |
A |
... |
Must be empty. |
## Not run: dictionary <- read_cidian("computer.qcel") print(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") print(dictionary) ## End(Not run)
read_cidian() reads a supported binary dictionary and returns a common
cidian_dictionary object. The parser preserves source order and does
not normalize, sort, or deduplicate entries.
read_cidian(path, ..., format = c("scel", "qcel", "qpyd", "bdict", "bcd"))read_cidian(path, ..., format = c("scel", "qcel", "qpyd", "bdict", "bcd"))
path |
A path to a dictionary file. |
... |
Must be empty. |
format |
A format name, with or without a leading dot. Supported
values are |
The format is inferred from the file extension when format is omitted or
NULL. Supply format when the file has no extension or its extension is
wrong.
A cidian_dictionary object containing metadata, entries, and
format fields. The entries$code column is a list-column of character
vectors, and entries$weight is a numeric vector.
## Not run: dictionary <- read_cidian("computer.qcel") dictionary as.data.frame(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") dictionary as.data.frame(dictionary) ## End(Not run)
Summarize a dictionary
## S3 method for class 'cidian_dictionary' summary(object, ...)## S3 method for class 'cidian_dictionary' summary(object, ...)
object |
A |
... |
Must be empty. |
An object of class summary.cidian_dictionary containing the
format, metadata, entry count, and number of weighted entries.
## Not run: dictionary <- read_cidian("computer.qcel") summary(dictionary) ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") summary(dictionary) ## End(Not run)
write_words() writes the word of every entry in x to path,
one word per line, preserving the source order.
write_words(x, path, ..., overwrite = NULL)write_words(x, path, ..., overwrite = NULL)
x |
A |
path |
A path to the output file. |
... |
Must be empty. |
overwrite |
Whether to replace |
When path already exists, the function asks for confirmation unless
overwrite is given explicitly.
The path, invisibly.
## Not run: dictionary <- read_cidian("computer.qcel") write_words(dictionary, "words.txt") ## End(Not run)## Not run: dictionary <- read_cidian("computer.qcel") write_words(dictionary, "words.txt") ## End(Not run)