Skip to content

Commit

Permalink
Further intergration of enhanced and enhanced++ dependencies into Cor…
Browse files Browse the repository at this point in the history
…eNLP.
  • Loading branch information
sebschu authored and Stanford NLP committed May 26, 2016
1 parent 020689d commit 852a9de
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/edu/stanford/nlp/pipeline/CoreNLP.proto
Expand Up @@ -67,6 +67,9 @@ message Sentence {
repeated RelationTriple openieTriple = 14; // The OpenIE triples in the sentence
repeated RelationTriple kbpTriple = 16; // The KBP triples in this sentence
repeated SentenceFragment entailedSentence = 15; // The entailed sentences, by natural logic
optional DependencyGraph enhancedDependencies = 17;
optional DependencyGraph enhancedPlusPlusDependencies = 18;

optional uint32 paragraph = 11;

optional string text = 12; // Only needed if we're only saving the sentence.
Expand Down
14 changes: 14 additions & 0 deletions src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java
Expand Up @@ -403,6 +403,8 @@ protected CoreNLPProtos.Sentence.Builder toProtoBuilder(CoreMap sentence, Set<Cl
if (keySet.contains(CollapsedDependenciesAnnotation.class)) { builder.setCollapsedDependencies(toProto(getAndRegister(sentence, keysToSerialize, CollapsedDependenciesAnnotation.class))); }
if (keySet.contains(CollapsedCCProcessedDependenciesAnnotation.class)) { builder.setCollapsedCCProcessedDependencies(toProto(getAndRegister(sentence, keysToSerialize, CollapsedCCProcessedDependenciesAnnotation.class))); }
if (keySet.contains(AlternativeDependenciesAnnotation.class)) { builder.setAlternativeDependencies(toProto(getAndRegister(sentence, keysToSerialize, AlternativeDependenciesAnnotation.class))); }
if (keySet.contains(EnhancedDependenciesAnnotation.class)) { builder.setEnhancedDependencies(toProto(getAndRegister(sentence, keysToSerialize, EnhancedDependenciesAnnotation.class))); }
if (keySet.contains(EnhancedPlusPlusDependenciesAnnotation.class)) { builder.setEnhancedPlusPlusDependencies(toProto(getAndRegister(sentence, keysToSerialize, EnhancedPlusPlusDependenciesAnnotation.class))); }
if (keySet.contains(TokensAnnotation.class) && getAndRegister(sentence, keysToSerialize, TokensAnnotation.class).size() > 0 &&
getAndRegister(sentence, keysToSerialize, TokensAnnotation.class).get(0).containsKey(ParagraphAnnotation.class)) {
builder.setParagraph(getAndRegister(sentence, keysToSerialize, TokensAnnotation.class).get(0).get(ParagraphAnnotation.class));
Expand Down Expand Up @@ -1065,6 +1067,12 @@ public CoreMap fromProto(CoreNLPProtos.Sentence proto) {
if (proto.hasAlternativeDependencies()) {
lossySentence.set(AlternativeDependenciesAnnotation.class, fromProto(proto.getAlternativeDependencies(), tokens, null));
}
if (proto.hasEnhancedDependencies()) {
lossySentence.set(EnhancedDependenciesAnnotation.class, fromProto(proto.getEnhancedDependencies(), tokens, null));
}
if (proto.hasEnhancedPlusPlusDependencies()) {
lossySentence.set(EnhancedPlusPlusDependenciesAnnotation.class, fromProto(proto.getEnhancedPlusPlusDependencies(), tokens, null));
}
// Add entailed sentences
if (proto.getEntailedSentenceCount() > 0) {
List<SentenceFragment> entailedSentences = proto.getEntailedSentenceList().stream().map(frag -> fromProto(frag, lossySentence.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toList());
Expand Down Expand Up @@ -1312,6 +1320,12 @@ public Annotation fromProto(CoreNLPProtos.Document proto) {
if (sentence.hasAlternativeDependencies()) {
map.set(AlternativeDependenciesAnnotation.class, fromProto(sentence.getAlternativeDependencies(), sentenceTokens, docid));
}
if (sentence.hasEnhancedDependencies()) {
map.set(EnhancedDependenciesAnnotation.class, fromProto(sentence.getEnhancedDependencies(), sentenceTokens, docid));
}
if (sentence.hasEnhancedPlusPlusDependencies()) {
map.set(EnhancedPlusPlusDependenciesAnnotation.class, fromProto(sentence.getEnhancedPlusPlusDependencies(), sentenceTokens, docid));
}
// Set entailed sentences
if (sentence.getEntailedSentenceCount() > 0) {
Set<SentenceFragment> entailedSentences = sentence.getEntailedSentenceList().stream().map(frag -> fromProto(frag, map.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toSet());
Expand Down
4 changes: 2 additions & 2 deletions src/edu/stanford/nlp/trees/GrammaticalStructure.java
Expand Up @@ -921,13 +921,13 @@ public List<TypedDependency> typedDependenciesCCprocessed(boolean includeExtras)


public List<TypedDependency> typedDependenciesEnhanced() {
List<TypedDependency> tdl = typedDependencies(Extras.NONE);
List<TypedDependency> tdl = typedDependencies(Extras.MAXIMAL);
addEnhancements(tdl, UniversalEnglishGrammaticalStructure.ENHANCED_OPTIONS);
return tdl;
}

public List<TypedDependency> typedDependenciesEnhancedPlusPlus() {
List<TypedDependency> tdl = typedDependencies(Extras.NONE);
List<TypedDependency> tdl = typedDependencies(Extras.MAXIMAL);
addEnhancements(tdl, UniversalEnglishGrammaticalStructure.ENHANCED_PLUS_PLUS_OPTIONS);
return tdl;
}
Expand Down
Expand Up @@ -953,7 +953,19 @@ public void addEnhancements(List<TypedDependency> list, EnhancementOptions optio
*/
@Override
protected void collapseDependencies(List<TypedDependency> list, boolean CCprocess, Extras includeExtras) {
addEnhancements(list, COLLAPSED_OPTIONS);
EnhancementOptions options = new EnhancementOptions(COLLAPSED_OPTIONS);
if (includeExtras.doRef) {
options.addReferent = true;
}

if (includeExtras.doSubj) {
options.addXSubj = true;
}

if (CCprocess) {
options.propagateDependents = true;
}
addEnhancements(list, options);
}

@Override
Expand Down
19 changes: 16 additions & 3 deletions src/edu/stanford/nlp/trees/ud/EnhancementOptions.java
Expand Up @@ -25,20 +25,33 @@ public class EnhancementOptions {
* @param enhanceConjuncts Add coordinating conjunctions to relation labels.
* @param propagateDependents Propagate dependents.
* @param addReferent Add "referent" relation in relative clauses.
* @param addCopyNode Add copy nodes for conjoined Ps and PPs.
* @param addCopyNodes Add copy nodes for conjoined Ps and PPs.
* @param demoteQuantMod Turn quantificational modifiers into flat multi-word expressions.
* @param addXSubj Add relation between controlling subject and controlled verb.
*/
public EnhancementOptions(boolean processMultiWordPrepositions, boolean enhancePrepositionalModifiers,
boolean enhanceConjuncts, boolean propagateDependents, boolean addReferent,
boolean addCopyNode, boolean demoteQuantMod, boolean addXSubj) {
boolean addCopyNodes, boolean demoteQuantMod, boolean addXSubj) {
this.processMultiWordPrepositions = processMultiWordPrepositions;
this.enhancePrepositionalModifiers = enhancePrepositionalModifiers;
this.enhanceConjuncts = enhanceConjuncts;
this.propagateDependents = propagateDependents;
this.addReferent = addReferent;
this.addCopyNodes = addCopyNode;
this.addCopyNodes = addCopyNodes;
this.demoteQuantMod = demoteQuantMod;
this.addXSubj = addXSubj;
}

public EnhancementOptions(EnhancementOptions options) {
this.processMultiWordPrepositions = options.processMultiWordPrepositions;
this.enhancePrepositionalModifiers = options.enhancePrepositionalModifiers;
this.enhanceConjuncts = options.enhanceConjuncts;
this.propagateDependents = options.propagateDependents;
this.addReferent = options.addReferent;
this.addCopyNodes = options.addCopyNodes;
this.demoteQuantMod = options.demoteQuantMod;
this.addXSubj = options.addXSubj;
}


}

0 comments on commit 852a9de

Please sign in to comment.