user7138786
user7138786

Reputation:

Python Geograpy unable to run demo

I am trying to run python's geograpy https://pypi.python.org/pypi/geograpy.

I installed geography using both

pip install geograpy

and

python setup.py install

I also made sure all the nltk's were installed properly. I installed any dependencies used by geograpy. I made the following changes to extraction.py

if (ne.node == 'GPE' or ne.node == 'PERSON') and ne[0][1] == 'NNP':

to

if (ne.label() == 'GPE' or ne.label() == 'PERSON') and ne[0][1] == 'NNP':

The demo code I am running is

import geograpy
url = 'http://www.gutenberg.ca/ebooks/doyleac-casebookofsherlockholmes/doyleac-casebookofsherlockholmes-00-h.html'

places = geograpy.get_place_context(url=url)

print places.country_mentions
print places.region_mentions
print places.city_mentions

However, I am getting this error

    if (ne.label() == 'GPE' or ne.label() == 'PERSON') and ne[0][1] == 'NNP':
AttributeError: 'Tree' object has no attribute 'label'

And if i change the extraction.py back to

if (ne.node == 'GPE' or ne.node == 'PERSON') and ne[0][1] == 'NNP':

I get this error:

  File "C:\Program Files (x86)\Python27\lib\site-packages\geograpy-0.3.7-py2.7.egg\geograpy\places.py", line 174, in set_cities
    self.country_cities[country.name] = []
AttributeError: 'NoneType' object has no attribute 'name'

I will also mention that I was using NLTK 3, but geograpy downgraded it to NLTK2.0.5.

Someone out there PLEASEEEEEEE help! THANKS

Upvotes: 1

Views: 580

Answers (1)

Naima
Naima

Reputation: 96

I faced the same problem. It just requires to change the correct variable name in palces.py file located in C:\Users\Naima\AppData\Roaming\Python\Python27\site-packages\geograpy\places.py Go to the line 174 in places.py file and replace the country.name with country_name as follows:

 self.country_cities[country_name] = []

Hope this works!

Upvotes: 4

Related Questions