edu.stanford.nlp.ie.machinereading.structure
Class AnnotationUtils

java.lang.Object
  extended by edu.stanford.nlp.ie.machinereading.structure.AnnotationUtils

public class AnnotationUtils
extends java.lang.Object

Utilities to manipulate Annotations storing datasets or sentences with Machine Reading info

Author:
Mihai

Method Summary
static void addEntityMention(CoreMap sentence, EntityMention arg)
           
static void addEntityMentions(CoreMap sentence, java.util.Collection<EntityMention> args)
           
static void addEventMention(CoreMap sentence, EventMention arg)
           
static void addEventMentions(CoreMap sentence, java.util.Collection<EventMention> args)
           
static void addRelationMention(CoreMap sentence, RelationMention arg)
           
static void addRelationMentions(CoreMap sentence, java.util.Collection<RelationMention> args)
           
static void addSentence(CoreMap dataset, CoreMap sentence)
           
static void addSentences(CoreMap dataset, java.util.List<CoreMap> sentences)
           
static Annotation createDataset(java.util.List<CoreMap> sentences)
          Given a list of sentences (as CoreMaps), wrap it in a new Annotation.
static java.lang.String datasetToString(CoreMap dataset)
           
static Annotation deepMentionCopy(CoreMap dataset)
          Creates a deep copy of the given dataset with new lists for all mentions (entity, relation, event)
static java.util.List<java.util.List<CoreLabel>> entityMentionsToCoreLabels(CoreMap dataset, java.util.Set<java.lang.String> annotationsToSkip, boolean useSubTypes, boolean useBIO)
          Converts the labels of all entity mentions in this dataset to sequences of CoreLabels
static java.lang.String excelify(java.lang.String s)
          Process string to be a cell in Excel file.
static java.util.List<RelationMention> getAllRelations(RelationMentionFactory factory, CoreMap sentence, boolean createUnrelatedRelations)
          Get list of all relations and non-relations between EntityMentions in this sentence Use with care.
static java.util.List<RelationMention> getAllUnrelatedRelations(RelationMentionFactory factory, CoreMap sentence, boolean checkExisting)
           
 java.util.List<EntityMention> getEntityMentions(CoreMap sent)
           
 java.util.List<EventMention> getEventMentions(CoreMap sent)
           
static RelationMention getRelation(RelationMentionFactory factory, CoreMap sentence, ExtractionObject... args)
          Return the relation that holds between the given entities.
 java.util.List<RelationMention> getRelationMentions(CoreMap sent)
           
static java.util.List<RelationMention> getRelations(RelationMentionFactory factory, CoreMap sentence, ExtractionObject... args)
          Return all the relations that holds between the given entities.
static CoreMap getSentence(CoreMap dataset, int i)
           
static java.lang.String getTextContent(CoreMap sent, Span span)
          Fetches the sentence text in a given token span
static java.lang.String prettify(java.lang.String s)
          Prepare a string for printing in a spreadsheet for Mechanical Turk input.
static java.util.List<CoreMap> readSentencesFromFile(java.lang.String path)
           
static int sentenceCount(CoreMap dataset)
           
static Annotation sentenceDeepMentionCopy(Annotation sentence)
          Deep copy of the sentence: we create new entity/relation/event lists here.
static java.util.List<CoreLabel> sentenceEntityMentionsToCoreLabels(CoreMap sentence, boolean addAnswerAnnotation, java.util.Set<java.lang.String> annotationsToSkip, java.util.Set<java.lang.String> mentionTypesToUse, boolean useSubTypes, boolean useBIO)
          Converts the labels of all entity mentions in this sentence to sequences of CoreLabels
static java.lang.String sentenceToString(CoreMap sent)
           
static void shuffleSentences(CoreMap dataset)
          Randomized shuffle of all sentences int this dataset
static java.lang.String tokensAndNELabelsToString(CoreMap sentence)
           
static java.lang.String tokensToString(java.util.List<CoreLabel> tokens)
           
static void updateOffsets(java.util.List<Word> tokens, int offset)
           
static void updateOffsetsInCoreLabels(java.util.List<CoreLabel> tokens, int offset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDataset

public static Annotation createDataset(java.util.List<CoreMap> sentences)
Given a list of sentences (as CoreMaps), wrap it in a new Annotation.


shuffleSentences

public static void shuffleSentences(CoreMap dataset)
Randomized shuffle of all sentences int this dataset

Parameters:
dataset -

entityMentionsToCoreLabels

public static java.util.List<java.util.List<CoreLabel>> entityMentionsToCoreLabels(CoreMap dataset,
                                                                                   java.util.Set<java.lang.String> annotationsToSkip,
                                                                                   boolean useSubTypes,
                                                                                   boolean useBIO)
Converts the labels of all entity mentions in this dataset to sequences of CoreLabels

Parameters:
dataset -
annotationsToSkip -
useSubTypes -

sentenceEntityMentionsToCoreLabels

public static java.util.List<CoreLabel> sentenceEntityMentionsToCoreLabels(CoreMap sentence,
                                                                           boolean addAnswerAnnotation,
                                                                           java.util.Set<java.lang.String> annotationsToSkip,
                                                                           java.util.Set<java.lang.String> mentionTypesToUse,
                                                                           boolean useSubTypes,
                                                                           boolean useBIO)
Converts the labels of all entity mentions in this sentence to sequences of CoreLabels

Parameters:
sentence -
addAnswerAnnotation -
annotationsToSkip -
useSubTypes -

getSentence

public static CoreMap getSentence(CoreMap dataset,
                                  int i)

sentenceCount

public static int sentenceCount(CoreMap dataset)

addSentence

public static void addSentence(CoreMap dataset,
                               CoreMap sentence)

addSentences

public static void addSentences(CoreMap dataset,
                                java.util.List<CoreMap> sentences)

deepMentionCopy

public static Annotation deepMentionCopy(CoreMap dataset)
Creates a deep copy of the given dataset with new lists for all mentions (entity, relation, event)

Parameters:
dataset -

sentenceDeepMentionCopy

public static Annotation sentenceDeepMentionCopy(Annotation sentence)
Deep copy of the sentence: we create new entity/relation/event lists here. However, we do not deep copy the ExtractionObjects themselves!

Parameters:
sentence -

getRelation

public static RelationMention getRelation(RelationMentionFactory factory,
                                          CoreMap sentence,
                                          ExtractionObject... args)
Return the relation that holds between the given entities. Return a relation of type UNRELATED if this sentence contains no relation between the entities.


getRelations

public static java.util.List<RelationMention> getRelations(RelationMentionFactory factory,
                                                           CoreMap sentence,
                                                           ExtractionObject... args)
Return all the relations that holds between the given entities. Returns a list containing a relation of type UNRELATED if this sentence contains no relation between the entities.


getAllRelations

public static java.util.List<RelationMention> getAllRelations(RelationMentionFactory factory,
                                                              CoreMap sentence,
                                                              boolean createUnrelatedRelations)
Get list of all relations and non-relations between EntityMentions in this sentence Use with care. This is an expensive call due to getAllUnrelatedRelations, which creates all non-existing relations between all entity mentions


getAllUnrelatedRelations

public static java.util.List<RelationMention> getAllUnrelatedRelations(RelationMentionFactory factory,
                                                                       CoreMap sentence,
                                                                       boolean checkExisting)

addEntityMention

public static void addEntityMention(CoreMap sentence,
                                    EntityMention arg)

addEntityMentions

public static void addEntityMentions(CoreMap sentence,
                                     java.util.Collection<EntityMention> args)

getEntityMentions

public java.util.List<EntityMention> getEntityMentions(CoreMap sent)

addRelationMention

public static void addRelationMention(CoreMap sentence,
                                      RelationMention arg)

addRelationMentions

public static void addRelationMentions(CoreMap sentence,
                                       java.util.Collection<RelationMention> args)

getRelationMentions

public java.util.List<RelationMention> getRelationMentions(CoreMap sent)

addEventMention

public static void addEventMention(CoreMap sentence,
                                   EventMention arg)

addEventMentions

public static void addEventMentions(CoreMap sentence,
                                    java.util.Collection<EventMention> args)

getEventMentions

public java.util.List<EventMention> getEventMentions(CoreMap sent)

prettify

public static java.lang.String prettify(java.lang.String s)
Prepare a string for printing in a spreadsheet for Mechanical Turk input.

Parameters:
s - String to be formatted
Returns:
String string enclosed in quotes with other quotes escaped, and with better formatting for readability by Turkers.

getTextContent

public static java.lang.String getTextContent(CoreMap sent,
                                              Span span)
Fetches the sentence text in a given token span

Parameters:
span -

sentenceToString

public static java.lang.String sentenceToString(CoreMap sent)

tokensAndNELabelsToString

public static java.lang.String tokensAndNELabelsToString(CoreMap sentence)

datasetToString

public static java.lang.String datasetToString(CoreMap dataset)

tokensToString

public static java.lang.String tokensToString(java.util.List<CoreLabel> tokens)

updateOffsets

public static void updateOffsets(java.util.List<Word> tokens,
                                 int offset)

updateOffsetsInCoreLabels

public static void updateOffsetsInCoreLabels(java.util.List<CoreLabel> tokens,
                                             int offset)

excelify

public static java.lang.String excelify(java.lang.String s)
Process string to be a cell in Excel file. Escape any quotes in the string and enclose the whole string with quotes.


readSentencesFromFile

public static java.util.List<CoreMap> readSentencesFromFile(java.lang.String path)
                                                     throws java.io.IOException,
                                                            java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Stanford NLP Group