首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理python中nltk标记器中来自不同国家的英语拼写差异

如何处理python中nltk标记器中来自不同国家的英语拼写差异
EN

Stack Overflow用户
提问于 2015-02-06 14:48:22
回答 1查看 144关注 0票数 1

我使用python2.7nltk标记器来标记一个简单的英文文本,以便提取每个单词的频率及其命名的实体类别。以下程序用于此目的:

代码语言:javascript
复制
 import re
 from collections import Counter
 from nltk.tag.stanford import NERTagger
 from nltk.corpus import stopwords

 stops = set(stopwords.words("english"))

WORD = re.compile(r'\w+')

def main ():
    text = "title Optimal Play against Best Defence: Complexity and   
    Heuristics"
    print text
    words = WORD.findall(text)
    print words
    word_frqc = Counter(words)

    tagger = ERTagger("./classifiers/english.all.3class.distsim.crf.ser.gz",  
    "stanford-ner.jar")
    terms = []
    answer = tagger.tag(words)
    print answer
    for i, word_pos in enumerate(answer):
        word, pos = word_pos
        if pos == 'PERSON':
           cat_Id = 1
        elif pos == 'ORGANIZATION':
           cat_Id = 2
        elif pos == 'LOCATION':
           cat_Id = 3
        else:
            cat_Id = 4
        frqc =word_frqc.get(word)
        terms.append( (i, word, cat_Id, frqc ))
print terms
if __name__ == '__main__':
     main()

程序的输出如下:

代码语言:javascript
复制
text = "title Optimal Play against Best **Defence:** Complexity and    
    Heuristics"

[(u'title', u'O'), (u'Optimal', u'O'), (u'Play', u'O'), (u'against', u'O'),       
 (u'Best', u'O'), (u'Defense', u'O'), (u'Complexity', u'O'), (u'and', u'O'),  
 (u'Heuristics', u'O')]

 [(0, u'title', 4, 1), (1, u'Optimal', 4, 1), (2, u'Play', 4, 1), (3, 
   u'against', 4, 1), (4, u'Best', 4, 1), (5, u'**Defense**', 4, None), (6, 
   u'Complexity', 4, 1), (7, u'and', 4, 1), (8, u'Heuristics', 4, 1)]

有一个问题是由tagger.tag()方法引起的。该方法将原始文本中的单词“defence”更改为“defence”。因此,程序在word_frqc中看不到“防御”一词,因此将该词在文本中的出现频率设置为“无”。

请问有什么方法(在python中)可以让方法不改变单词吗?

EN

回答 1

Stack Overflow用户

发布于 2016-01-22 11:53:49

我也有同样的问题。

尝试使用安装地理

pip安装地理位置。

检查github repo here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28360085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档