Python Forum
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue on tree
#1
Hi, 

I need to know what is wrong with this code and why I am getting errors and how can solve it......

def leaves(tag_words):
    from nltk.tree import Tree


    import re 
    pattern = r'\w+:?(?=\/)'    # for removing NNS AND NN
    npb= []
    for i in tag_words[0:]:
        
        
       tr= [(" " .join((re.findall(pattern, str(word.leaves())))) ) for word in Tree.fromstring(str(i)).subtrees(filter = lambda t: t.label()=='NP')]
      
       
       npb.extend(tr)
     
    nor = [stem(normalizatio((i.lower()))) for i in npb]# lemmatization 
  
    candi=[t for t in nor if acceptable_word(t)]  # stopword remove  
    
    return candi
please help me........
Output:
  File "C:\ProgramData\Anaconda2\lib\site-packages\nltk\tree.py", line 636, in fromstring     cls._parse_error(s, 'end-of-string', close_b)   File "C:\ProgramData\Anaconda2\lib\site-packages\nltk\tree.py", line 675, in _parse_error     raise ValueError(msg) ValueError: Tree.read(): expected u')' but got u'end-of-string'             at index 159.                 "...,/,   ./.)"                               ^
thanks you
Reply
#2
I don't see any code!
Reply
#3
When something doesn't work, and you don't know why, and you don't know where the issue is, the first thing you should do is simplify the problem. In your case, that means getting rid of the list comprehensions, and all those excessive parentheses that make it very difficult to read. This isn't lisp, after all.
Reply
#4
line 11 is way too complicated list comp to determine any problem in a reasonable amount of thought.
Recommended Tutorials:
Reply
#5
For future readers, OP created a suspiciously similar thread here: https://python-forum.io/Thread-Need-your-help
Further discussion should probably take place there (I'm not merging, since they're different enough that it'd just make things confusing).
Reply
#6
Brian Kernighan is always right:
  • Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? "The Elements of Programming Style", 2nd edition, chapter 2.

  • The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. "Unix for Beginners" (1979). (and how do you put a print statement in a one-liner)
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020