My work consists in finding a query (can be noun+verb
) in a sentence, then extract the object.
exemple: "coding is sometimes a tough work."
My query would be: "coding is"
.
the typed dependencies i get are:
nsubj(work-6, coding-1)
cop(work-6, is-2)
advmod(work-6, sometimes-3)
det(work-6, a-4)
amod(work-6, tough-5)
My program should extract the nsubj dependency, identify "coding"
as the query and save "work"
.
May be this seems simple, but until now, i didn't find a method able to extract a specific typed dependency, and I really need this to finish my work.
Any help is welcome,
Introduction. A dependency parser analyzes the grammatical structure of a sentence, establishing relationships between "head" words and words which modify those heads. The figure below shows a dependency parse of a short sentence.
Dependency parsing is the process of analyzing the grammatical structure of a sentence based on the dependencies between the words in a sentence. In Dependency parsing, various tags represent the relationship between two words in a sentence. These tags are the dependency tags.
You can find dependencies by following code:
Tree tree = sentence.get(TreeAnnotation.class);
// Get dependency tree
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
Collection<TypedDependency> td = gs.typedDependenciesCollapsed();
System.out.println(td);
Object[] list = td.toArray();
System.out.println(list.length);
TypedDependency typedDependency;
for (Object object : list) {
typedDependency = (TypedDependency) object;
System.out.println("Depdency Name"typedDependency.dep().nodeString()+ " :: "+ "Node"+typedDependency.reln());
if (typedDependency.reln().getShortName().equals("something")) {
//your code
}
I don't think there's a way to tell the parser to extract the dependencies around a given word. However, you can just run through the list of dependencies for each sentence, searching for all instances in which the query word appears in an nsubj
relationship.
Also, how are you storing the parses of the sentences? If (as I gather from your question) it's in a text file, you can just use 2 successive greps, one for the query word, and one for the relationship you desire, to get a list of relevant other words.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With