v2026.6.4
All Bundles
Bundle Natural language processing toolkit. Provides tokenization, text preprocessing, TF-IDF vectorization, cosine similarity, and sentiment analysis. Works with plain strings — no external model required. Compile with -lib nlp.

Tokenizer

Text tokenization utilities for breaking text into words, sentences, and n-grams

Example

text := "Hello, world! This is a test.";
words := System.NLP.Tokenizer->WordTokenize(text);
sentences := System.NLP.Tokenizer->SentenceTokenize(text);
bigrams := System.NLP.Tokenizer->WordNGrams(words, 2);

Operations

CharNGrams # function

Generates character-level n-grams from text

function : CharNGrams(text:String, n:Int) ~ String[]

Parameters

NameTypeDescription
textStringinput text
nIntsize of n-grams

Return

TypeDescription
Stringarray of n-gram strings

Example

trigrams := Tokenizer->CharNGrams("hello", 3);
each(g in trigrams) {
  g->PrintLine();
};

SentenceTokenize # function

Tokenizes text into sentences using common sentence delimiters

function : SentenceTokenize(text:String) ~ String[]

Parameters

NameTypeDescription
textStringinput text to tokenize

Return

TypeDescription
Stringarray of sentence tokens

Example

sents := Tokenizer->SentenceTokenize("Hello! How are you? I am fine.");
each(s in sents) {
  s->PrintLine();
};

WordNGrams # function

Generates word-level n-grams from tokenized text

function : WordNGrams(tokens:String[], n:Int) ~ String[]

Parameters

NameTypeDescription
tokensStringarray of word tokens
nIntsize of n-grams

Return

TypeDescription
Stringarray of n-gram strings (words joined by spaces)

Example

words := Tokenizer->WordTokenize("the quick brown fox");
bigrams := Tokenizer->WordNGrams(words, 2);
each(g in bigrams) {
  g->PrintLine();
};

WordTokenize # function

Tokenizes text into words using whitespace and punctuation as delimiters

function : WordTokenize(text:String) ~ String[]

Parameters

NameTypeDescription
textStringinput text to tokenize

Return

TypeDescription
Stringarray of word tokens

Example

words := Tokenizer->WordTokenize("Hello, world! How are you?");
each(w in words) {
  w->PrintLine();
};