使用pos标记寻找三词短语
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                使用pos标记寻找三词短语
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            # -*- coding:utf-8 -*-
import nltk
from nltk.corpus import brown
def 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,w3
if __name__=='__main__':for tagged_sent in brown.tagged_sents():process(tagged_sent)
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的使用pos标记寻找三词短语的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: NLTK找出最频繁的名词标记的程序(代码
- 下一篇: 把函数作为参数
