- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 SpaCy 来获取命名实体。但是,它总是将新线符号错误地标记为命名实体。
下面是输入文本。
mytxt = """<?xml version="1.0"?>
<nitf>
<head>
<title>KNOW YOUR ROLE ON SUPER BOWL LIII.</title>
</head>
<body>
<body.head>
<hedline>
<hl1>KNOW YOUR ROLE ON SUPER BOWL LIII.</hl1>
</hedline>
<distributor>Gale Group</distributor>
</body.head>
<body.content>
<p>Montpelier: <org>Department of Motor Vehicles</org>, has issued the following
news release:</p>
<p>Be a designated sober driver, help save lives. Remember these tips
on game night:</p>
<p>Know your State's laws: refusing to take a breath test in many
jurisdictions could result in arrest, loss of your driver's
license, and impoundment of your vehicle. Not to mention the
embarrassment in explaining your situation to family, friends, and
employers.</p>
<p>In case of any query regarding this article or other content needs
please contact: <a href="mailto:editorial@plusmediasolutions.com">editorial@plusmediasolutions.com</a></p>
</body.content>
</body>
</nitf>
"""
下面是我的代码:
CONTENT_XML_TAG = ('p', 'ul', 'h3', 'h1', 'h2', 'ol')
soup = BeautifulSoup(mytxt, 'xml')
spacy_model = spacy.load('en_core_web_sm')
content = "\n".join([p.get_text() for p in soup.find('body.content').findAll(CONTENT_XML_TAG)])
print(content)
section_spacy = spacy_model(content)
tokenized_sentences = []
for sent in section_spacy.sents:
tokenized_sentences.append(sent)
for s in tokenized_sentences:
labels = [(ent.text, ent.label_) for ent in s.ents]
print(Counter(labels))
打印输出:
Counter({('\n', 'GPE'): 2, ('Department of Motor Vehicles', 'ORG'): 1})
Counter({('\n', 'GPE'): 1})
Counter({('\n', 'GPE'): 2, ('State', 'ORG'): 1})
Counter({('\n', 'GPE'): 3})
Counter({('\n', 'GPE'): 1})
我不敢相信 SpaCy 会有这样的错误分类。我错过了什么吗?
最佳答案
from bs4 import BeautifulSoup
import spacy
CONTENT_XML_TAG = ('p', 'ul', 'h3', 'h1', 'h2', 'ol')
soup = BeautifulSoup(mytxt, 'xml')
spacy_model = spacy.load('en_core_web_sm')
content = "\n".join([p.get_text() for p in soup.find('body.content').findAll(CONTENT_XML_TAG)])
section_spacy = spacy_model(content)
def remove_whitespace_entities(doc):
doc.ents = [e for e in doc.ents if not e.text.isspace()]
return doc
spacy_model.add_pipe(remove_whitespace_entities, after='ner')
doc = spacy_model(content)
print(doc.ents)
关于python - SpaCy 将新行 (\n) 标记为 GPE 命名实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55154045/
我想将我的 Eclipse 谷歌插件回滚到以前的版本。我怎样才能做到这一点? 最佳答案 使用 Help>About>Installation Details>Installation History
我的 eclipse 4.2 Juno 无法安装与 Google App Engine Java SDK 和 Google Web Toolkit 相关的任何内容。我见过类似的问题和答案。他们建议使用
我尝试将 Eclipse Indigo 与 Google Plugin for Eclipse (GPE) 结合使用,但找不到 GPE 3.7。我的意思是,我会对 GPE 3.6 感到满意。 现在我在
我正在尝试实现一个代码来使用 OpenWeatherMap API 和 NLTK 来检查特定区域的天气状况,以查找实体名称识别。但我无法找到将 GPE 中存在的实体(给出位置)(在本例中为芝加哥)传递
我正在使用 SpaCy 来获取命名实体。但是,它总是将新线符号错误地标记为命名实体。 下面是输入文本。 mytxt = """ KNOW YOUR ROLE ON SUPER BOWL LIII.
我正在使用 google eclipse 插件在 Eclipse 中使用 GWT 和 GAE。有时我只想快速修复服务器。我更改了我的服务器代码中的某些内容并重新部署,但 GWT 代码也全部重新编译。此
我只需要两个与应用引擎相关的 jar(appengine-api-1.0-sdk-1.6.0.jar 和 appengine-api-labs-1.6.0.jar 准确地说)在我的 WEB-INF/l
我读了最后一篇与 maven 项目集成良好的 GPE。 因此,我使用 maven-gae-plugin 从 cmd 行创建了一个 maven 项目。 然后作为maven项目导入到eclipse中。 但
当我尝试使用 eclipse 界面生成客户端库时,我得到了这个错误: eclipse.buildId=M20120914-1800 java.version=1.7.0_25 java.vendor=
将现有 GWT 项目导入 Eclipse 后,WEB-INF/lib 目录为空并有一个红色“X”。我知道这个项目使用 GAE,所以.. 我转到项目属性 -> Google -> Web Toolkit
我是一名优秀的程序员,十分优秀!