【问题标题】:Is there a way to explicitly specify an alternative location for NLTK's corpora/wordnet? [duplicate]有没有办法为 NLTK 的语料库/wordnet 明确指定一个替代位置? [复制]
【发布时间】:2016-09-28 03:00:35
【问题描述】:

我有一个使用 NLTK 的 WordNetLemmatizer 的脚本,它反过来要求语料库/wordnet 出现在用户系统的某个位置。 WordNetLemmatizer 导入如下:

from nltk.stem.wordnet import WordNetLemmatizer

我的脚本(实际上,一个相当庞大的程序)被编译成可执行文件,我不能指望最终用户安装 NLTK 组件。我想在我的程序目录中包含语料库/wordnet。

有没有办法让 WordNetLemmatizer 在明确指定的位置查找语料库/wordnet,特别是在与我的 python 脚本生成的可执行文件相同的目录中?

【问题讨论】:

    标签: python nltk


    【解决方案1】:

    您是否尝试在脚本中添加以下行?

    nltk.path.append('/home/user/some_directory/nltk_data/')
    

    问候, 格热戈日

    【讨论】:

    • nltk.data.path.append 可以解决问题。谢谢。
    猜你喜欢
    • 2012-10-21
    • 2016-07-09
    • 2013-01-08
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多