Class AnnotationUtils
- java.lang.Object
-
- edu.stanford.nlp.ie.machinereading.structure.AnnotationUtils
-
public class AnnotationUtils extends Object
Utilities to manipulate Annotations storing datasets or sentences with Machine Reading info- Author:
- Mihai
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddEntityMention(CoreMap sentence, EntityMention arg)static voidaddEntityMentions(CoreMap sentence, Collection<EntityMention> args)static voidaddEventMention(CoreMap sentence, EventMention arg)static voidaddEventMentions(CoreMap sentence, Collection<EventMention> args)static voidaddRelationMention(CoreMap sentence, RelationMention arg)static voidaddRelationMentions(CoreMap sentence, Collection<RelationMention> args)static voidaddSentence(CoreMap dataset, CoreMap sentence)static voidaddSentences(CoreMap dataset, List<CoreMap> sentences)static AnnotationcreateDataset(List<CoreMap> sentences)Given a list of sentences (as CoreMaps), wrap it in a new Annotation.static StringdatasetToString(CoreMap dataset)static AnnotationdeepMentionCopy(CoreMap dataset)Creates a deep copy of the given dataset with new lists for all mentions (entity, relation, event)static List<List<CoreLabel>>entityMentionsToCoreLabels(CoreMap dataset, Set<String> annotationsToSkip, boolean useSubTypes, boolean useBIO)Converts the labels of all entity mentions in this dataset to sequences of CoreLabels.static Stringexcelify(String s)Process string to be a cell in Excel file.static 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 List<RelationMention>getAllUnrelatedRelations(RelationMentionFactory factory, CoreMap sentence, boolean checkExisting)static List<EntityMention>getEntityMentions(CoreMap sent)static List<EventMention>getEventMentions(CoreMap sent)static RelationMentiongetRelation(RelationMentionFactory factory, CoreMap sentence, ExtractionObject... args)Return the relation that holds between the given entities.static List<RelationMention>getRelationMentions(CoreMap sent)static List<RelationMention>getRelations(RelationMentionFactory factory, CoreMap sentence, ExtractionObject... args)Return all the relations that holds between the given entities.static CoreMapgetSentence(CoreMap dataset, int i)static StringgetTextContent(CoreMap sent, Span span)Fetches the sentence text in a given token spanstatic Stringprettify(String s)Prepare a string for printing in a spreadsheet for Mechanical Turk input.static List<CoreMap>readSentencesFromFile(String path)static intsentenceCount(CoreMap dataset)static AnnotationsentenceDeepMentionCopy(Annotation sentence)Deep copy of the sentence: we create new entity/relation/event lists here.static List<CoreLabel>sentenceEntityMentionsToCoreLabels(CoreMap sentence, boolean addAnswerAnnotation, Set<String> annotationsToSkip, Set<String> mentionTypesToUse, boolean useSubTypes, boolean useBIO)Converts the labels of all entity mentions in this sentence to sequences of CoreLabels.static StringsentenceToString(CoreMap sent)static voidshuffleSentences(CoreMap dataset)Randomized shuffle of all sentences int this datasetstatic StringtokensAndNELabelsToString(CoreMap sentence)static StringtokensToString(List<CoreLabel> tokens)static voidupdateOffsets(List<Word> tokens, int offset)static voidupdateOffsetsInCoreLabels(List<CoreLabel> tokens, int offset)
-
-
-
Method Detail
-
createDataset
public static Annotation createDataset(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 List<List<CoreLabel>> entityMentionsToCoreLabels(CoreMap dataset, Set<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 List<CoreLabel> sentenceEntityMentionsToCoreLabels(CoreMap sentence, boolean addAnswerAnnotation, Set<String> annotationsToSkip, Set<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-
-
sentenceCount
public static int sentenceCount(CoreMap dataset)
-
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 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 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 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, Collection<EntityMention> args)
-
getEntityMentions
public static List<EntityMention> getEntityMentions(CoreMap sent)
-
addRelationMention
public static void addRelationMention(CoreMap sentence, RelationMention arg)
-
addRelationMentions
public static void addRelationMentions(CoreMap sentence, Collection<RelationMention> args)
-
getRelationMentions
public static List<RelationMention> getRelationMentions(CoreMap sent)
-
addEventMention
public static void addEventMention(CoreMap sentence, EventMention arg)
-
addEventMentions
public static void addEventMentions(CoreMap sentence, Collection<EventMention> args)
-
getEventMentions
public static List<EventMention> getEventMentions(CoreMap sent)
-
prettify
public static String prettify(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 String getTextContent(CoreMap sent, Span span)
Fetches the sentence text in a given token span- Parameters:
span-
-
updateOffsetsInCoreLabels
public static void updateOffsetsInCoreLabels(List<CoreLabel> tokens, int offset)
-
excelify
public static String excelify(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 List<CoreMap> readSentencesFromFile(String path) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
-