【发布时间】:2014-03-24 14:58:59
【问题描述】:
我正在 Java Eclipse 中创建一个工具,它可以区分句子是否包含特定单词。
我正在使用 twitter4j 工具来搜索 twitter 中的推文。
我使用了 stanford NLP 标记器来标记来自 twitter 的推文。然后将其存储在一个文本文件中。
这里是代码
public class TextTag {
public static void main(String[] args) throws IOException,
ClassNotFoundException {
String tagged;
// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("taggers/english-left3words-distsim.tagger");
// The sample string
String sample = "Output Tagged";
//The tagged string
tagged = tagger.tagString(sample);
//output the tagged sample string onto your console
//System.out.println(tagged);
/*pick up some sentences from the file ouput.txt and store the output of
tagged sentences in another file EntityTagged.txt. */
FileInputStream fstream = new FileInputStream("Output.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
//we will now pick up sentences line by line from the file ouput.txt and store it in the string sample
while((sample = br.readLine())!=null)
{
//tag the string
tagged = tagger.tagString(sample);
FileWriter q = new FileWriter("EntityTagged.txt",true);
BufferedWriter out =new BufferedWriter(q);
//write it to the file EntityTagged.txt
out.write(tagged);
out.newLine();
out.close();
}
我的下一步是使用来自 EntityTagged.txt 的标记推文,并将这些推文与一串肯定词和否定词进行比较。
我创建了 2 个文本文件,一个正面词列表和一个负面词列表,我的目标是循环遍历“EntityTagged.txt”文件中的 10 条不同标记的推文,对照正面和负面。 txt 文件来找出是否出现了一个词,这样我就可以区分推文是正面的还是负面的
我的最终结果应该有
推文 1:正面评价 推文2:负面 推文3:否定
等
目前,我正在努力创建一种可以实现此功能的算法
任何帮助将不胜感激
谢谢
【问题讨论】:
标签: java twitter text-files stanford-nlp pos-tagger