rock3125 / enhanced-subject-verb-object-extraction

Enhanced Subject Word Object Extraction
Apache License 2.0
148 stars 50 forks source link

Maximum recursion depth exceeded in comparison #5

Closed dav-ell closed 5 years ago

dav-ell commented 5 years ago

Hi, fantastic library you have here. Probably the best SVO extractor on GitHub.

I found two sentences that caused an error:

Then there’s a development setback on top of that that pushes you even further back.

and

And that goes with that we’re going to do things differently, but we haven’t done that yet.

Give the error:

RecursionError: maximum recursion depth exceeded in comparison

Traceback:

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input> in <module>
      1 from subject_verb_object_extract import findSVOs, nlp
      2 tokens = nlp("Then there’s a development setback on top of that that pushes you even further back.")
----> 3 svos = findSVOs(tokens)
      4 print(svos)

~/subject_verb_object_extract.py in findSVOs(tokens)
    295                                          "!" + v.lemma_ if verbNegated or objNegated else v.lemma_, to_str(expand(sub, tokens))))
    296                         else:
--> 297                             svos.append((to_str(expand(sub, tokens)),
    298                                          "!" + v.lower_ if verbNegated or objNegated else v.lower_, to_str(expand(obj, tokens))))
    299     return svos

~/subject_verb_object_extract.py in expand(item, tokens)
    250         for item2 in parts[-1].rights:
    251             if item2.pos_ == "DET" or item2.pos_ == "NOUN":
--> 252                 parts.extend(expand(item2, tokens))
    253             break
    254 

... last 1 frames repeated, from the frame below ...

~/subject_verb_object_extract.py in expand(item, tokens)
    250         for item2 in parts[-1].rights:
    251             if item2.pos_ == "DET" or item2.pos_ == "NOUN":
--> 252                 parts.extend(expand(item2, tokens))
    253             break
    254 

RecursionError: maximum recursion depth exceeded in comparison
rock3125 commented 5 years ago

Thanks for your comments and feedback dav-ell! I had a quick look and saw that its recursing infinitely (as you pointed out). I've add an infinite recursion check. I also added a demo.py file that shows your two use cases working along with my original example. Enjoy!

dav-ell commented 5 years ago

Awesome! Thanks!