跳转到主要内容

A Cython MeCab包装器,用于快速、Pythonic的日语分词。

项目描述

Open in Streamlit Current PyPI packages Test Status PyPI - Downloads Supported Platforms

fugashi

fugashi by Irasutoya

fugashi是一个Cython包装器,用于MeCab,这是一个日语分词和形态分析工具。提供了Linux、OSX(Intel)和Win64的Wheel版本,并且UniDic安装简单。

不需要用英语写issue。

查看交互式演示,查看博客文章以了解fugashi存在的背景和一些设计决策,或查看本指南以了解日语分词的基本介绍。

如果您使用的是没有提供Wheel的平台,您需要先安装MeCab。建议您从源代码安装。如果您需要在Windows上从源代码构建,建议使用@chezou的分支;有关官方存储库问题的说明,请参阅问题#44

没有Wheel的已知平台

  • 基于musl的发行版,如alpine #77
  • PowerPC
  • Windows 32位

用法

from fugashi import Tagger

tagger = Tagger('-Owakati')
text = "麩菓子は、麩を主材料とした日本の菓子。"
tagger.parse(text)
# => '麩 菓子 は 、 麩 を 主材 料 と し た 日本 の 菓子 。'
for word in tagger(text):
    print(word, word.feature.lemma, word.pos, sep='\t')
    # "feature" is the Unidic feature data as a named tuple

安装字典

fugashi需要一个字典。推荐使用UniDic,并提供了两个易于安装的版本。

  • unidic-lite,Unidic 2.1.2的略微修改版本(来自2013年),相对较小
  • unidic,最新的UniDic 3.1.0,在磁盘上占770MB,需要单独下载步骤

如果您只是想确保一切正常工作,可以从unidic-lite开始,但为了更严肃的处理,建议使用unidic。对于生产使用,通常还需要生成自己的字典;有关详细信息,请参阅MeCab文档

要获取这两个字典中的任何一个,您可以直接使用pip安装,或执行以下操作

pip install 'fugashi[unidic-lite]'

# The full version of UniDic requires a separate download step
pip install 'fugashi[unidic]'
python -m unidic download

有关可用的不同MeCab字典的更多信息,请参阅这篇文章

字典使用

在编写fugashi时,假设您会使用Unidic处理日语,但它支持任意词典。

如果您使用除了Unidic之外的词典,可以使用GenericTagger如下

from fugashi import GenericTagger
tagger = GenericTagger()

# parse can be used as normal
tagger.parse('something')
# features from the dictionary can be accessed by field numbers
for word in tagger(text):
    print(word.surface, word.feature[0])

您还可以创建一个词典包装器以获取特征信息作为命名元组。

from fugashi import GenericTagger, create_feature_wrapper
CustomFeatures = create_feature_wrapper('CustomFeatures', 'alpha beta gamma')
tagger = GenericTagger(wrapper=CustomFeatures)
for word in tagger.parseToNodeList(text):
    print(word.surface, word.feature.alpha)

引用

如果您在研究中使用fugashi,如果您能引用此论文将不胜感激。您可以在ACL AnthologyArxiv上阅读。

@inproceedings{mccann-2020-fugashi,
    title = "fugashi, a Tool for Tokenizing {J}apanese in Python",
    author = "McCann, Paul",
    booktitle = "Proceedings of Second Workshop for NLP Open Source Software (NLP-OSS)",
    month = nov,
    year = "2020",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/2020.nlposs-1.7",
    pages = "44--51",
    abstract = "Recent years have seen an increase in the number of large-scale multilingual NLP projects. However, even in such projects, languages with special processing requirements are often excluded. One such language is Japanese. Japanese is written without spaces, tokenization is non-trivial, and while high quality open source tokenizers exist they can be hard to use and lack English documentation. This paper introduces fugashi, a MeCab wrapper for Python, and gives an introduction to tokenizing Japanese.",
}

替代方案

如果您在使用fugashi时遇到问题,请随时提交问题。然而,有些情况下可能最好使用不同的库。

许可和版权声明

fugashi是在MIT许可证的条款下发布的。请广泛传播。

fugashi是MeCab的包装器,fugashi的wheel包括MeCab二进制文件。MeCab是由Taku Kudo <taku@chasen.org>和日本电信电话公司提供的版权免费软件,并在BSD许可证下重新分发。

项目详情


发布历史 发布通知 | RSS源

下载文件

下载适合您平台的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。

源分布

fugashi-1.3.2.tar.gz (338.8 kB 查看哈希值)

上传时间: 源代码

构建分布

fugashi-1.3.2-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (508.0 kB 查看哈希值)

上传时间: PyPy macOS 10.9+ x86-64

fugashi-1.3.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (507.9 kB 查看哈希值)

上传时间: PyPy macOS 10.9+ x86-64

fugashi-1.3.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (507.1 kB 查看哈希值)

上传时间: PyPy macOS 10.9+ x86-64

fugashi-1.3.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (507.1 kB 查看哈希值)

上传时间: PyPy macOS 10.9+ x86-64

fugashi-1.3.2-cp312-cp312-win_amd64.whl (497.8 kB 查看哈希值)

上传时间: CPython 3.12 Windows x86-64

fugashi-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (622.1 kB 查看哈希值)

上传时间: CPython 3.12 manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (605.9 kB 查看哈希值)

上传时间: CPython 3.12 manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp312-cp312-macosx_11_0_arm64.whl (512.6 kB 查看哈希值)

上传时间: CPython 3.12 macOS 11.0+ ARM64

fugashi-1.3.2-cp312-cp312-macosx_10_9_x86_64.whl (518.2 kB 查看哈希值)

上传时间: CPython 3.12 macOS 10.9+ x86-64

fugashi-1.3.2-cp312-cp312-macosx_10_9_universal2.whl (559.9 kB 查看哈希值)

上传时间: CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

fugashi-1.3.2-cp311-cp311-win_amd64.whl (498.3 kB 查看哈希值)

上传时间: CPython 3.11 Windows x86-64

fugashi-1.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (606.7 kB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (594.3 kB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp311-cp311-macosx_11_0_arm64.whl (513.1 kB 查看哈希值)

上传时间: CPython 3.11 macOS 11.0+ ARM64

fugashi-1.3.2-cp311-cp311-macosx_10_9_x86_64.whl (519.5 kB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ x86-64

fugashi-1.3.2-cp311-cp311-macosx_10_9_universal2.whl (561.9 kB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

fugashi-1.3.2-cp310-cp310-win_amd64.whl (499.1 kB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

fugashi-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (600.9 kB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (586.9 kB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp310-cp310-macosx_11_0_arm64.whl (514.8 kB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

fugashi-1.3.2-cp310-cp310-macosx_10_9_x86_64.whl (521.0 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ x86-64

fugashi-1.3.2-cp310-cp310-macosx_10_9_universal2.whl (565.2 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

fugashi-1.3.2-cp39-cp39-win_amd64.whl (500.2 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

fugashi-1.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (614.5 kB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (602.2 kB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp39-cp39-macosx_11_0_arm64.whl (514.5 kB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

fugashi-1.3.2-cp39-cp39-macosx_10_9_x86_64.whl (520.9 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ x86-64

fugashi-1.3.2-cp39-cp39-macosx_10_9_universal2.whl (564.9 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

fugashi-1.3.2-cp38-cp38-win_amd64.whl (500.2 kB 查看哈希值)

上传时间 CPython 3.8 Windows x86-64

fugashi-1.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (616.0 kB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (603.3 kB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp38-cp38-macosx_11_0_arm64.whl (513.2 kB 查看哈希值)

上传时间 CPython 3.8 macOS 11.0+ ARM64

fugashi-1.3.2-cp38-cp38-macosx_10_9_x86_64.whl (519.5 kB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ x86-64

fugashi-1.3.2-cp38-cp38-macosx_10_9_universal2.whl (562.0 kB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

fugashi-1.3.2-cp37-cp37m-win_amd64.whl (499.5 kB 查看哈希值)

上传时间 CPython 3.7m Windows x86-64

fugashi-1.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (584.1 kB 查看哈希值)

上传时间 CPython 3.7m manylinux: glibc 2.17+ x86-64

fugashi-1.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (570.7 kB 查看哈希值)

上传时间 CPython 3.7m manylinux: glibc 2.17+ ARM64

fugashi-1.3.2-cp37-cp37m-macosx_10_9_x86_64.whl (518.3 kB 查看哈希值)

上传于 CPython 3.7m macOS 10.9+ x86-64

由以下组织支持