fhamborg / Giveme5W1H

Extraction of the journalistic five W and one H questions (5W1H) from news articles: who did what, when, where, why, and how?
Apache License 2.0
512 stars 89 forks source link

AttributeError: 'ParentedTree' object has no attribute 'unicode_repr' #63

Closed nurub-tech closed 3 years ago

nurub-tech commented 3 years ago

Describe the bug Installed the library using the readme file. Running the example parse_single_from_code.py and got the error

To Reproduce Tried to copy the cache folder from the library to my local machine under Giveme5W1H like what's explained in #30 didn't solve the issue

Log Full log of running the example: No extractors passed: initializing default configuration. No combinedScorers passed: initializing default configuration. extractor = <Giveme5W1H.extractor.extractor.MasterExtractor object at 0x000002AFDF407788> doc = <Giveme5W1H.extractor.document.Document object at 0x000002AFF2344F08> Exception in thread Thread-4: Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractor.py", line 20, in run extractor.process(document) File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractors\abs_extractor.py", line 40, in process self._extract_candidates(document) File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractors\cause_extractor.py", line 92, in _extract_candidates for candidate in self._evaluate_tree(tree): File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractors\cause_extractor.py", line 131, in _evaluate_tree if sibling.label() == 'VP' and "('NP'" in sibling.unicode_repr(): AttributeError: 'ParentedTree' object has no attribute 'unicode_repr'

C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\examples\caches\Nominatim.prickle CACHED: Canada: Canada Exception in thread Thread-1: Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractor.py", line 20, in run extractor.process(document) File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractors\abs_extractor.py", line 40, in process self._extract_candidates(document) File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\extractors\environment_extractor.py", line 147, in _extract_candidates self._cache_nominatim.cache(location_string, location) File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\tools\key_value_cache.py", line 58, in cache self.persist() File "C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\extractor\tools\key_value_cache.py", line 43, in persist with open(self._cache_path, 'wb') as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\nurub\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\Giveme5W1H\examples\caches\Nominatim.prickle'

Versions (please complete the following information):

jinzhao3611 commented 3 years ago

I solved this issue by going to the cause_extractor.py and change line 131 from _if sibling.label() == 'VP' and "('NP'" in sibling.unicode_repr():_ to if sibling.label() == 'VP' and "('NP'" in sibling.__repr__():

pmckim1 commented 3 years ago

I solved this issue by going to the cause_extractor.py and change line 131 from _if sibling.label() == 'VP' and "('NP'" in sibling.unicode_repr():_ to if sibling.label() == 'VP' and "('NP'" in sibling.__repr__():

I had the same problem and this fix worked for me. Thanks for posting!

fhamborg commented 3 years ago

fixed with latest pypi version