问题
I want to extract information from sentences.
Currently, I am able to do the following using spacy.
Amy's monthly payment is $2000. --> (Amy's monthly payment, $2000)
However, I am trying to do the following.
The monthly payments for Amy, Bob, and Eva are $2000, $3000 and $3500 respectively.
--> ((Amy's monthly payment, $2000), (Bob's monthly payment, $3000), (Eva's monthly payment, $3500))
Is there any way that I can perform the task using the NLP method through python library such as Spacy? The pattern of the sentence is not fixed. Using regular expressions is not working.
Thanks
回答1:
If you look at the spacy dependency parse you can see that conjunctions are shown in it: So you will need to add some logic that takes into account this conjunction relationship when you iterate through the dependency parse tree. You could link the conjunctions like this:
conjunctions = set()
for span in doc:
if span.dep == conj:
conjunctions.add(span.head)
conjunctions.add(span)
You can play around with the spacy dependency parse visualisations here: https://explosion.ai/demos/displacy?text=The%20monthly%20payments%20for%20Amy%2C%20Bob%2C%20and%20Eva%20are%20%242000%2C%20%243000%20and%20%243500%20respectively.&model=en_core_web_lg&cpu=1&cph=1
来源:https://stackoverflow.com/questions/61258030/extract-name-entities-and-its-corresponding-numerical-values-from-sentence