Python NLTK: How to tag sentences with the simplified set of part-of-speech tags?

前端 未结 3 1462
醉酒成梦
醉酒成梦 2020-12-13 18:57

Chapter 5 of the Python NLTK book gives this example of tagging words in a sentence:

>>> text = nltk.word_tokenize(\"And now for something completel         


        
3条回答
  •  误落风尘
    2020-12-13 19:37

    You can simply set the tagset attribute to 'universal' in the pos_tag method.

    In [39]: from nltk import word_tokenize, pos_tag
    ...: 
    ...: text = word_tokenize("Here is a simple way of doing this")
    ...: tags = pos_tag(text, tagset='universal')
    ...: print(tags)
    ...: 
    [('Here', 'ADV'), ('is', 'VERB'), ('a', 'DET'), ('simple', 'ADJ'), ('way', 'NOUN'), ('of', 'ADP'), ('doing', 'VERB'), ('this', 'DET')]
    

提交回复
热议问题