Search code examples
pythongeotext

GeoText Package Not Identifying Cities at All in my Array


Using Python, I have an Array that Stores All the Words in my string, which I Loop through:

    #Loop through Title String Array and have GeoText identify the City
    for i in range(len(title_str_array)):
            places = GeoText(title_str_array[i])
            print(places.cities)

I am printing out my Title String Array to make sure the CITY is in there, and it is (please disregard the nonsense words - I am using Azure Computer Vision to identify Text on an image and it is not 100% correct; But the City Name: 'BOSTON' is clearly in my Array

 Title Array: ['A', 'COLOU', 'RE', '"', 'pu', 'BLICATION,', 'BOSTON', 't', 's,', 'MASS.,', 'U.'])

When I print out places.cities, I just get and Empty Value: []

I have PIP installed the GeoText Package, but the 'method' of identifying the cities is not returning 'BOSTON'

Am I missing something obvious?

Thank you!


Solution

  • GeoText (by default) won't recognise BOSTON. It will however recognise Boston

    You need to normalise the words in your list such that the first letter is uppercase and the remainder are lowercase.

    You could do that as follows:

    from geotext import GeoText
    
    ta = ['A', 'COLOU', 'RE', '"', 'pu', 'BLICATION,', 'BOSTON', 't', 's,', 'MASS.,', 'U.']
    
    print(GeoText(" ".join(map(str.title, ta))).cities)
    

    Output:

    ['Boston']