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.
SentimentAnalyzer
Basic lexicon-based sentiment analysis
Example
text := "This is absolutely wonderful and amazing!";
score := System.NLP.SentimentAnalyzer->Analyze(text);
classification := System.NLP.SentimentAnalyzer->Classify(text);
result := System.NLP.SentimentAnalyzer->AnalyzeDetailed(text);
result->ToString()->PrintLine();Operations
Analyze # function
Analyzes sentiment of text and returns a sentiment score
function : Analyze(text:String) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| text | String | input text to analyze |
Return
| Type | Description |
|---|---|
| Int | sentiment score (positive = positive sentiment, negative = negative sentiment, 0 = neutral) |
Example
score := SentimentAnalyzer->Analyze("This product is absolutely wonderful!");
"Score: {$score}"->PrintLine();AnalyzeDetailed # function
Gets detailed sentiment analysis with scores
function : AnalyzeDetailed(text:String) ~ SentimentResultParameters
| Name | Type | Description |
|---|---|---|
| text | String | input text to analyze |
Return
| Type | Description |
|---|---|
| SentimentResult | sentiment result with score and classification |
Example
result := SentimentAnalyzer->AnalyzeDetailed("Amazing and wonderful experience!");
result->ToString()->PrintLine();Classify # function
Classifies text sentiment as positive, negative, or neutral
function : Classify(text:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| text | String | input text to classify |
Return
| Type | Description |
|---|---|
| String | sentiment label: "positive", "negative", or "neutral" |
Example
label := SentimentAnalyzer->Classify("This is terrible and horrible.");
label->PrintLine();Init # function
Initializes sentiment lexicons with common positive and negative words
function : Init() ~ Nil