Language
Language, sentiment, entities
Runs on device. No permission, no network, fast enough to call from a widget.
Methods
Language.detect(text)AnyThe dominant language, or null when the text is too short.
- text String required
The text to identify.
returns code is a language code like "it" or "en".
Language.sentiment(text)Number-1 for negative, 1 for positive, 0 for neutral.
- text String required
The text to score.
returns 0 means neutral, and is also what a language with no sentiment model returns. The two cases are indistinguishable.
Language.tokenize(text, unit)[String]Splits text into words, sentences or paragraphs.
- text String required
The text to split.
- unit String required
"word", "sentence" or "paragraph". Defaults to word.
Language.entities(text)[Any]People, places and organisations, as { text, type }.
- text String required
The text to scan.
Language.lemmas(text)[Any]Each word with its dictionary form, as { text, lemma }.
- text String required
The text to analyse.
Examples
Colour a headline by mood
var score = Language.sentiment(headline);
var colour = score > 0.2 ? Color.green() : score < -0.2 ? Color.red() : Color.gray();
Script.setWidget(new Widget({ child: Text(headline, { color: colour }) }));