enhanced-subject-verb-object-extraction icon indicating copy to clipboard operation
enhanced-subject-verb-object-extraction copied to clipboard

Attribute Error

Open humehta opened this issue 6 years ago • 7 comments

My code: from subject_verb_object_extract import findSVOs, nlp tokens = nlp("The respiratory tract has a branching structure like that of a tree.") svos = findSVOs(tokens) print(svos)

Getting the following error: ~\Anaconda3\Scripts\subject_verb_object_extract.py in expand(item, tokens) 231 parts = [] 232 --> 233 for part in item.lefts: 234 if part.pos_ in BREAKER_POS: 235 break

AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'lefts'

humehta avatar Jun 06 '18 20:06 humehta

you must have the spaCy SRL (Semantic Role Labelling) pipeline enabled to get the lefts, head, rights and other parts. This code relies on SRL, as SVO basically is the application of SRL. The easiest would be to use spacy like:

nlp = en_core_web_sm.load()

See the spacy documentation for more information please.

rock3125 avatar Jun 06 '18 21:06 rock3125

Thanks!

humehta avatar Jun 07 '18 14:06 humehta

I tried loading spacy like: import spacy import en_core_web_sm from subject_verb_object_extract import findSVOs nlp = en_core_web_sm.load() tokens = nlp("The respiratory tract has a branching structure like that of a tree.") svos = findSVOs(tokens) print(svos)

But still getting the same error.

humehta avatar Jun 07 '18 14:06 humehta

apologies - I tried the code you used above, and there was indeed a bug. Not quite sure why spacy didn't have these attributes in some case - but I've modified the code to ignore these attributes when missing. Thanks Humehta!

rock3125 avatar Jun 08 '18 02:06 rock3125

No problem! Thanks for the rectification.

humehta avatar Jun 08 '18 14:06 humehta

Hey Peter: I am just curious to know the following your output for the following text is as follows:

Text:

Their function in the respiratory system is to extract oxygen from the atmosphere and transfer it into the bloodstream, and to release carbon dioxide from the bloodstream into the atmosphere, in a process of gas exchange.

Output: [('Their function in the respiratory system', 'extract', 'oxygen')]

Why doesn't it traverse the whole sentence and gives an output for just one part of the sentence?

humehta avatar Jun 08 '18 15:06 humehta

ay! that is a good question. That is probably where this software needs to be extended. SVO extraction is quite a job in itself. I basically extended a previous system a bit. However, more work is needed. Not sure if you ever could get a perfect system...

rock3125 avatar Jun 08 '18 22:06 rock3125