2014-12-01 4 views
5

그래서 텍스트 코퍼스를 분석하고 모든 토큰 화 된 단어에 대해 스 트리머를 사용했습니다. 하지만 코퍼스의 모든 명사를 다시 찾아야하므로 nltk.pos_tag(stemmed_sentence) 하지만 내 질문에 맞습니까? 스템머와 pos 태그러 사이의 우선 순위에 대해 혼동이 있음

B.] tokenize->stem  #stemming and pos_tagging done seperately 
    tokeinze->pos_tagging 

A.] tokenize->stem->pos_tagging 

OR

필자는 방법 A를 따랐다하지만 pos_tagging 달성의 적당한 방법에 관한 혼동 임.

답변

7

왜 사용하지 않으시겠습니까?

>>> 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." 

이 토큰 화의 결과는 다음과 같습니다

다음은 예입니다. 이 토큰 화의 결과입니다> 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'.', '.')] 

-> 줄기 ->이 토큰 화의 결과입니다 줄기

>>> 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'.'] 

-

>>> [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', '.'] 

이 토큰 화의 결과입니다 - > 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'), ('.', '.')] 

그럼 옳은 길이야?

1

난 당신이

이 예 here를 참조하십시오 태그 POS 전에 줄기 싶지 않아 생각 :

파이썬 인터프리터에서 수입 NLTK 후

NLTK에 POS 태그를 사용하는 방법, pos_tag 메소드라고하는 pos 태그를 사용하기 전에 word_tokenize를 사용해야합니다 :

>>> import nltk 
>>> text = nltk.word_tokenize(“Dive into NLTK: Part-of-speech tagging and POS Tagger”) 
>>> text 
[‘Dive’, ‘into’, ‘NLTK’, ‘:’, ‘Part-of-speech’, ‘tagging’, ‘and’, ‘POS’, ‘Tagger’] 
>>> nltk.pos_tag(text) 
[(‘Dive’, ‘JJ’), (‘into’, ‘IN’), (‘NLTK’, ‘NNP’), (‘:’, ‘:’), (‘Part-of-speech’, ‘JJ’), (‘tagging’, ‘NN’), (‘and’, ‘CC’), (‘POS’, ‘NNP’), (‘Tagger’, ‘NNP’)] 
+1

awww, OP를위한 재미를 망치지 마십시오.) – alvas

+0

아직 재미가 남아 있기를 바랍니다.) – bpgergo

+0

@bpgergo 감사합니다 .-) – rzach