From 848a6b381e3eb48a2ef274d1e0e18b1ebcba5596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E9=95=87=E8=B4=A4?= <15717938+liangzhenxian-9563@user.noreply.gitee.com> Date: Sat, 14 Nov 2026 13:25:15 +0800 Subject: [PATCH] docs: describe sentiment scores for empty input --- docs/sentiment_analysis.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/sentiment_analysis.md b/docs/sentiment_analysis.md index dbd3399ec..8e6d3cf29 100644 --- a/docs/sentiment_analysis.md +++ b/docs/sentiment_analysis.md @@ -14,6 +14,16 @@ var analyzer = new Analyzer("English", stemmer, "afinn"); console.log(analyzer.getSentiment(["I", "like", "cherries"])); // 0.6666666666666666 ``` + +An empty array has a neutral sentiment score of `0`. This also applies when a +tokenizer produces no words, for example when `WordTokenizer` receives only +whitespace or punctuation. + +```javascript +console.log(analyzer.getSentiment([])); +// 0 +``` + The constructor has three parameters: * Language: see below for supported languages. * Stemmer: to increase the coverage of the sentiment analyzer a stemmer may be provided. May be `null`.