【问题标题】:NLTK wordnet does not contain vocabulary term - PythonNLTK wordnet 不包含词汇术语 - Python
【发布时间】:2018-06-13 22:09:35
【问题描述】:

我的程序中的一个函数可以找到某些词汇的定义,这对我程序的其他部分很有用。然而,似乎并不是每个词汇都出现在 wordnet 中。 我发现定义如下:

y = wn.synset(w + '.n.01').definition()

其中“w”是从列表中提供的众多词汇之一(不包括程序的其余部分,因为它有太多不相关的代码)。但是,当列表到达术语“连接酶”时,会出现以下错误:

第 1298 行,在同义词集中 引发 WordNetError(消息 %(引理,pos)) nltk.corpus.reader.wordnet.WordNetError:词性为“n”的没有引理“连接酶”

有没有绕过这个或不同的方法来找到这些术语的定义不在 wordnet 中?我的程序正在处理各种科学术语,所以当我在列表中添加更多单词时,这种情况可能会更频繁地发生。

【问题讨论】:

    标签: python nltk wordnet


    【解决方案1】:

    您不应假设 WordNet 知道某个单词。检查是否有任何相关的同义词集,只有在至少有一个时才要求定义:

    for word in ["ligase", "world"]: # Your word list
        ss = wn.synsets(word)
        if ss:
            definition = ss[0].definition() 
            print("{}: {}".format(word, definition))
        else:
            print("### Word {} not found".format(word))
    
    #### Word ligase not found
    #world: everything that exists anywhere
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 2013-09-22
      相关资源
      最近更新 更多