如何使用Python 3.5中的NLTK 3使用POS标签查找单词组合

时间:2016-04-09 00:52:29

标签: python nltk

我正在编写一个程序:

  1. 打开.txt或.xml文件并使用TreeTagger(语法标记器)标记其内容
  2. 识别确定符(DT)的所有实例,后跟常用名词(NN)
  3. 该程序没有产生任何错误。但是,它不返回任何东西。如果你看到我做错了什么,请告诉我。

    这是我的计划的相关部分:

    tagger = treetaggerwrapper.TreeTagger(TAGLANG = 'en')
    tagged_text = tagger.tag_text(text)
    #tags the text
    
    nltk_text = nltk.Text(tagged_text)
    bigram_list = list(bigrams(nltk_text))
    
    for (w1, t1), (w2, t2) in nltk.bigrams(bigram_list):
       if t1.startswith('DT') and t2.startswith('NN') :
            p.pprint(w1, w2)
    #identifies instances of 'DT' followed by 'NN'
    else:
        print('No matches found')`
    

0 个答案:

没有答案
相关问题