使用pos标记寻找三词短语

来源:互联网 发布:昆士兰it 编辑:程序博客网 时间:2024/06/06 02:49
# -*- coding:utf-8 -*-import nltkfrom nltk.corpus import browndef process(sentence):for(w1,t1),(w2,t2),(w3,t3) in nltk.trigrams(sentence):if(t1.startswith('V'))and t2=='TO' and t3.startswith('V'):#代码的意思是:动词+to+动词的形式,一旦发现就输出print w1,w2,w3if __name__=='__main__':for tagged_sent in brown.tagged_sents():process(tagged_sent)

原创粉丝点击