2014-01-18 3 views
1

NLTK를 통해 WordNet에이 단어가 '존재하는지'확인하는 간단한 함수를 작성하고 싶습니다.NLTK WordNet에서 간단한 단어를 찾지 못하는 이유는 무엇입니까?

def is_known(word): 
    """return True if this word "exists" in WordNet 
     (or at least in nltk.corpus.stopwords).""" 
    if word.lower() in nltk.corpus.stopwords.words('english'): 
     return True 
    synset = wn.synsets(word) 
    if len(synset) == 0: 
     return False 
    else: 
     return True 

could, since, without, although과 같은 단어가 거짓입니까? WordNet에 나타나지 않습니까? WN (NLTK 사용)에 단어가 있는지 여부를 알아내는 더 좋은 방법이 있습니까?

내 첫 번째 시도는 to, if, when, then, I, you과 같은 단어 인 "stopwords"를 제거하는 것이었지만 아직 찾을 수없는 매우 일반적인 단어 (예 : could)가 있습니다.

+0

The water can is heavy

I can foo bar. 왜 True를 반환합니까? – alvas

+1

그것은 단지이 단어들을 무시하려고했습니다. 그러나 나는 모든 일반적인 단어가 불어 구어가 아니라는 것을 알아 차렸다. – Sadik

답변

6

WordNet에는 이러한 단어 나 단어가 없습니다. 에 대한 설명하여 WordNet docs에서 다음을 참조하십시오

Q. Why is WordNet missing: of, an, the, and, about, above, because, etc. 
A. WordNet only contains "open-class words": nouns, verbs, adjectives, and adverbs. Thus, excluded words include determiners, prepositions, pronouns, conjunctions, and particles. 

당신은 또한 워드 넷의 온라인 버전에서 단어의 이러한 종류의를 찾을 수 없습니다.

+0

링크에 대한 thanx – Sadik

0
당신은 워드 넷의 모든 표제어를 추출하고 해당 목록에 대해 확인하기 위해 시도 할 수

:

from nltk.corpus import wordnet as wn 
from itertools import chain 
all_lemmas = set(chain(*[i.lemma_names for i in wn.all_synsets()])) 

def in_wordnet(word): 
    return True if word in all_lemmas else False 

print in_wordnet('can') 
print in_wordnet('could') 

[OUT] :

True 
False 

이 보조 정리하지 단어가 포함 된 워드 넷 점에 유의 함 . 또한 단어/표제어는 다국어가 될 수 있으며 실제로 포함 단어가 아님을주의하십시오. 불용어 그것을 때

+0

in_wordnet은 is_known과 동일한 결과를 제공하지만 매우 느립니다 (당연히 기능이 아닙니다) – Sadik

관련 문제