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 Access文本视图   安卓在Java中,我什么时候应该用*导入整个包,而不是从包中导入单个对象?   JavaSpringMVC:请解释@RequestParam和@ModelAttribute之间的区别   java Flyway Ant构建未迁移   java“没有可供下载的文件”   如何解决java静态名称冲突?   我是否需要框架来补充JavaEE6、JSF2 WebApp?哪一个?   java如何传递HttpServletRequest参数?   只有java的视频不会播放声音。为什么?   java在Maven3中做这样的属性重写工作吗?   java计算Android中两个标记之间的距离   Javascript页面加载中的java复选框持久性问题   java序列化lambda函数的映射   java使用jersey、maven和eclipse配置swagger   java我可以在oncreate方法之外使用setContentView吗?   java在使用JAXRS响应类返回实体时遇到异常   java规范了加密和解密文本的文本编写方法   java如何更改ChoiceBox的默认大小?   java在Android上暂时禁用PIN/密码锁