Class AnnotationUtils


  • public class AnnotationUtils
    extends Object
    Utilities to manipulate Annotations storing datasets or sentences with Machine Reading info
    Author:
    Mihai
    • 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 -
      • 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,
                                        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 -
      • 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
      • addEventMention

        public static void addEventMention​(CoreMap sentence,
                                           EventMention arg)
      • 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 -
      • sentenceToString

        public static String sentenceToString​(CoreMap sent)
      • tokensAndNELabelsToString

        public static String tokensAndNELabelsToString​(CoreMap sentence)
      • datasetToString

        public static String datasetToString​(CoreMap dataset)
      • updateOffsets

        public static void updateOffsets​(List<Word> tokens,
                                         int offset)
      • 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.