Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,10 @@ private static void convertRel(SemanticGraph sg) {
}
}

@Override
protected void addEnhancements(List<TypedDependency> list, EnhancementOptions options) {

SemanticGraph sg = new SemanticGraph(list);

/**
* Manipulates the given SemanticGraph to add enhancements. Note that this modifies the input graph.
*/
public static void addEnhancements(SemanticGraph sg, EnhancementOptions options) {
if (DEBUG) {
printListSorted("addEnhancements: before correctDependencies()", sg.typedDependencies());
}
Expand Down Expand Up @@ -977,6 +976,15 @@ protected void addEnhancements(List<TypedDependency> list, EnhancementOptions op
}

correctSubjPass(sg);
}

@Override
protected void addEnhancements(List<TypedDependency> list, EnhancementOptions options) {

SemanticGraph sg = new SemanticGraph(list);

addEnhancements(sg, options);

list.clear();
list.addAll(sg.typedDependencies());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
import edu.stanford.nlp.trees.EnglishPatterns;
import edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.ProcessProtobufRequest;

Expand All @@ -29,14 +30,36 @@ public static void enhanceDependencies(Pattern relativePronounsPattern, Annotati
}
}

/**
* Enhance the dependencies on a single sentence, using the English-specific rules for enhancement
*/
public static void enhanceEnglishDependencies(Annotation annotation) {
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
SemanticGraph basic = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);

SemanticGraph enhanced = new SemanticGraph(basic);
UniversalEnglishGrammaticalStructure.addEnhancements(enhanced, UniversalEnglishGrammaticalStructure.ENHANCED_OPTIONS);
sentence.set(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class, enhanced);

SemanticGraph plusplus = new SemanticGraph(basic);
UniversalEnglishGrammaticalStructure.addEnhancements(plusplus, UniversalEnglishGrammaticalStructure.ENHANCED_PLUS_PLUS_OPTIONS);
sentence.set(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class, plusplus);
}
}

/**
* Process all sentences in the document, enhancing the basic dependencies on each sentence
*/
public static CoreNLPProtos.Document processRequest(Pattern relativePronounsPattern, CoreNLPProtos.DependencyEnhancerRequest request) {
ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer();
Annotation annotation = serializer.fromProto(request.getDocument());

enhanceDependencies(relativePronounsPattern, annotation);
if (request.hasLanguage() &&
(request.getLanguage() == CoreNLPProtos.Language.English || request.getLanguage() == CoreNLPProtos.Language.UniversalEnglish)) {
enhanceEnglishDependencies(annotation);
} else {
enhanceDependencies(relativePronounsPattern, annotation);
}

return serializer.toProto(annotation);
}
Expand Down