我想指望从包含数据如下文本文件的话:字数问题
ROK :
ROK/(NN)
New :
New/(SV)
releases, :
releases/(NN) + ,/(SY)
week :
week/(EP)
last :
last/(JO)
compared :
compare/(VV) + -ed/(EM)
year :
year/(DT)
releases :
releases/(NN)
像/(NN)/(SV),和/(EP)被认为是类的表达。 我想在每个类别之前提取单词并计算整个文本中有多少单词。
我想在这样一个新的文本文件写一个结果:
(NN)
releases 2
ROK 1
(SY)
New 1
, 1
(EP)
week 1
(JO)
last 1
......
请帮我!
这里是我的车库代码; _;它不起作用。
import os, sys
import re
wordset = {}
for line in open('E:\\mach.txt', 'r'):
if '/(' in line:
word = re.findall(r'(\w)/\(', line)
print word
if word not in wordset: wordset[word]=1
else: wordset[word]+=1
f = open('result.txt', 'w')
for word in wordset:
print>> f, word, wordset[word]
f.close()
此代码显示出色的性能!但实际上我想解析韩国的话。在这种情况下,此代码无法正常工作。你有什么主意吗? – ooozooo
哦..刚刚找到你的评论。你还需要帮助吗? –