spacy支持像词缀规则和字典一样自由拆分词缀

spacy-affixes的Python项目详细描述


间距附加

https://img.shields.io/pypi/v/spacy-affixes.svghttps://img.shields.io/travis/linhd-postdata/spacy-affixes.svgDocumentation Status

spacy支持词缀拆分,以便像词缀规则和字典一样自由。

使用量

这个库是为将clitics从动词中分离而生的,因此pos标记可以与spacy模型一起使用。

fromspacy_affixesimportAffixesMatchernlp=spacy.load("es")affixes_matcher=AffixesMatcher(nlp,split_on=["VERB"])nlp.add_pipe(affixes_matcher,name="affixes",before="tagger")fortokeninnlp("Yo mismamente podría hacérselo bien."):print(token.text,token.lemma_,token.pos_,token.tag_,token._.has_affixes,token._.affixes_rule,token._.affixes_kind,token._.affixes_text,token._.affixes_length,)

输出将是

Hay Hay AUX AUX__Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin False None None None 0
que que SCONJ SCONJ___ False None None None 0
hacér hacer VERB  True suffix_selo suffix hacer 2
se se PRON PRON__Person=3 False None None None 0
lo el PRON PRON__Case=Acc|Gender=Masc|Number=Sing|Person=3|PronType=Prs False None None None 0
todo todo PRON PRON__Gender=Masc|Number=Sing|PronType=Ind False prefix_todo None None 0
, , PUNCT PUNCT__PunctType=Comm False None None None 0
y y CONJ CCONJ___ False None None None 0
rápidamente rápidamente ADV ADV___ False suffix_mente None None 0
además además ADV ADV___ False prefix_a None None 0
. . PUNCT PUNCT__PunctType=Peri False None None None 0

但是,如果需要,带后缀的单词也可以被拆分,或者几乎任何规则匹配的单词, 只需将通用依赖pos的列表传递给参数split_on。传入split_on="*"将使AffixesMatcher()尝试在找到的所有内容上进行拆分。

规则与词汇< EH3>

由于许可问题,默认情况下,{{CD4}}不带任何规则或词典。有两种方法可以将数据输入spacy-affixes

    < L> > P>用自己感兴趣的实体创建规则和词典,并使用^ {CD6>}传递它们。其格式如下。

    • rules: Dictionary of rules for affixes handling. Each dict uses a key that contains the pattern to match and the value is a list of dicts with the corresponding rule parameters:
      • pattern: Regular expression to match, (ex. r"ito$") If a match is found, it gets removed from the token
      • kind: AFFIXES_SUFFIX or AFFIXES_PREFIX
      • pos_re: EAGLE regular expression to match, (ex. r"V")
      • strip_accent: Boolean indicating whether accents should be stripped in order to find the rest of the token in the lexicon
      • affix_add: List of strings to add to the rest of the token to find it in the lexicon. Each element in the list is tried separately, as in an OR condition. The character * means add nothing (ex. ["*", "io"])
      • affix_text: List of Strings with the text to the rest of the token as individual tokens. For example, a rule for dígamelo might have ["me", "lo"] as its affix_text
    • lexicon: Dictionary keyed by word with values for lemma, EAGLE code, UD POS, and UD Tags.
  1. 转换Freeling数据。考虑到如果您使用免费数据,您实际上是同意他们的许可证,这可能会在发布中有影响,如果您自己的代码。如果安装了,spacy-affixes将查找环境变量FREELINGDIRFREELINGSHARE以查找词缀规则和字典文件并对其进行处理。如果您没有安装freeling,则始终可以运行download命令:

python -m spacy_affixes download <lang> <version>

其中lang是受支持语言的2字符iso 639-1代码,以及version是github存储库中的标记版本。

注释

  • 由于缺少良好的映射,因此还不支持通用依赖项标记。
  • 有些决定可能会让人觉得很奇怪,因为这个图书馆一开始的目的只是将西班牙文本中的陈词滥调一分为二。

历史记录

0.1.0(2019-04-02)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Thumbnailator库将图像转换为cmyk   Java反射从目录中的类运行测试   JavaEclipseJDT编译器说方法未定义,但EclipseIDE没有   重构如何重构一行重复的java代码   java Eclipse:使用删除线文本呈现自定义注释   java问题与ArrayList复制数据   java如何在swagger中传递访问令牌?   使用另一个java文件运行java文件时出错   java为什么谷歌云存储生成的上传链接在成功上传后不会失效?   java将我的客户端PC重定向到默认登录页面   java hibernate c3p0配置mysql问题   java和java之间的区别。尼奥。文件文件和java。伊奥。文件   列出java循环并向映射中添加值   java为什么OJ报告这段代码的运行时错误?