2014-12-01 14 views
5

arasındaki öncelik hakkında karışıklık yaptım Bu yüzden bir metin corpus analiz ediyordum ve tüm tokenized kelimeler için stemmer kullanıyorum. Ama aynı zamanda corpus içindeki tüm isimleri bulmak zorundayım, böylece tekrar bir nltk.pos_tag(stemmed_sentence) yaptım Ama sorum şu doğru mu yapıyorum? Köşeçi ve pos tagger

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

A.] tokenize->stem->pos_tagging 

VEYA

Ive A yöntemini takip etti, ama pos_tagging ulaşmak için sağ yolu olarak Im karıştı.

cevap

7

Neden denemiyorsunuz?

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

Bu tokenizing sonucudur:

İşte bir örnek. Bu tokenize sonucudur> POS etiketi

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

-> kök -> Bu tokenize sonucudur kök

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

Bu tokenize sonucudur - > POS etiketi

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

Peki doğru yol nedir?

1

Sana

Bu örneği here Bkz etiketleme POS önce kök istemiyorum düşünüyorum:

piton yorumlayıcı ithalat NLTK sonra

NLTK yılında POS Etiketlemeyi nasıl kullanılır, pos_tag yöntemi olarak adlandırılan pos etiketlemeden önce word_tokenize kullanmalısınız:

>>> 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 için eğlenceyi bozmayın;) – alvas

+0

Umarım biraz eğlencem vardır;) – bpgergo

+0

@bpgergo çok teşekkürler ;-) – rzach

İlgili konular