extract name entities and its corresponding numerical values from sentence

▼魔方 西西 提交于 2021-02-11 13:59:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!