4 python stemming nltk part-of-speech
所以我正在分析一个文本语料库,我使用词干分析器来表示所有标记化的单词.但我也必须找到语料库中的所有名词,所以我再次做了一个nltk.pos_tag(stemmed_sentence)
但我的问题是我做得对吗?
A.] tokenize->stem->pos_tagging
Run Code Online (Sandbox Code Playgroud)
要么
B.] tokenize->stem #stemming and pos_tagging done seperately
tokeinze->pos_tagging
Run Code Online (Sandbox Code Playgroud)
我按照方法A,但我很困惑,它是实现pos_tagging的正确方法.
你为什么不试试呢?
这是一个例子:
>>> from nltk.stem import PorterStemmer
>>> from nltk import word_tokenize, pos_tag
>>> sent = "This is a messed up sentence from the president's Orama and it's going to be sooo good, you're gonna laugh."
Run Code Online (Sandbox Code Playgroud)
这是令牌化的结果.
>>> [word for word in word_tokenize(sent)]
['This', 'is', 'a', 'messed', 'up', 'sentence', 'from', 'the', 'president', "'s", 'Orama', 'and', 'it', "'s", 'going', 'to', 'be', 'sooo', 'good', ',', 'you', "'re", 'gon', 'na', 'laugh', '.']
Run Code Online (Sandbox Code Playgroud)
这是tokenize - > stem的结果
>>> porter = PorterStemmer()
>>> [porter.stem(word) for word in word_tokenize(sent)]
[u'Thi', u'is', u'a', u'mess', u'up', u'sentenc', u'from', u'the', u'presid', u"'s", u'Orama', u'and', u'it', u"'s", u'go', u'to', u'be', u'sooo', u'good', u',', u'you', u"'re", u'gon', u'na', u'laugh', u'.']
Run Code Online (Sandbox Code Playgroud)
这是tokenize - > stem - > POS标签的结果
>>> pos_tag([porter.stem(word) for word in word_tokenize(sent)])
[(u'Thi', 'NNP'), (u'is', 'VBZ'), (u'a', 'DT'), (u'mess', 'NN'), (u'up', 'RP'), (u'sentenc', 'NN'), (u'from', 'IN'), (u'the', 'DT'), (u'presid', 'JJ'), (u"'s", 'POS'), (u'Orama', 'NNP'), (u'and', 'CC'), (u'it', 'PRP'), (u"'s", 'VBZ'), (u'go', 'RB'), (u'to', 'TO'), (u'be', 'VB'), (u'sooo', 'RB'), (u'good', 'JJ'), (u',', ','), (u'you', 'PRP'), (u"'re", 'VBP'), (u'gon', 'JJ'), (u'na', 'NN'), (u'laugh', 'IN'), (u'.', '.')]
Run Code Online (Sandbox Code Playgroud)
这是tokenize - > POS标签的结果
>>> pos_tag([word for word in word_tokenize(sent)])
[('This', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('messed', 'VBN'), ('up', 'RP'), ('sentence', 'NN'), ('from', 'IN'), ('the', 'DT'), ('president', 'NN'), ("'s", 'POS'), ('Orama', 'NNP'), ('and', 'CC'), ('it', 'PRP'), ("'s", 'VBZ'), ('going', 'VBG'), ('to', 'TO'), ('be', 'VB'), ('sooo', 'RB'), ('good', 'JJ'), (',', ','), ('you', 'PRP'), ("'re", 'VBP'), ('gon', 'JJ'), ('na', 'NN'), ('laugh', 'IN'), ('.', '.')]
Run Code Online (Sandbox Code Playgroud)
那么正确的方法是什么?
| 归档时间: |
|
| 查看次数: |
1363 次 |
| 最近记录: |