I need to extract descriptions of locations from a text. For now, I am trying to get location with it's adjectival modifier.
For example from
In compact Durham you don't need transport to get around.
I want to get
compact Durham
I have CoreEntityMention
and SemanticGraph
of my sentence. I can get index of NE's token to find IndexedWord
in SemanticGraph
, but NE may contain more than one token so I don't know hot to build the link. I saw this similar question, but didn't understand suggested solution. Do need I to check dependence for each token?
Here is my approach written in Kotlin (no big difference from Java):
val dependencies = mutableListOf<String>()
val depGraph = entityMention.sentence().dependencyParse()
for (token in entityMention.tokens()) {
val node = depGraph.getNodeByIndex(token.index())
for (dependence in depGraph.childPairs(node)) {
if (dependence.first.shortName == "amod") {
dependencies.add(dependence.second.toString())
}
}
}
Is it correct and simplest way?
Yes, at the moment I think the best thing you can do is iterate through the tokens of the entity mention since dependencies exist between tokens.
I'll note this question, and maybe we can add some code to make this easier in the future.