Classify Reviews by Sentiment Word Occurrences
Problem statement
For every review, split on whitespace and count all token occurrences found in positiveWords and negativeWords. Repeated tokens count repeatedly. Matching is case-sensitive and punctuation remains part of a token.
Return positive when the positive count is greater, negative when it is smaller, and neutral when the counts are equal. A token present in both lexicons contributes to both counts.
Function
classifyReviews(reviews: String[], positiveWords: String[], negativeWords: String[]) → String[]Examples
Example 1
reviews = ["good good bad","bad","plain"]positiveWords = ["good"]negativeWords = ["bad"]return = ["positive","negative","neutral"]The batch contains positive, negative, and neutral reviews.
Example 2
reviews = ["great great poor"]positiveWords = ["great"]negativeWords = ["poor"]return = ["positive"]Every matching occurrence contributes.
Constraints
0 <= reviews.length <= 10000- The total input text length is at most
200000.