Skip to content

Commit

Permalink
Fix some of the more glaring UD bugs in OpenIE
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Angeli authored and Stanford NLP committed Apr 27, 2015
1 parent 0e9cdab commit 0548207
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 281 deletions.
29 changes: 26 additions & 3 deletions src/edu/stanford/nlp/ie/util/RelationTriple.java
@@ -1,8 +1,10 @@
package edu.stanford.nlp.ie.util;

import edu.stanford.nlp.ie.machinereading.structure.Span;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.naturalli.Util;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
import edu.stanford.nlp.util.*;
Expand Down Expand Up @@ -76,7 +78,7 @@ public CoreLabel subjectHead() {
* This method will additionally strip out punctuation as well.
*/
public String subjectLemmaGloss() {
return StringUtils.join(subject.stream().filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]")).map(CoreLabel::lemma), " ");
return StringUtils.join(subject.stream().filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]")).map(x -> x.lemma() == null ? x.word() : x.lemma()), " ");
}

/** The object of this relation triple, as a String */
Expand All @@ -94,7 +96,7 @@ public CoreLabel objectHead() {
* This method will additionally strip out punctuation as well.
*/
public String objectLemmaGloss() {
return StringUtils.join(object.stream().filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]")).map(CoreLabel::lemma), " ");
return StringUtils.join(object.stream().filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]")).map(x -> x.lemma() == null ? x.word() : x.lemma()), " ");
}

/**
Expand All @@ -110,7 +112,7 @@ public String relationGloss() {
*/
public String relationLemmaGloss() {
return StringUtils.join(relation.stream()
.filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]") && !x.lemma().matches("[\\.,;'\"\\?!]")).map(CoreLabel::lemma), " ").toLowerCase();
.filter(x -> !x.tag().matches("[\\.\\?,:;'\"!]") && (x.lemma() == null || !x.lemma().matches("[\\.,;'\"\\?!]"))).map(x -> x.lemma() == null ? x.word() : x.lemma()), " ").toLowerCase();
}

/** A textual representation of the confidence. */
Expand Down Expand Up @@ -185,6 +187,27 @@ public String toString() {
return "" + this.confidence + "\t" + subjectGloss() + "\t" + relationGloss() + "\t" + objectGloss();
}

/** Print a description of this triple, formatted like the ReVerb outputs. */
public String toReverbString(String docid, CoreMap sentence) {
return docid + "\t" +
relation.get(0).sentIndex() + "\t" +
subjectGloss().replace('\t', ' ') + "\t" +
relationGloss().replace('\t', ' ') + "\t" +
objectGloss().replace('\t', ' ') + "\t" +
(subject.get(0).index() - 1) + "\t" +
subject.get(subject.size() - 1).index() + "\t" +
(relation.get(0).index() - 1) + "\t" +
relation.get(relation.size() - 1).index() + "\t" +
(object.get(0).index() - 1) + "\t" +
object.get(object.size() - 1).index() + "\t" +
confidenceGloss() + "\t" +
StringUtils.join(sentence.get(CoreAnnotations.TokensAnnotation.class).stream().map(x -> x.word().replace('\t', ' ').replace(" ", "")), " ") + "\t" +
StringUtils.join(sentence.get(CoreAnnotations.TokensAnnotation.class).stream().map(CoreLabel::tag), " ") + "\t" +
subjectLemmaGloss().replace('\t', ' ') + "\t" +
relationLemmaGloss().replace('\t', ' ') + "\t" +
objectLemmaGloss().replace('\t', ' ');
}

@Override
public int compareTo(RelationTriple o) {
if (this.confidence < o.confidence) {
Expand Down

0 comments on commit 0548207

Please sign in to comment.