我有一个文本,我想找到“ADJs”、“PRONs”、“VERBs”、“NOUNs”等的数量。我知道有.pos_tag()函数,但它给了我不同的结果,我想要结果为“ADJ” ','PRON', '动词', '名词'。这是我的代码:
import nltk
from nltk.corpus import state_union, brown
from nltk.corpus import stopwords
from nltk import ne_chunk
from nltk.tokenize import PunktSentenceTokenizer
from nltk.tokenize import word_tokenize
from nltk.tokenize import RegexpTokenizer
from nltk.stem import WordNetLemmatizer
from collections import Counter
sentence = "this is my sample text that I want to analyze with programming language"
# tokenizing text (make list with evey word)
sample_tokenization = word_tokenize(sample)
print("THIS IS TOKENIZED SAMPLE TEXT, LIST OF WORDS:\n\n", sample_tokenization)
print()
# tagging words …Run Code Online (Sandbox Code Playgroud)