#C6549. Review Sentence Classification
Review Sentence Classification
Review Sentence Classification
You are given a set of reviews. Each review consists of several sentences. In addition, you are provided with two lists of keywords: positive and negative. For each sentence, if it contains any positive keyword, you should classify it as positive. If it does not contain a positive keyword but contains at least one negative keyword, classify it as negative. Otherwise, the sentence should be classified as neutral.
More formally, for each sentence, let \(S\) be the sentence text. Let \(P\) be the set of positive keywords and \(N\) be the set of negative keywords. The classification is determined as follows:
[ \text{classification}(S) = \begin{cases} \text{positive}, & \text{if } \exists p \in P: p \text{ is a substring of } S,\ \text{negative}, & \text{if } \nexists p \in P \text{ and } \exists n \in N: n \text{ is a substring of } S,\ \text{neutral}, & \text{otherwise.} \end{cases} ]
Your task is to implement a program that reads the input from standard input and outputs the classification for each sentence of each review to standard output.
inputFormat
Input Format:
- The first line contains two integers, P and N, representing the number of positive and negative keywords respectively.
- The second line contains P space-separated positive keywords.
- The third line contains N space-separated negative keywords.
- The fourth line contains an integer R, the number of reviews.
- For each review, the first line contains an integer S – the number of sentences in that review, followed by S lines, each representing a sentence.
outputFormat
Output Format:
- For each review, output a single line containing the classification of each sentence (either
positive
,negative
, orneutral
) separated by a single space.
3 2
happy love excellent
poor bad
2
3
I love this product.
The service was excellent.
The delivery was poor.
2
This makes me happy.
The item is bad.
positive positive negative
positive negative
</p>