我试图写一个关键字提取程序使用斯坦福POS taggers和NER。对于关键词提取,我只对专有名词感兴趣。这是基本方法
示例代码
docText="'Jack Frost works for Boeing Company. He manages 5 aircraft and their crew in London"
words = re.split("\W+",docText)
stops = set(stopwords.words("english"))
#remove stop words from the list
words = [w for w in words if w not in stops and len(w) > 2]
# Stemming
pstem = PorterStemmer()
words = [pstem.stem(w) for w in words]
nounsWeWant = set(['NN' ,'NNS', 'NNP', 'NNPS'])
finalWords = []
stn = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
stp = StanfordPOSTagger('english-bidirectional-distsim.tagger')
for w in words:
if stp.tag([w.lower()])[0][1] not in nounsWeWant:
finalWords.append(w.lower())
else:
finalWords.append(w)
finalString = " ".join(finalWords)
print finalString
tagged = stn.tag(finalWords)
print tagged
这给了我
^{pr2}$很明显,我不想让波音公司受到牵制。也没有同伴。我需要用词干作为输入,因为我的输入可能包含Performing
之类的术语。我见过像Performing
这样的词会被NER作为专有名词,因此可以归类为Organization
。因此,首先我把所有的单词都改成小写。然后我检查单词的POS标记是否是名词。如果是的话,我还是保持原样。如果不是,我将单词转换成小写,并将其添加到最终单词列表中,该列表将传递给NER。在
你知道如何避免使用专有名词词干吗?在
使用完整的斯坦福CoreNLP管道来处理您的NLP工具链。避免使用你自己的标记器、清洁器、POS标记器等。它不能很好地使用NER工具。在
[出来]:
^{pr2}$或获取json输出:
如果您真的需要python包装器,请参见https://github.com/smilli/py-corenlp
这可能是您想要的输出:
如果您想要NLTK附带的包装器,那么您必须稍等片刻,直到this issue得到解析;p
相关问题 更多 >
编程相关推荐