【问题标题】:How can I look up an english dictionary in python?如何在 python 中查找英语词典?
【发布时间】:2018-03-21 15:51:00
【问题描述】:

我正在开发一个 Python 程序来查找文本中单词的词源。我发现基本上有两种选择:解析提供词源的在线词典或使用 API。我在这里找到了这个回复,但我似乎不明白如何将 Oxford API 与我的 Python 程序链接起来。

谁能解释我如何在英语词典中查找单词?提前谢谢你。

链接到问题here

请注意,虽然 WordNet 并不包含所有英语单词,但牛津英语词典呢? (http://developer.oxforddictionaries.com/)。根据您项目的范围,它可能是一个杀手级 API。 你试过看格雷迪沃德的白鲸吗? [链接] (http://icon.shef.ac.uk/Moby/)。 您可以将其作为词典添加到 NLTK 中(请参阅第 2.1 节中有关“加载您自己的语料库”的注释)。

from nltk.corpus import PlaintextCorpusReader
corpus_root = '/usr/share/dict'
wordlists = PlaintextCorpusReader(corpus_root, '.*')

from nltk.corpus import BracketParseCorpusReader
corpus_root = r"C:\corpora\penntreebank\parsed\mrg\wsj"
file_pattern = r".*/wsj_.*\.mrg"
ptb = BracketParseCorpusReader(corpus_root, file_pattern)

【问题讨论】:

  • 这很困难,关于单词定义/词源/消歧,没有单一的来源,即使是英语也是如此。我认为有一个提供词源的维基词典工具,但我现在找不到。

标签: python parsing dictionary nlp nltk


【解决方案1】:

您可以使用开源的ety 包。 披露:我是该项目的贡献者

它基于研究“Etymological Wordnet: Tracing the History of Words”中使用的数据,该数据已经从Wiktionary 预先抓取。

一些例子:

>>> import ety

>>> ety.origins("potato")
[Word(batata, language=Taino)]

>>> ety.origins('drink', recursive=True)
[Word(drync, language=Old English (ca. 450-1100)),
 Word(drinken, language=Middle English (1100-1500)),
 Word(drincan, language=Old English (ca. 450-1100))]

>>> print(ety.tree('aerodynamically'))
aerodynamically (English)
├── -ally (English)
└── aerodynamic (English)
    ├── aero- (English)
    │   └── ἀήρ (Ancient Greek (to 1453))
    └── dynamic (English)
        └── dynamique (French)
            └── δυναμικός (Ancient Greek (to 1453))
                └── δύναμις (Ancient Greek (to 1453))
                    └── δύναμαι (Ancient Greek (to 1453))

【讨论】:

    【解决方案2】:

    使用PyDictionary 可能是一个不错的选择

    【讨论】:

    • 但它是否提供了我可以提取的词源?
    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2016-07-18
    • 2011-07-06
    相关资源
    最近更新 更多