我需要编写一个代码,将关于产品的几行评论作为输入,并根据评论中描述产品的形容词对产品进行评分。我刚刚使用 POS 标记器来标记每条评论的词性。现在,我必须挑选出描述名词的形容词,如果一个名词似乎与产品有关,我需要考虑相应的形容词。这是我用于 POS 标记的代码。它工作得很好。
import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Tagg {
public static void main(String[] args) throws IOException,
ClassNotFoundException {
String tagged;
// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("edu/stanford/nlp/models/pos-tagger/wsj- left3words/wsj-0-18-left3words-distsim.tagger");
FileInputStream fstream = new FileInputStream("src/input.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
FileWriter q = new FileWriter("src/output.txt",true);
BufferedWriter out =new BufferedWriter(q);
String sample;
//we will now pick up sentences line by line from the file input.txt and store it in the string sample
while((sample = br.readLine())!=null)
{
//tag the string
tagged = tagger.tagString(sample);
System.out.print(tagged+"\n");
//write it to the file output.txt
out.write(tagged);
out.newLine();
}
out.close();
}
}
我需要一种方法来进行。.