Пример #1
0
        public virtual void Annotate(Annotation dataset)
        {
            // TODO for now, we only merge RelationMentions
            logger.Info("Extractor 0 annotating dataset.");
            extractors[0].Annotate(dataset);
            // store all the RelationMentions per sentence
            IList <ICollection <RelationMention> > allRelationMentions = new List <ICollection <RelationMention> >();

            foreach (ICoreMap sentence in dataset.Get(typeof(CoreAnnotations.SentencesAnnotation)))
            {
                IList <RelationMention>       relationMentions       = sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation));
                ICollection <RelationMention> uniqueRelationMentions = new HashSet <RelationMention>(relationMentions);
                allRelationMentions.Add(uniqueRelationMentions);
            }
            // skip first extractor since we did it at the top
            for (int extractorIndex = 1; extractorIndex < extractors.Length; extractorIndex++)
            {
                logger.Info("Extractor " + extractorIndex + " annotating dataset.");
                IExtractor extractor = extractors[extractorIndex];
                extractor.Annotate(dataset);
                // walk through all sentences and merge our RelationMentions with the combined set
                int sentenceIndex = 0;
                foreach (ICoreMap sentence_1 in dataset.Get(typeof(CoreAnnotations.SentencesAnnotation)))
                {
                    IList <RelationMention> relationMentions = sentence_1.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation));
                    Sharpen.Collections.AddAll(allRelationMentions[sentenceIndex], relationMentions);
                }
            }
            // put all merged relations back into the dataset
            int sentenceIndex_1 = 0;

            foreach (ICoreMap sentence_2 in dataset.Get(typeof(CoreAnnotations.SentencesAnnotation)))
            {
                ICollection <RelationMention> uniqueRelationMentions = allRelationMentions[sentenceIndex_1];
                IList <RelationMention>       relationMentions       = new List <RelationMention>(uniqueRelationMentions);
                sentence_2.Set(typeof(MachineReadingAnnotations.RelationMentionsAnnotation), relationMentions);
                sentenceIndex_1++;
            }
        }