"NotImplementedError: use shortcut () to access node label

I need to extract all city names from the website. I used beautifulSoup with RE in previous projects, but on this site city names are part of the plain text and do not have a specific format. I found a geotherapy package ( https://pypi.python.org/pypi/geograpy/0.3.7 ) that fits my requirements.

Geocopying uses the nltk package. I installed all the models and packages for nltk, but it continues to throw this error:

>>> import geograpy >>> places = geograpy.get_place_context(url="http://www.state.gov/misc/list/") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\geograpy\__init__.py", line 6, in get_place_context e.find_entities() File "C:\Python27\lib\site-packages\geograpy\extraction.py", line 31, in find_entities if (ne.node == 'GPE' or ne.node == 'PERSON') and ne[0][1] == 'NNP': File "C:\Python27\lib\site-packages\nltk\tree.py", line 198, in _get_node raise NotImplementedError("Use label() to access a nod label.") NotImplementedError: Use label() to access a node label. 

Any help would be appreciated

+7
python nltk
source share
3 answers

You can solve this by replacing ".node" with ".label ()".

In your problem you can try replacing

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

from

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

Do not assume that everyone modifies the lib files. For a guy or anyone who needs help, you will need to access where the package is installed. You want to modify extract.py. If you use Windows 10 or something similar, the file may be located in the folder C: \ Python27 \ Lib \ site-packages \ geograpy \ extract.py. It is usually located in the same installation directory as python. As mentioned earlier, change (line 31)

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':

Done. Happy coding.

+4
source share

It seems that geograpy calls the node method of the nltk Tree object:

 nes = nltk.ne_chunk(nltk.pos_tag(text)) for ne in nes: if len(ne) == 1: if (ne.node == 'GPE' or ne.node == 'PERSON') and ne[0][1] == 'NNP': 

which package nltk marked obsolete:

 def _get_node(self): """Outdated method to access the node value; use the label() method instead.""" raise NotImplementedError("Use label() to access a node label.") def _set_node(self, value): """Outdated method to set the node value; use the set_label() method instead.""" raise NotImplementedError("Use set_label() method to set a node label.") node = property(_get_node, _set_node) 

The package is broken. You can fix it yourself or use another.

+2
source share

All Articles