using stanford coreNLP i have extracted all the type dependencies of a sentence which is in passive voice. Now I want to make it active voice. For this I have to delete and insert some new rule into this. For example if we take sentence like " The cat was chased by the dog." then the typed dependency representation is as: det(cat-2, The-1) nsubjpass(chased-4, cat-2) auxpass(chased-4, was-3) det(dog-7, the-6) agent(chased-4, dog-7) punct(chased-4, .-8)
A transformation rule to convert the above to active voice would require three deletions and two insertions: 1. Match and Delete: (a) nsubjpass(??X0, ??X1) (b) auxpass(??X0, ??X2) (c) agent(??X0, ??X3)
Here ??X0(chased) ,??X1(cat), ??X2(was) and ??X3(dog)
Now my question is that how can I implement these rule into my java code.
So you want to change the sentence:
"The cat was chased by the dog."
into:
"The dog chased the cat."
?
If I were working on this, my first instinct would be to use the rules to generate the new sentence String, and then just rebuild a new Annotation object with that text.
So I would not mess with editing the graph or the other annotations, I would just create the new String I wanted, and the rebuild the dependency graph.
So you could imagine having a rule like:
Pattern: X was VERB by Y --> Y <VERB> X
Example: "The cat was chased by the dog." --> "The dog chased the cat."
And follow this algorithm:
Detect pattern in dependency graph or with regex (in this case "was VERB by")
Create X and Y. So you could follow the graph to add extra words such as determinants. So in this case you would follow the determinant edge to expand "cat" into "The cat" and "dog" into "the dog".
Output the new altered String: X Y, and lowercase everything. In this case outputting "the cat chased the dog"
Then capitalize the first word of your new sentence and add punctuation at the end. Resulting in "The cat chased the dog."
Then I'd just feed this new String into an Annotation and re-run the pipeline to get a new dependency graph.
Annotation newSentenceAnnotation = new Annotation("The dog chased the cat.");
pipeline.annotate(newSentenceAnnotation);
Here are some links for working with the Semantic Graph:
http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/semgraph/SemanticGraph.html
http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/semgraph/SemanticGraphEdge.html
If you look at this recent demo we put up, there is a class called DependencyMatchFinder.java which demonstrates accessing a SemanticGraph from an Annotation:
https://github.com/stanfordnlp/nlp-meetup-demo/blob/master/DependencyMatchFinder.java