我需要编写一段代码,对产品进行几行评论作为输入,并根据描述评论中产品的形容词对产品进行评分。我刚刚使用POS tagger来标记每条评论的词性。现在,我必须选出描述名词的形容词,如果名词似乎与产品有关,我需要考虑相应的形容词。这是我用于POS标记的代码。它只是正常工作。查找使用斯坦福大学NLP描述名词的形容词
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();
}
}
我需要一种方法来继续。 。
请不要使用DataInputStream来读取文本,也请从您的示例中删除它,这个不好的想法经常被复制。 http://vanillajava.blogspot.co.uk/2012/08/java-memes-which-refuse-to-die.html –