简体   繁体   中英

NLTK Tagging specific words

I'm new to NTLK and Python overall. I understand you can insert a sentence and have all the words tagged to a part of speech, but i'm trying to figure out how to tag for a specific part of speech. For example, I want to only tag nouns and verbs, how would I go about doing that? This is probably a dumb question but I've been researching for a bit and still am very confused. I'd be great if I could get a few lines of code that I can edit to tag for specific parts of speech.

text = word_tokenize("And now for something completely different")
nltk.pos_tag(text)
[('And', 'CC'), ('now', 'RB'), ('for', 'IN'), ('something', 'NN'),
('completely', 'RB'), ('different', 'JJ')]  

https://www.nltk.org/book/ch05.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM