spacy支持像词缀规则和字典一样自由拆分词缀
spacy-affixes的Python项目详细描述
间距附加
spacy支持词缀拆分,以便像词缀规则和字典一样自由。
- 免费软件:apache软件许可证2.0
- 文档:https://spacy-affixes.readthedocs.io。
使用量
这个库是为将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
orAFFIXES_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 itsaffix_text
- pattern: Regular expression to match, (ex.
- lexicon: Dictionary keyed by word with values for lemma, EAGLE code, UD POS, and UD Tags.
转换Freeling数据。考虑到如果您使用免费数据,您实际上是同意他们的许可证,这可能会在发布中有影响,如果您自己的代码。如果安装了,
spacy-affixes
将查找环境变量FREELINGDIR
或FREELINGSHARE
以查找词缀规则和字典文件并对其进行处理。如果您没有安装freeling,则始终可以运行download
命令:
python -m spacy_affixes download <lang> <version>
其中lang
是受支持语言的2字符iso 639-1代码,以及version
是github存储库中的标记版本。
注释
- 由于缺少良好的映射,因此还不支持通用依赖项标记。
- 有些决定可能会让人觉得很奇怪,因为这个图书馆一开始的目的只是将西班牙文本中的陈词滥调一分为二。
历史记录
0.1.0(2019-04-02)
- pypi上的第一个版本。