Example #1
0
 def testIssue7(self):
     '''
     test https://github.com/somnathrakshit/geograpy3/issues/7
     disambiguating countries
     '''
     localities = [
         'Vienna, Illinois,',
         'Paris, Texas',
         'Zaragoza, Spain',
         'Vienna, Austria',
     ]
     expected = [
         {
             'iso': 'US'
         },
         {
             'iso': 'US'
         },
         {
             'iso': 'ES'
         },
         {
             'iso': 'AT'
         },
     ]
     for index, locality in enumerate(localities):
         city = geograpy.locateCity(locality, debug=False)
         if self.debug:
             print("  %s" % city)
         self.assertEqual(expected[index]['iso'], city.country.iso)
Example #2
0
 def testStackOverflow64418919(self):
     '''
     https://stackoverflow.com/questions/64418919/problem-retrieving-region-in-us-with-geograpy3
     '''
     examples = ['Seattle']
     for example in examples:
         city = geograpy.locateCity(example, debug=False)
         print(city)
Example #3
0
    def testGeoTextAndGrapy(self):
        '''
        test the GeoText and geograpy3 library
        '''
        debug = True
        limit = 100
        sqlQuery = """select count(*) as count,
locality from Event_wikicfp
where locality is not null
group by locality
order by 1 desc
LIMIT %d
""" % limit
        dbFile = Lookup.getDBFile()
        if os.path.isfile(dbFile):
            sqlDB = SQLDB(dbFile)
        else:
            lookup = Lookup.ensureAllIsAvailable("testGeoText")
            sqlDB = lookup.getSQLDB()
        if sqlDB is not None:
            print("testGeoText from database %s " % sqlDB.dbname)
            totalResult = sqlDB.query("""select count(*) as count
  from event_wikicfp
  where locality is not null""")
            total = totalResult[0]['count']
            listOfDicts = sqlDB.query(sqlQuery)
            index = 0
            rsum = 0
            found = 0
            problems = []
            for record in listOfDicts:
                locality = record['locality']
                count = record['count']
                index += 1
                rsum += count
                print("%5d: %5d/%5d %5.1f%%=%s" %
                      (index, count, rsum, rsum / total * 100, locality))
                geo = GeoText(locality)
                if debug:
                    print("  %s" % geo.countries)
                    print("  %s" % geo.cities)
                city = geograpy.locateCity(locality)
                if city is not None:
                    found += 1
                else:
                    problems.append(locality)
                if debug:
                    print("  %s%s" % (city, '✅' if city is not None else '❌'))
            if self.debug:
                print("found %d/%d = %5.1f%%" %
                      (found, limit, found / limit * 100))
                print("problems: %s" % problems)
            self.assertTrue(found / limit > 0.8)
        pass
Example #4
0
 def checkExamples(self, examples, countries):
     '''
     
     check that the given example give results in the given countries
     Args:
         examples(list): a list of example location strings
         countries(list): a list of expected country iso codes
     '''
     for index, example in enumerate(examples):
         city = geograpy.locateCity(example, debug=False)
         if self.debug:
             print("%3d: %22s->%s" % (index, example, city))
         self.assertEqual(countries[index], city.country.iso)
Example #5
0
 def testStackOverflow64379688(self):
     '''
     compare old and new geograpy interface
     '''
     examples = [
         'John Doe 160 Huntington Terrace Newark, New York 07112 United States of America',
         'John Doe 30 Huntington Terrace Newark, New York 07112 USA',
         'John Doe 22 Huntington Terrace Newark, New York 07112 US',
         'Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italia',
         'Mario Bianchi, Via Nazionale 256, 00148 Roma (RM) Italy',
         'Newark', 'Rome'
     ]
     for example in examples:
         city = geograpy.locateCity(example, debug=False)
         print(city)
Example #6
0
    def testProceedingsExample(self):
        '''
        test a proceedings title Example
        '''
        examples = [
            '''Proceedings of the 
IEEE 14th International Conference on 
Semantic Computing, ICSC 2020, 
San Diego, CA, USA, 
February 3-5, 2020'''
        ]
        for example in examples:
            places = geograpy.get_place_context(text=example)
            print(places)
            city = geograpy.locateCity(example, debug=False)
            print(city)
Example #7
0
 def testIssue10(self):
     '''
     test https://github.com/somnathrakshit/geograpy3/issues/10
     Add ISO country code
     '''
     localities = [
         'Singapore', 'Beijing, China', 'Paris, France', 'Barcelona, Spain',
         'Rome, Italy', 'San Francisco, US', 'Bangkok, Thailand',
         'Vienna, Austria', 'Athens, Greece', 'Shanghai, China'
     ]
     expectedCountry = [
         'SG', 'CN', 'FR', 'ES', 'IT', 'US', 'TH', 'AT', 'GR', 'CN'
     ]
     for index, locality in enumerate(localities):
         city = geograpy.locateCity(locality)
         if self.debug:
             print("  %s" % city)
         self.assertEqual(expectedCountry[index], city.country.iso)