WordDict: Word dictionary

Description Super class Methods Examples

Description

A datastructure to construct a dictionary for words as keys to numbers as values. This class also provides the method word2vec() to transform an already tokenized character vector into a word embeding. The default value for a missing value is 0 here. Specific editing can be done using the put() function.

Super class

RolliNLP::DictMap -> WordDict

Methods

Public methods

Inherited methods

Method new()

Usage
WordDict$new(lower = F)

Method get()

Usage
WordDict$get(key)

Method add()

Usage
WordDict$add(word)

Method word2vec()

Usage
WordDict$word2vec(words)

Method clone()

The objects of this class are cloneable with this method.

Usage
WordDict$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
wd <- WordDict$new(lower = TRUE)
wd$add("Hello")
wd$add("World")
wd$get("world") == 2
wd <- WordDict$new(lower = FALSE)
wd$add("Hello")
wd$add("World")
wd$get("world") == 0 # Missing word
wd$get("World") == 2
wd$word2vec(c("Hello", "World")) == c(1,2)
wd$word2vec(c("Hello", "world")) == c(1,0)

LazerLambda/RolliNLP documentation built on Oct. 17, 2020, 8:54 p.m.