![](/img/trans.png)
[英]How do I print out just the word itself in a WordNet synset using Python NLTK?
[英]How do I extract the offset of a WordNet synset give a synset in Python NLTK?
WordNet中的感知偏移量是8位數字,后跟POS標簽。 例如,同義詞集“ dog.n.01”的偏移量為“ 02084071-n”。 我嘗試了以下代碼:
from nltk.corpus import wordnet as wn
ss = wn.synset('dog.n.01')
offset = str(ss.offset)
print (offset)
但是,我得到以下輸出:
<bound method Synset.offset of Synset('dog.n.01')>
如何獲得以下格式的實際偏移量:“ 02084071-n”?
>>> from nltk.corpus import wordnet as wn
>>> ss = wn.synset('dog.n.01')
>>> offset = str(ss.offset()).zfill(8) + '-' + ss.pos()
>>> offset
u'02084071-n'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.