0

我试图从文本中仅提取城市名称,因此我将 geograpy 库与 python 一起使用,但在输出中,已提取了一些其他名称。这是我的代码:

from geograpy.extraction import Extractor
text6 = u"""Some text..."""
e6 = Extractor(text=text6)
e6.find_entities()
print(e6.places)

输入文本:-

反对党领袖马欣达·拉贾帕克萨表示,由于宪法委员会的武断行为,整个公共行政部门已经崩溃。反对党领袖在一次会议后回答记者提出的问题时这么说...

输出

['Opposition', 'Leader Mahinda Rajapaksa', 'Opposition Leader']

此文本中没有任何城市名称,因此输出为空

4

1 回答 1

1

作为 geograpy3 的提交者以重现您的问题,我向最新的 geograpy3 https://github.com/somnathrakshit/geograpy3/blob/master/tests/test_extractor.py添加了一个测试:并添加了问题:

https://github.com/somnathrakshit/geograpy3/issues/3 已修复: 此提交

所以现在的结果是:

[]

如要求

 def testStackoverflow54712198(self):
        '''
        see https://stackoverflow.com/questions/54712198/not-only-extracting-places-from-a-text-but-also-other-names-in-geograpypython
        '''
        text='''Opposition Leader Mahinda Rajapaksa says that the whole public administration has collapsed due to the constitution council’s arbitrary actions. The Opposition Leader said so in response to a query a journalised raised after a meeting held...'''
        e=Extractor(text)
        places=e.find_geoEntities()
        if self.debug:
            print(places)
        self.assertEqual([],places)
于 2020-09-09T11:38:41.577 回答