完全可解析的词典/同义词典
我正在设计一系列简单的单词游戏,希望能帮助我学习新单词。我的一个重要想法是要有一个可以完全解析的字典;我想用正则表达式来搜索字典中的特定单词,并提取一些其他信息,比如定义、词性(名词/动词等)、同义词、反义词、以及用这个词造的句子等等。目前我有一个叫Wordbook的Mac应用,觉得还不错,但我还没弄明白能不能用Python脚本来解析它。我在想可能不行,不知道有没有人知道哪个字典可以做到这一点。理想情况下,我希望这一切都能在没有互联网的情况下完成。
谢谢
3 个回答
2
据我所知,dictionary.com 提供了一个免费的接口,可以用于非商业用途,具体信息可以在这里找到。你可能可以从网上获取一些数据。
4
Wordnik 提供了一个可以用Python编程的接口
8
nltk wordnet 语料库提供了一种程序化的方式来访问一个“庞大的英语单词词汇数据库”。你可以根据不同的关系在这个单词图谱中进行导航。它可以满足显示“定义、词性、同义词、反义词、引用”等需求,并且“最好是可以下载的字典”。
另一个选择是下载维基词典的最新快照数据,然后将其解析成你可以使用的格式,但这可能会有点复杂(除非已经存在一个不错的Python维基词典解析器)。
下面是一个使用Wordnet打印一些属性的例子:
import textwrap
from nltk.corpus import wordnet as wn
POS = {
'v': 'verb', 'a': 'adjective', 's': 'satellite adjective',
'n': 'noun', 'r': 'adverb'}
def info(word, pos=None):
for i, syn in enumerate(wn.synsets(word, pos)):
syns = [n.replace('_', ' ') for n in syn.lemma_names]
ants = [a for m in syn.lemmas for a in m.antonyms()]
ind = ' '*12
defn= textwrap.wrap(syn.definition, 64)
print 'sense %d (%s)' % (i + 1, POS[syn.pos])
print 'definition: ' + ('\n' + ind).join(defn)
print ' synonyms:', ', '.join(syns)
if ants:
print ' antonyms:', ', '.join(a.name for a in ants)
if syn.examples:
print ' examples: ' + ('\n' + ind).join(syn.examples)
print
info('near')
输出:
sense 1 (verb)
definition: move towards
synonyms: approach, near, come on, go up, draw near, draw close, come near
examples: We were approaching our destination
They are drawing near
The enemy army came nearer and nearer
sense 2 (adjective)
definition: not far distant in time or space or degree or circumstances
synonyms: near, close, nigh
antonyms: far
examples: near neighbors
in the near future
they are near equals
...