使用NLTK
分词
text = nltk.tokenize.word_tokenize("he is riding a horse .")
print(text)
>>> ['he', 'is', 'riding', 'a', 'horse', '.']
词性标注
nltk.pos_tag(text)
>>>[('he', 'PRP'), ('is', 'VBZ'), ('riding', 'VBG'), ('a', 'DT'), ('horse', 'NN'), ('.', '.')]
注意: 在作词性标注的时候要输入分词后的列表, 如果直接输入一句话会按字母分