0
我正在Java Eclipse中創建一個工具來區分句子是否包含特定單詞。針對特定單詞讀取文本文件
我正在使用twitter4j工具來搜索twitter中的推文。
我已經使用了stanford NLP tagger來標記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個不同標記的推文,針對positive.txt和負面.txt文件,以找出一個詞來,這樣即使在鳴叫是積極還是消極
我的最終結果應該有我可以區分
分享Tweet 1:積極 Tweet 2個:負 分享Tweet 3:負
etc
目前,我正在努力創造一種能夠實現這個
任何幫助將非常感激
謝謝
非常感謝您的幫助。我如何閱讀文本文件,我已經創建了積極的話,消極的話和鳴叫 – user3406318
我在GitHub上有一個例子:https://github.com/CoachEd/JavaExamples/tree/master/ReadTextFileExample。這將逐行讀取文本文件。然後你可以相應地解析每一行。 –