基于leff的定制法语pos和lemmatizer
spacy-lefff的Python项目详细描述
spacy lefff:基于lefff的自定义法语pos和lemmatizer,用于spacy
spacy v2.0扩展和管道组件,用于添加基于Lefff的法语pos和lemmatizer。
on版本v2.0.17,Spacy更新的法语元素化
说明
此包允许将lefff引理化和词性标记带到spacy自定义管道。
当pos标记和lemmatizaion组合在一个管道中时,与内置的spacy法语处理相比,它改进了法语文本的预处理。
它仍然是一个WIP(正在工作),因此匹配可能不完美,但如果包未找到任何内容,仍然可以使用spaCy
的默认结果。
安装
spacy-lefff
需要spacy
<;=v2.0.12。
pip install spacy-lefff
用法
导入并初始化您的nlp
spacy对象,并在分析文档后添加自定义组件,这样您就可以使用pos标记了。
注意使用UTF-8
。
如果pos和lemmatizer都捆绑在一起,则需要通过设置after_melt
告诉lemmatizer使用熔融映射,否则它将使用语音映射的spacy部分。
default
选项允许在没有找到引理的情况下默认返回单词。
使用Spacy到Lefff的当前映射为:
{"ADJ":"adj","ADP":"det","ADV":"adv","DET":"det","PRON":"cln","PROPN":"np","NOUN":"nc","VERB":"v","PUNCT":"poncts"}
熔融标记集
熔融标签表:
ADJ adjective
ADJWH interrogative adjective
ADV adverb
ADVWH interrogative adverb
CC coordination conjunction
CLO object clitic pronoun
CLR reflexive clitic pronoun
CLS subject clitic pronoun
CS subordination conjunction
DET determiner
DETWH interrogative determiner
ET foreign word
I interjection
NC common noun
NPP proper noun
P preposition
P+D preposition+determiner amalgam
P+PRO prepositon+pronoun amalgam
PONCT punctuation mark
PREF prefix
PRO full pronoun
PROREL relative pronoun
PROWH interrogative pronoun
V indicative or conditional verb form
VIMP imperative verb form
VINF infinitive verb form
VPP past participle
VPR present participle
VS subjunctive verb form
代码片段
您需要在:python -m spacy download fr
之前安装french spacy包。
- 使用
LefffLemmatizer
而不使用POSTagger
: 的示例
importspacyfromspacy_lefffimportLefffLemmatizer,POSTaggernlp=spacy.load('fr')french_lemmatizer=LefffLemmatizer()nlp.add_pipe(french_lemmatizer,name='lefff')doc=nlp(u"Apple cherche a acheter une startup anglaise pour 1 milliard de dollard")fordindoc:print(d.text,d.pos_,d._.lefff_lemma,d.tag_,d.lemma_)
Text | spaCy POS | Lefff Lemma | spaCy tag | spaCy Lemma |
---|---|---|---|---|
Apple | ADJ | None | ADJ__Number=Sing | Apple |
cherche | NOUN | cherche | NOUN__Number=Sing | chercher |
a | AUX | None | AUX__Mood=Ind Number=Sing Person=3 Tense=Pres VerbForm=Fin | avoir |
acheter | VERB | acheter | VERB__VerbForm=Inf | acheter |
une | DET | un | DET__Definite=Ind Gender=Fem Number=Sing PronType=Art | un |
startup | ADJ | None | ADJ__Number=Sing | startup |
anglaise | NOUN | anglaise | NOUN__Gender=Fem Number=Sing | anglais |
pour | ADP | None | ADP___ | pour |
1 | NUM | None | NUM__NumType=Card | 1 |
milliard | NOUN | milliard | NOUN__Gender=Masc Number=Sing NumType=Card | milliard |
de | ADP | un | ADP___ | de |
dollard | NOUN | None | NOUN__Gender=Masc Number=Sing | dollard |
- 使用
POSTagger
: 的示例
importspacyfromspacy_lefffimportLefffLemmatizer,POSTaggernlp=spacy.load('fr')pos=POSTagger()french_lemmatizer=LefffLemmatizer(after_melt=True,default=True)nlp.add_pipe(pos,name='pos',after='parser')nlp.add_pipe(french_lemmatizer,name='lefff',after='pos')doc=nlp(u"Apple cherche a acheter une startup anglaise pour 1 milliard de dollard")fordindoc:print(d.text,d.pos_,d._.melt_tagger,d._.lefff_lemma,d.tag_,d.lemma_)
Text | spaCy POS | MElt Tag | Lefff Lemma | spaCy tag | spaCy Lemma |
---|---|---|---|---|---|
Apple | ADJ | NPP | apple | ADJ__Number=Sing | Apple |
cherche | NOUN | V | chercher | NOUN__Number=Sing | chercher |
a | AUX | V | avoir | AUX__Mood=Ind Number=Sing Person=3 Tense=Pres VerbForm=Fin | avoir |
acheter | VERB | VINF | acheter | VERB__VerbForm=Inf | acheter |
une | DET | DET | un | DET__Definite=Ind Gender=Fem Number=Sing PronType=Art | un |
startup | ADJ | NC | startup | ADJ__Number=Sing | startup |
anglaise | NOUN | ADJ | anglais | NOUN__Gender=Fem Number=Sing | anglais |
pour | ADP | P | pour | ADP___ | pour |
1 | NUM | DET | 1 | NUM__NumType=Card | 1 |
milliard | NOUN | NC | milliard | NOUN__Gender=Masc Number=Sing NumType=Card | milliard |
de | ADP | P | de | ADP___ | de |
dollard | NOUN | NC | dollard | NOUN__Gender=Masc Number=Sing | dollard |
我们可以看到cherche
和startup
在默认pos标记符中都没有正确标记。
spaCy
将其分类为NOUN
和ADJ
,而MElT
将其分类为V
和NC
。
学分
Sagot,B.(2010年)。The Lefff, a freely available and large-coverage morphological and syntactic lexicon for French。第七届语言资源与评价国际会议(lrec 2010)。
Beno_t Sagot关于Lefff的网页
http://alpage.inria.fr/~sagot/lefff-en.html
Claude Coulombe的第一个工作是用python支持lefff:https://github.com/ClaudeCoulombe