我正在使用Spacy以及一些自定义代码来对工作进行一些自然语言处理。我们想做一些事情,以便通过使用纸张上的位置来找到撰写论文的地方,并且很好奇是否存在可以找到诸如国家,城市,州等位置的软件包?感谢您的宝贵时间。
答案 0 :(得分:1)
Spacy已将实体识别(NER)命名。预训练模型具有的一种实体类型是LOC
用于定位。在某些模型中,还有GPE
(地缘政治实体)。我在下面使用的en_core_web_sm
同时具有LOC
和GPE
。 (完整列表位于https://spacy.io/api/annotation#named-entities)。另请参阅:https://spacy.io/usage/linguistic-features#named-entities
开箱即用并不是完美的,但它可能会有用。
最小示例:
import spacy # install cmd: pip3 install spacy --user
import en_core_web_sm # install cmd: python3 -m spacy download en_core_web_sm --user
text='San Fransisco is in California and my friend Frank lives there, close to the bay. He purchased his first house last January.'
NLP = en_core_web_sm.load()
output = NLP(text)
for item in output.ents:
print(item.label_, item)
具有以下输出:
GPE San Fransisco
GPE California
PERSON Frank
DATE last January