Learn R Programming

flashlighttext (version 0.1.0)

KenLM: KenLM

Description

KenLM

KenLM

Arguments

Super class

flashlighttext::LM -> KenLM

Active bindings

path

returns a string

usrTknDict

returns a string vector

Methods

Public methods

Inherited methods


Method new()

Usage

KenLM$new(path = NULL, usrTknDict = NULL)

Arguments

path

a character string representing the path to the binary file containing the language model.

usrTknDict

a Dictionary instance populated with user-defined tokens.

Returns

An instance of the KenLM class.

Examples

library(flashlighttext)
sys_file <- function(file) system.file(file, package = "flashlighttext")
read_bin <- function(file, type, size) readBin(sys_file(file), size = size, type, n = 10000)

lexicon <- load_words(sys_file("words.lst")) word_dict <- create_word_dict(lexicon) lm <- KenLM$new(sys_file("lm.arpa"), word_dict) lm_state <- lm$start(FALSE) c(lm_state, lm_score) %<-% lm$score(lm_state, 0)


Method clone()

The objects of this class are cloneable with this method.

Usage

KenLM$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code

## ------------------------------------------------
## Method `KenLM$new`
## ------------------------------------------------

library(flashlighttext)
sys_file <- function(file) system.file(file, package = "flashlighttext")
read_bin <- function(file, type, size) readBin(sys_file(file), size = size, type, n = 10000)

lexicon <- load_words(sys_file("words.lst")) 
word_dict <- create_word_dict(lexicon) 
lm <- KenLM$new(sys_file("lm.arpa"), word_dict) 
lm_state <- lm$start(FALSE) 
c(lm_state, lm_score) %<-% lm$score(lm_state, 0) 

Run the code above in your browser using DataLab