【问题标题】:How to use new .sbl Snowball algorithm in Python?如何在 Python 中使用新的 .sbl Snowball 算法?
【发布时间】:2018-02-10 08:39:32
【问题描述】:

我想在 Python 中使用立陶宛语词干分析器,但是,像 NLTK 这样的常用工具中没有立陶宛语。

但是,我可以找到立陶宛词干分析器 herehere 的雪球 .sbl 文件。

但是如何在 Python 中使用它们呢?

我能够found 是获取 .c 文件的命令行方法。但是接下来呢?

正如雪球官方page 所述,有 PyStemmer - 雪球的 Python 接口。但是在那里我找不到任何方法来使用新的或自定义的 .sbl 算法。

那么如何将新的 .sbl 算法导入 Python 呢?

【问题讨论】:

  • 你找到解决办法了吗?

标签: python stemming snowball


【解决方案1】:

截至目前,立陶宛语已添加到 Snowball git repo,但 pyStemmer 使用的是不包含它的旧版本的存储库。我没有设法在 python 中正确安装新版本的 Snowball,而是使用带有 python 子进程模块的 c 可执行文件。

为此,您只需要克隆存储库,使用命令make 安装它,然后您就可以获得可执行的词干。您可以在 unix 终端 ./stemwords -l lt 中使用命令测试立陶宛语,然后输入您想要处理的单词。

将它与 python 的子进程一起用于处理包含要逐行提取的单词的文件:

import subprocess
args = ("./stemwords", "-l", "lt", "-i", "input_file.txt", "-o", "output_file.txt")
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
popen.wait()

输入文件:

Kodėl
moteriai
vienišai
ištekėjusiai

输出文件:

kod
mot
vieniš
ištekėjus

【讨论】:

  • 如何在windows上安装? [链接]sourceforge.net/projects/gnuwin32make在windows上抛出错误:The system cannot find the path specified. GNUmakefile:48: algorithms.mk: No such file or directory make: *** No rule to make target `algorithms.mk'. Stop.
猜你喜欢
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 2011-07-30
  • 2019-10-13
  • 1970-01-01
  • 2011-03-03
  • 2015-04-12
  • 2021-11-24
相关资源
最近更新 更多