簡體   English   中英

NLTK詞匯表中的單詞缺失-Python

[英]Missing words in NLTK vocabulary - Python

我正在測試NLTK軟件包的詞匯。 我使用了以下代碼,希望能看到全部True

import nltk

english_vocab = set(w.lower() for w in nltk.corpus.words.words())

print ('answered' in english_vocab)
print ('unanswered' in english_vocab)
print ('altered' in english_vocab)
print ('alter' in english_vocab)
print ('looks' in english_vocab)
print ('look' in english_vocab)

但是我的結果如下,缺少許多單詞,或者缺少某些形式的單詞? 我想念什么嗎?

False
True
False
True
False
True

實際上,語料庫不是所有英語單詞的詳盡列表,而是文本的集合。 判斷一個單詞是否為有效英語單詞的一種更合適的方法是使用wordnet:

from nltk.corpus import wordnet as wn

print wn.synsets('answered')
# [Synset('answer.v.01'), Synset('answer.v.02'), Synset('answer.v.03'), Synset('answer.v.04'), Synset('answer.v.05'), Synset('answer.v.06'), Synset('suffice.v.01'), Synset('answer.v.08'), Synset('answer.v.09'), Synset('answer.v.10')]

print wn.synsets('unanswered')
# [Synset('unanswered.s.01')]

print wn.synsets('notaword')
# []

NLTK語料庫實際上並不存儲每個單詞,它們被定義為“大量文本”。

例如,您正在使用的words語料庫,我們可以用它查看其定義readme()方法:

>>> print(nltk.corpus.words.readme())
Wordlists

en: English, http://en.wikipedia.org/wiki/Words_(Unix)
en-basic: 850 English words: C.K. Ogden in The ABC of Basic English (1932)

Unix的詞匯並不詳盡,因此可能確實遺漏了一些詞匯。 語料庫從本質上說是不完整的(因此強調自然語言)。

話雖如此,您可能想嘗試使用源自字典的語料庫,例如brown

>>> print(nltk.corpus.brown.readme())
BROWN CORPUS

A Standard Corpus of Present-Day Edited American English, for use with Digital Computers.

by W. N. Francis and H. Kucera (1964)
Department of Linguistics, Brown University
Providence, Rhode Island, USA

Revised 1971, Revised and Amplified 1979

http://www.hit.uib.no/icame/brown/bcm.html

Distributed with the permission of the copyright holder, redistribution permitted.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM