Search code examples
nlpstanford-nlpopennlp

Detect relation between two persons in text


Goal is to find all the pairs of persons between which there is any kind of relation in a piece of text. Particularly, if we have this piece of text:

Alice Wilson, doctor with more than 30 years of experience in suppressing virus epidemics, has met with the president of Neverland country, John Doe, to discuss ways of tackling a new virus.

John Doe will meet next week with the state official Jack Sparrow of some other country to discuss something totally-unrelated-to-the-first-part-of-text.

There is a relation between Alice Wilson and John Doe, as well as John Doe and Jack Sparrow. However, there is no real relation between Alice Wilson and Jack Sparrow, apart from that they both appear in the same text.

Therefore, the resulting pairs would be:

Alice Wilson, John Doe
John Doe, Jack Sparrow

I have found a way to extract people's names from text using Stanford CoreNLP's Named Entity Recognizer, thus having Alice Wilson, John Doe and Jack Sparrow, but I am not sure how to find relations between them. CoreNLP can perform Part-of-Speech tagging, which can tag words with Subject, Verb, Object etc. Nonetheless, I still don't see a way of tackling all the possible variations where a person's name can be found, e.g.:

John Doe said that... <- 'John Doe' is a Subject
Jack Sparrow introduced John Doe to the senior officials... <- 'John Doe' is an Object
Jack Sparrow, John Doe's cousin, told the press... <- Not even sure what 'John Doe' here is.

Any ideas (code is welcome, but not necessary) on how to approach this?


Solution

  • You can see if there's a dependency path between the two entities in the sentence. For more info: http://nlp.stanford.edu/software/stanford-dependencies.shtml

    It won't be 100% accurate but good enough. To improve accuracy, you can prune the paths that are longer than certain lengths or have certain dependencies.

    You can also look at open information extraction tools like http://reverb.cs.washington.edu