sergey-tihon / Stanford.NLP.NET

Stanford NLP for .NET
http://sergey-tihon.github.io/Stanford.NLP.NET/
MIT License
597 stars 123 forks source link

Is is possible to loop through the dependencies of the Semantic Graph Annotation? #98

Closed Eric-Ryan closed 5 years ago

Eric-Ryan commented 5 years ago

I get a NullException error for using "java.util.ArrayList". I have also tried "java.util.AbstractSet" and "java.util.AbstractCollection" but got the same error. This is my attempt:

var dependencyGraphAnnotation = new SemanticGraphCoreAnnotations.BasicDependenciesAnnotation().getClass();
var dependencies = sentence.get(dependencyGraphAnnotation);

foreach (var dependency in dependencies java.util.ArrayList) // I get NullExceptionError here
{
    Console.WriteLine(dependency);

    // Console.WriteLine(dependency.value());
    // Console.WriteLine(dependency.label());

    if (dependency.ToString().Equals("nsubj"))
    {
        Console.WriteLine(" hello world ");
    }

}
Eric-Ryan commented 5 years ago

I fixed it by doing this:

var dependencies = sentence.get(dependencyGraphAnnotation) as edu.stanford.nlp.semgraph.SemanticGraph;