0

I have already successfully parsed sentences to get dependency information using stanford parser (version 3.9.1(run it in IDE Eclipse)) with command "TypedDependencies", but how could I get depnedency information about a single word( it's parent, siblings and children)? I have searched javadoc, it seems Class semanticGraph is used to do this job, but it need a IndexedWord type as input, how do I get IndexedWord? Do you have any simple samples?

user8420001
  • 25
  • 1
  • 4

1 Answers1

0

You can create a SemanticGraph from a List of TypedDependencies and then you can use the methods getChildren(IndexedWord iw), getParent(IndexedWord iw), and getSiblings(IndexedWord iw). (See the javadoc of SemanticGraph).

To get the IndexedWord of a specific word, you can, for example, use the SemanticGraph method getNodeByIndex(int i), which will return the IndexNode of the i-th token in a sentence.

Sebastian Schuster
  • 1,563
  • 10
  • 7
  • Thanks a lot! It really helpd! But how to get all the word's IndexedWord in a sentence? Cause I need every token's dependency information. I have tried methods - getAllNodesByWordPattern(), there is my code "Collection tdl = gs.typedDependencies(); List id = sg.getAllNodesByWordsPattern(tdl.toString()); for(IndexedWord i : id){System.out.println(sg.getChildren(i));}", It give a wrong output"Illegal character range near index 10". I'm very poor in java, Thanks for your help again! – user8420001 Jun 07 '18 at 05:51
  • I am an idiot :D, tdl.size() and for loop can solve the upper question. – user8420001 Jun 07 '18 at 06:21
  • But still look foward if you have a better way to solve the problem :) – user8420001 Jun 07 '18 at 09:38