rock3125 / enhanced-subject-verb-object-extraction

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

Attribute Error #2

Open humehta opened 6 years ago

humehta commented 6 years ago

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_objectextract.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'

rock3125 commented 6 years ago

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.

humehta commented 6 years ago

Thanks!

humehta commented 6 years ago

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.

rock3125 commented 6 years ago

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!

humehta commented 6 years ago

No problem! Thanks for the rectification.

humehta commented 6 years ago

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?

rock3125 commented 6 years ago

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...