- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个由词形还原名词和名词块组成的文档语料库。我正在使用此代码:
import spacy
nlp = spacy.load('en_core_web_sm')
def lemmatizer(doc, allowed_postags=['NOUN']):
doc = [token.lemma_ for token in doc if token.pos_ in allowed_postags]
doc = u' '.join(doc)
return nlp.make_doc(doc)
nlp.add_pipe(nlp.create_pipe('merge_noun_chunks'), after='ner')
nlp.add_pipe(lemmatizer, name='lemm', after='merge_noun_chunks')
doc_list = []
for doc in data:
pr = nlp(doc)
doc_list.append(pr)
句子
'the euro area has advanced a long way as a monetary union'
识别名词块后
['the euro area', 'advanced', 'long', 'way', 'a monetary union']
和词形还原得到:
['euro', 'area', 'way', 'monetary', 'union']
.
['the euro area','way', 'a monetary union']
或
['the_euro_area','way', 'a_monetary_union']
?
最佳答案
我不认为你的问题是关于词形还原。
此方法适用于您的示例。
# merge noun phrase and entities
def merge_noun_phrase(doc):
spans = list(doc.ents) + list(doc.noun_chunks)
spans = spacy.util.filter_spans(spans)
with doc.retokenize() as retokenizer:
for span in spans:
retokenizer.merge(span)
return doc
sentence = "the euro area has advanced a long way as a monetary union"
doc = nlp(sentence)
doc2 = merge_noun_phrase(doc)
for token in doc2:
print(token)
#['the euro area', 'way', 'a monetary union']
我必须注意,我使用的是 spacy2.3.5,也许是
spacy.util.filter_spans
在最新版本中已弃用。这个答案会帮助你。 :)
doc = nlp("the euro area has advanced a long way as a monetary union")
for chunk in doc.noun_chunks:
print(chunk.lemma_)
#['the euro area', 'a monetary union']
根据
What is the lemma for 'two pets'中的回答,“在跨度级别查看引理可能不是很有用,在 token 级别上工作更有意义。”
关于nlp - 名词和名词 block 的空间词形还原,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66332810/
是否可以使用 R 包 openNLP 提取 noun+noun 或 (adj|noun)+noun?也就是说,我想使用语言过滤来提取候选名词短语。你能指导我该怎么做吗?非常感谢。 感谢您的回复。这是代
我正在寻找一个免费的(可下载的)名词词典来用作实际的单词生成器 - 与验证码相似但不同。 有人知道这样的东西是否可用吗? 谢谢, 凯尔 最佳答案 Kevin's Word List Page包括词性数
通常单词列表是 1 个包含所有内容的文件,但是是否有可单独下载的名词列表、动词列表、形容词列表等? 我特别需要它们来学习英语。 最佳答案 如果您仅从 wordnet.princeton.edu/dow
我正在使用 Rails 4,我遇到了 this cool gist前几天。 无论如何,我如何使用 Rails 做一些类似的事情,我可以从两个数组中随机选择以生成一个有点独特的名称? 我知道有用于此的
我想要一个 python 库函数,它可以跨不同的词性进行翻译/转换。有时它应该输出多个单词(例如“coder”和“code”都是动词“to code”的名词,一个是主语,另一个是宾语) # :: St
根据 this guide在设计 REST API 端点时,我们不应该在 URL 中使用 Action /动词(例如 /addNewEmployee),如果我们想执行一个 Action ,我们应该只使
根据 this guide在设计 REST API 端点时,我们不应该在 URL 中使用 Action /动词(例如 /addNewEmployee),如果我们想执行一个 Action ,我们应该只使
我有一个用 @Path 注释的类,如下所示: @Path("widgets") @Produces(MediaType.APPLICATION_XML) public class WidgetReso
我是一名优秀的程序员,十分优秀!