Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BllipParser: AttributeError: 'str' object has no attribute 'decode' on Python 3.5 #1920

Closed
acattle opened this issue Dec 19, 2017 · 3 comments · Fixed by #2897
Closed

BllipParser: AttributeError: 'str' object has no attribute 'decode' on Python 3.5 #1920

acattle opened this issue Dec 19, 2017 · 3 comments · Fixed by #2897
Labels

Comments

@acattle
Copy link

acattle commented Dec 19, 2017

When calling next(BllipParser.parse()) on Python 3.5, I receive the following error:

File "/home/andrew/.local/lib/python3.5/site-packages/nltk/parse/bllip.py", line 169, in parse
_ensure_ascii(sentence)
File "/home/andrew/.local/lib/python3.5/site-packages/nltk/parse/bllip.py", line 101, in _ensure_ascii
word.decode('ascii')
AttributeError: 'str' object has no attribute 'decode'

Related to #507

NLTK v3.2.5
Python v3.5.2
OS: Ubuntu (16.04.3) running on WSL (16299.125)

@EgorNemchinov
Copy link

EgorNemchinov commented Dec 23, 2017

Hey!
There are indeed differences since in Python 3 strings are no longer bytes arrays.
This problem might be solved by changing decode() to encode(), since they both check whether it's an ascii string.

May I solve this?

@interrogator
Copy link

So nobody ever solved this? Currently I have to wrap words in a dummy class with a decode method that does nothing. I'd love to remove that from my code.

@interrogator
Copy link

Here is the traceback, happens when I use Bllip's parse_one:

~/venv/3.7/lib/python3.7/site-packages/nltk-3.4.4-py3.7.egg/nltk/parse/api.py in parse_one(self, sent, *args, **kwargs)
     70     def parse_one(self, sent, *args, **kwargs):
     71         """:rtype: Tree or None"""
---> 72         return next(self.parse(sent, *args, **kwargs), None)

~/venv/3.7/lib/python3.7/site-packages/nltk-3.4.4-py3.7.egg/nltk/parse/bllip.py in parse(self, sentence)
    182         :rtype: iter(Tree)
    183         """
--> 184         _ensure_ascii(sentence)
    185         nbest_list = self.rrp.parse(sentence)
    186         for scored_parse in nbest_list:

~/venv/3.7/lib/python3.7/site-packages/nltk-3.4.4-py3.7.egg/nltk/parse/bllip.py in _ensure_ascii(words)
    103     try:
    104         for i, word in enumerate(words):
--> 105             word.decode('ascii')
    106     except UnicodeDecodeError:
    107         raise ValueError(

AttributeError: 'str' object has no attribute 'decode'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants