def testIssue49(self): ''' country recognition ''' show = self.debug texts = [ 'United Kingdom', 'UK', 'Great Britain', 'GB', 'United States' ] expected = [ "United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", "United States of America" ] if show: print("lookup with geograpy.get_geoPlace_context") for text in texts: countries = geograpy.get_geoPlace_context(text=text).countries if show: print(f"{text}:{countries}") if show: print("lookup with PlaceContext") for i, text in enumerate(texts): pc = PlaceContext([text]) pc.set_countries() if show: print(f"{text}:{pc.countries}") self.assertEqual([expected[i]], pc.countries)
def testGeograpyIssue32(self): ''' test https://github.com/ushahidi/geograpy/issues/32 ''' url = "https://www.politico.eu/article/italy-incurable-economy/" places = geograpy.get_geoPlace_context(url=url) print(places) self.assertEquals(['Rome', 'Brussels', 'Italy'], places.cities)
def testIssue22(self): ''' https://github.com/somnathrakshit/geograpy3/issues/22 ''' url = 'https://en.wikipedia.org/wiki/2012_Summer_Olympics_torch_relay' places = geograpy.get_geoPlace_context(url=url) if self.debug: print(places) self.assertTrue(len(places.countries) > 5) self.assertTrue(len(places.regions) > 5) self.assertTrue(len(places.cities) > 20)
def testIssue9(self): ''' test https://github.com/somnathrakshit/geograpy3/issues/9 [BUG]AttributeError: 'NoneType' object has no attribute 'name' on "Pristina, Kosovo" ''' locality = "Pristina, Kosovo" gp = geograpy.get_geoPlace_context(text=locality) if self.debug: print(" %s" % gp.countries) print(" %s" % gp.regions) print(" %s" % gp.cities)
def testGetGeoPlace(self): ''' test geo place handling ''' url = 'http://www.bbc.com/news/world-europe-26919928' places = geograpy.get_geoPlace_context(url=url) if self.debug: print(places) self.assertEqual( ['Moscow', 'Donetsk', 'Brussels', 'Kharkiv', 'Russia'], places.cities)
def testGetGeoPlace(self): ''' test geo place handling ''' # 'http://www.bbc.com/news/world-europe-26919928' # broken since 2020-10 - returns javascript instead of plain html url = 'https://en.wikipedia.org/wiki/Golden_spike' places = geograpy.get_geoPlace_context(url=url) if self.debug: print(places) self.assertTrue("Ogden" in places.cities) self.assertTrue('Utah' in places.regions) self.assertTrue('United States' in places.countries)
def testStackoverflow62152428(self): ''' see https://stackoverflow.com/questions/62152428/extracting-country-information-from-description-using-geograpy?noredirect=1#comment112899776_62152428 ''' examples = { 2: 'Socialist Republic of Alachua', 3: 'Hérault, France', 4: 'Gwalior, India', 5: 'Zaragoza,España', 6: 'Zaragoza, Spain', 7: 'amsterdam ', 8: 'Evesham', 9: 'Rochdale' } for index, text in examples.items(): places = geograpy.get_geoPlace_context(text=text) print("example %d: %s" % (index, places.countries))
def testGeograpyIssue32(self): ''' test https://github.com/ushahidi/geograpy/issues/32 ''' # do not test since url is unreliable return url = "https://www.politico.eu/article/italy-incurable-economy/" places = geograpy.get_geoPlace_context(url=url) if self.debug: print(places) self.assertSetEqual( { 'Italy', 'Germany', 'France', 'United States of America', 'Belgium', 'Canada' }, set(places.countries)) self.assertSetEqual( {'Rome', 'Brussels', 'Italy', 'Germany'}, set(places.cities) ) # Notes: Italy is also city in US-NY, Germany is also city in US-TX
import geograpy url='https://en.wikipedia.org/wiki/2012_Summer_Olympics_torch_relay' places = geograpy.get_geoPlace_context(url = url) print(places)