【发布时间】:2017-03-14 08:41:04
【问题描述】:
原始推文已按以下结构保存到文件中:
推文语言 ||推特
以下是我删除 URL、RT、用户名和任何非字母数字字符的预处理阶段。
def cleanTweets() {
File dirtyTweets = new File("result.txt")
File cleanTweets = new File("cleanTweets.txt")
try {
Scanner console = new Scanner(dirtyTweets)
PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(cleanTweets)))
LinkedHashSet<String> ln = new LinkedHashSet<String>();
while (console.hasNextLine()) {
String line = console.nextLine();
String[] splitter = line.split("\\|\\|\\|")
//Only looks at the english tweets
if (splitter[0] == "en") {
line = line.replaceFirst("en", "")
String urlIdentifier = "((http|ftp|https):\\/\\/)?[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?"
//Removes URL's, RT, Twitter usernames and any non alpha numeric character
String[] removeNoise = ["RT", urlIdentifier, "(?:\\s|\\A)[@]+([A-Za-z0-9-_]+)", "[^a-zA-Z0-9 ]"]
removeNoise.each { noise ->
line = line.replaceAll(noise, "").toLowerCase()
}
ln.add(line)
}
}
ln.each { line ->
printWriter.write(line)
printWriter.println()
}
//write to file here
} catch (IOException e) {
}
}
然后将其保存到新文件中。对这些推文进行情绪分析的下一阶段是什么?
【问题讨论】:
标签: java twitter stanford-nlp