Skip to content

Commit

Permalink
Merge pull request #10 from mrchypark/cpp11-package
Browse files Browse the repository at this point in the history
change to cpp11 package
  • Loading branch information
mrchypark authored Mar 30, 2022
2 parents f5d4b80 + 291b4dc commit 72c225a
Show file tree
Hide file tree
Showing 60 changed files with 3,427 additions and 2,176 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ auto*
inst/ModelGenerator*
^\.github$
^_pkgdown\.yml$
kiwilibtmp/*
kiwilibs/*
^model*
^windows/*
^tools/winbuild*
4 changes: 1 addition & 3 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ jobs:
- {os: macOS-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
- {os: windows-latest, r: 'oldrel-1'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-18.04, r: 'oldrel-1'}
- {os: ubuntu-18.04, r: 'oldrel-2'}
- {os: ubuntu-18.04, r: 'oldrel-3'}
- {os: ubuntu-18.04, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
install.packages('remotes')
remotes::install_deps(dependencies = TRUE)
install.packages("pkgdown", type = "binary")
install.packages("pkgdown")
packageVersion("pkgdown")
remotes::install_github("amirmasoudabdol/preferably", type = "source")
packageVersion("preferably")
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/pkgdown.yml

This file was deleted.

41 changes: 0 additions & 41 deletions .github/workflows/readme.yml

This file was deleted.

9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
.RData
config.log
config.status
Kiwi*
^Kiwi*
src/Makevars
inst/ModelGenerator*
inst/*
inst/model/*
kiwilibs/*
kiwilibtmp/*
kiwi-model.tgz
model*
windows/*
23 changes: 16 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Package: elbird
Title: Blazing Fast Morphological Analyzer based on kiwi(Korean Intelligent Word Identifier)
Title: Blazing Fast Morphological Analyzer Based on Kiwi(Korean Intelligent Word Identifier)
Version: 0.1.0
Authors@R: person(given = "Chanyub",
family = "Park",
role = c("aut","cre"),
email = "mrchypark@gmail.com",
comment = c(ORCID = "0000-0001-6474-2570"))
Description: This is the R wrapper package Kiwi(Korean Intelligent Word Identifier), a blazing fast speed morphological analyzer for Korean.
It supports configuration of user dictionary and detection of unregistered nouns based on frequency.
Description: This is the R wrapper package Kiwi(Korean Intelligent Word Identifier),
a blazing fast speed morphological analyzer for Korean.
It supports configuration of user dictionary and detection of
unregistered nouns based on frequency.
License: LGPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand All @@ -16,10 +18,17 @@ URL: https://github.com/mrchypark/elbird/
BugReports: https://github.com/mrchypark/elbird/issues
SystemRequirements: c("C++11", "git", "wget", "cmake")
Depends:
R (>= 3.3)
LazyData: true
R (>= 3.5)
Imports:
dplyr,
purrr,
methods,
tibble
tibble,
R6 (>= 2.4.0),
vroom,
matchr
LinkingTo:
cpp11
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Config/testthat/parallel: true
23 changes: 15 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# Generated by roxygen2: do not edit by hand

export(Kiwi)
export(Match)
export(Stopwords)
export(Tags)
export(analyze)
export(kiwi_model_path)
export(model_is_set)
export(get_model)
export(model_exists)
export(model_home)
export(model_works)
export(split_into_sents)
export(tokenize)
export(tokenize_tbl)
export(tokenize_tibble)
export(tokenize_tidy)
export(tokenize_tidytext)
export(tokenize_tt)
importFrom(R6,R6Class)
importFrom(dplyr,anti_join)
importFrom(dplyr,bind_rows)
importFrom(methods,new)
importFrom(dplyr,mutate)
importFrom(matchr,Enum)
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,map_int)
importFrom(tibble,tibble)
importFrom(utils,download.file)
importFrom(utils,untar)
importFrom(vroom,vroom)
importFrom(vroom,vroom_write)
useDynLib(elbird, .registration = TRUE)
useDynLib(elbird,kiwi_analyze_)
useDynLib(elbird,kiwi_clear_error_)
useDynLib(elbird,kiwi_error_)
useDynLib(elbird,kiwi_init_)
useDynLib(elbird,kiwi_version_)
35 changes: 24 additions & 11 deletions R/analyze.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#' analyze
#'
#' @param text target text.
#' @param top_n Number of result. default is 3.
#' @name analyze
#' @param top_n \code{integer}: Number of result. Default is 3.
#' @inheritParams tokenize
#' @examples
#' \dontrun{
#' analyze("Test text.")
#' analyze("Please use Korean.", top_n = 1)
#' analyze("Test text.", 1, Match$ALL_WITH_NORMALIZING)
#' analyze("Test text.", stopwords = FALSE)
#' analyze("Test text.", stopwords = TRUE)
#' analyze("Test text.", stopwords = "user_dict.txt")
#' analyze("Test text.", stopwords = Stopwords$new(TRUE))
#' }
#' @export
analyze <- function(text, top_n = 3) {
if (init_chk_not())
init()
analyze <-
function(text,
top_n = 3,
match_option = Match$ALL,
stopwords = FALSE) {
if (init_chk_not())
init()

return(
kiwi_analyze(
kiwi_analyze_wrap(
get("kb", envir = .el),
text,
top_n, 1
top_n,
match_option,
stopwords
)
)
}
}
Empty file removed R/class.R
Empty file.
73 changes: 73 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generated by cpp11: do not edit by hand

kiwi_version_ <- function() {
.Call(`_elbird_kiwi_version_`)
}

kiwi_error_ <- function() {
.Call(`_elbird_kiwi_error_`)
}

kiwi_clear_error_ <- function() {
invisible(.Call(`_elbird_kiwi_clear_error_`))
}

kiwi_builder_close_ <- function(handle_ex) {
.Call(`_elbird_kiwi_builder_close_`, handle_ex)
}

kiwi_builder_init_ <- function(model_path, num_threads, options) {
.Call(`_elbird_kiwi_builder_init_`, model_path, num_threads, options)
}

kiwi_builder_add_word_ <- function(handle_ex, word, pos, score) {
.Call(`_elbird_kiwi_builder_add_word_`, handle_ex, word, pos, score)
}

kiwi_builder_add_alias_word_ <- function(handle_ex, alias, pos, score, orig_word) {
.Call(`_elbird_kiwi_builder_add_alias_word_`, handle_ex, alias, pos, score, orig_word)
}

kiwi_builder_add_pre_analyzed_word_ <- function(handle_ex, form, analyzed_r, score) {
.Call(`_elbird_kiwi_builder_add_pre_analyzed_word_`, handle_ex, form, analyzed_r, score)
}

kiwi_builder_load_dict_ <- function(handle_ex, dict_path) {
.Call(`_elbird_kiwi_builder_load_dict_`, handle_ex, dict_path)
}

kiwi_close_ <- function(handle_ex) {
.Call(`_elbird_kiwi_close_`, handle_ex)
}

kiwi_builder_extract_words_ <- function(handle_ex, input, min_cnt, max_word_len, min_score, pos_threshold) {
.Call(`_elbird_kiwi_builder_extract_words_`, handle_ex, input, min_cnt, max_word_len, min_score, pos_threshold)
}

kiwi_builder_extract_add_words_ <- function(handle_ex, input, min_cnt, max_word_len, min_score, pos_threshold) {
.Call(`_elbird_kiwi_builder_extract_add_words_`, handle_ex, input, min_cnt, max_word_len, min_score, pos_threshold)
}

kiwi_builder_build_ <- function(handle_ex) {
.Call(`_elbird_kiwi_builder_build_`, handle_ex)
}

kiwi_init_ <- function(model_path, num_threads, options) {
.Call(`_elbird_kiwi_init_`, model_path, num_threads, options)
}

kiwi_set_option_ <- function(handle_ex, option, value) {
invisible(.Call(`_elbird_kiwi_set_option_`, handle_ex, option, value))
}

kiwi_get_option_ <- function(handle_ex, option) {
.Call(`_elbird_kiwi_get_option_`, handle_ex, option)
}

kiwi_analyze_ <- function(handle_ex, text, top_n, match_options, stopwords_r) {
.Call(`_elbird_kiwi_analyze_`, handle_ex, text, top_n, match_options, stopwords_r)
}

kiwi_split_into_sents_ <- function(handle_ex, text, match_options, return_tokens) {
.Call(`_elbird_kiwi_split_into_sents_`, handle_ex, text, match_options, return_tokens)
}
17 changes: 17 additions & 0 deletions R/dictionary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dict_path <- function() {
path <- Sys.getenv("ELBIRD_DICTIONARY_HOME")
if (nzchar(path)) {
normalizePath(path, mustWork = FALSE)
} else {
normalizePath(file.path(system.file("", package = "elbird"), "dicts"),
mustWork = FALSE)
}
}

dict_stopwords_path <- function() {
normalizePath(file.path(dict_path(), "stopwords.txt"), mustWork = FALSE)
}

dict_user_path <- function() {
normalizePath(file.path(dict_path(), "stopwords.txt"), mustWork = FALSE)
}
19 changes: 9 additions & 10 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ init_chk_not <- function() {
length(ls(envir = .el)) != 1
}

#' @importFrom methods new
init <- function() {
if (!model_exists())
get_model_file()
init <- function(size = "small") {
if (!kiwi_model_exists(size))
get_kiwi_models(size)

kb <- kiwi_init(model_path_full(), 0, 0)
kb <- kiwi_init_(kiwi_model_path_full(size), 0, BuildOpt$DEFAULT)
err <- kiwi_error_wrap()

if (identical(kb, new("externalptr"))) {
tem <- kiwi_error()
kiwi_clear_error()
stop(tem)
}
if (!is.null(err))
stop(err)

assign("kb", kb, envir = .el)
}



Loading

0 comments on commit 72c225a

Please sign in to comment.