在此添加简短描述!

spacy-wordnet的Python项目详细描述


Spacy wordnet

spacy wordnet是一个简单的自定义组件,用于将WordNetMultiWordnetWordNet domainsspaCy一起使用。

组件将NLTK wordnet interface与wordnet域结合起来,允许用户:

  • 获取已处理令牌的所有语法集。例如,获取单词bank的所有语法集(词义)。
  • 按域获取和筛选语法集。例如,获取金融领域中动词withdraw的同义词。

开始

spacy wordnet组件可以很容易地集成到spacy管道中。您只需要以下各项:

先决条件

  • python 3.x
  • 间距

您还需要安装以下NLTK WordNet数据:

python -m nltk.downloader wordnet
python -m nltk.downloader omw

安装

pip install spacy-wordnet

用法

importspacyfromspacy_wordnet.wordnet_annotatorimportWordnetAnnotator# Load an spacy model (supported models are "es" and "en") nlp=spacy.load('en')nlp.add_pipe(WordnetAnnotator(nlp.lang),after='tagger')token=nlp('prices')[0]# wordnet object link spacy token with nltk wordnet interface by giving acces to# synsets and lemmas token._.wordnet.synsets()token._.wordnet.lemmas()# And automatically tags with wordnet domainstoken._.wordnet.wordnet_domains()# Imagine we want to enrich the following sentence with synonymssentence=nlp('I want to withdraw 5,000 euros')# spaCy WordNet lets you find synonyms by domain of interest# for example economyeconomy_domains=['finance','banking']enriched_sentence=[]# For each token in the sentencefortokeninsentence:# We get those synsets within the desired domainssynsets=token._.wordnet.wordnet_synsets_for_domain(economy_domains)ifsynsets:lemmas_for_synset=[]forsinsynsets:# If we found a synset in the economy domains# we get the variants and add them to the enriched sentencelemmas_for_synset.extend(s.lemma_names())enriched_sentence.append('({})'.format('|'.join(set(lemmas_for_synset))))else:enriched_sentence.append(token.text)# Let's see our enriched sentenceprint(' '.join(enriched_sentence))# >> I (need|want|require) to (draw|withdraw|draw_off|take_out) 5,000 euros

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

推荐PyPI第三方库


热门话题
java对角差分   不满意链接错误:org。opencv。海吉。海吉。imread_0(OpenCV Java)   java在Eclipse中使用mavenreleaseplugin   java在加载时冻结JVM/Tomcat,而safepointlog记录使用safepoints“ThreadStop”条目   c#在visual studio中进行调试时是否可以像在eclipse(java)中那样编辑代码   java更改生成的jaxb类的类名和包结构   java我怎样才能同时使用JTextField和JLabel?   Java swing使用按钮更改包含图标的标签的颜色   java如何实例化。我在运行时得到的类文件   java无法使用XPath为站点160by2定位WebElements mobile和message box。com和way2sms。通用域名格式   java将MYSQL日期时间值转换为UTC时区格式yyyyMMdd'T'HH:mm:ss'Z'   java在Bundle中,如何找到给定键的值的类型?   使用Java流使用数据库游标   java阻止在过滤适配器数据时重新加载图像[Android]