2
我需要预先处理一些文本文件,这样我可以申请分类技术,如流式细胞仪等,以及其他主题建模技术,如隐含狄利克雷分布等任何更好的预处理库或python实现?
详细制定预处理一点我需要删除停用词,提取物名词和关键词并执行词干。这是我用于此目的的代码是:
#--------------------------------------------------------------------------
#Extracting nouns
#--------------------------------------------------------------------------
for i in range (0,len(a)) :
x=a[i]
text=nltk.pos_tag(nltk.Text(nltk.word_tokenize(x)))
for noun in text:
if(noun[1]=="NN" or noun[1]=="NNS"):
temp+=noun[0]
temp+=' '
documents.append(temp)
print documents
#--------------------------------------------------------------------------
#remove unnecessary words and tags
#--------------------------------------------------------------------------
texts = [[word for word in document.lower().split() if word not in stoplist]for document in documents]
allTokens = sum(texts, [])
tokensOnce = set(word for word in set(allTokens) if allTokens.count(word)== 0)
texts = [[word for word in text if word not in tokensOnce]for text in texts]
print texts
#--------------------------------------------------------------------------
#Stemming
#--------------------------------------------------------------------------
for i in texts:
for j in range (0,len(i)):
k=porter.stem(i[j])
i[j]=k
print texts
与我上面提到的代码的问题是
- 用于提取名词和关键字缺少许多话NLTK模块。 例如,对某些文档进行了预处理,并且像“Sachin”这样的名称未被识别为关键字,并在预处理后被忽略。
- 这个词没有被正确地引用。有太多词干(网络和网络到网络),有些时候名词也被阻止。
是否有更好的模块用于所需的功能还是有更好的实现相同的模块? 请帮助