Esempio n. 1
0
        // for backward compatibility with a few old things
        // TODO: Aim to get rid of this entirely
        private static void AddObsoleteCoreferenceAnnotations(Annotation annotation, IList <IList <Mention> > orderedMentions, IDictionary <int, CorefChain> result)
        {
            IList <Pair <IntTuple, IntTuple> > links = SieveCoreferenceSystem.GetLinks(result);
            //
            // save the coref output as CorefGraphAnnotation
            //
            // cdm 2013: this block didn't seem to be doing anything needed....
            // List<List<CoreLabel>> sents = new ArrayList<List<CoreLabel>>();
            // for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
            //   List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
            //   sents.add(tokens);
            // }
            // this graph is stored in CorefGraphAnnotation -- the raw links found by the coref system
            IList <Pair <IntTuple, IntTuple> > graph = new List <Pair <IntTuple, IntTuple> >();

            foreach (Pair <IntTuple, IntTuple> link in links)
            {
                //
                // Note: all offsets in the graph start at 1 (not at 0!)
                //       we do this for consistency reasons, as indices for syntactic dependencies start at 1
                //
                int      srcSent = link.first.Get(0);
                int      srcTok  = orderedMentions[srcSent - 1][link.first.Get(1) - 1].headIndex + 1;
                int      dstSent = link.second.Get(0);
                int      dstTok  = orderedMentions[dstSent - 1][link.second.Get(1) - 1].headIndex + 1;
                IntTuple dst     = new IntTuple(2);
                dst.Set(0, dstSent);
                dst.Set(1, dstTok);
                IntTuple src = new IntTuple(2);
                src.Set(0, srcSent);
                src.Set(1, srcTok);
                graph.Add(new Pair <IntTuple, IntTuple>(src, dst));
            }
            annotation.Set(typeof(CorefCoreAnnotations.CorefGraphAnnotation), graph);
            foreach (CorefChain corefChain in result.Values)
            {
                if (corefChain.GetMentionsInTextualOrder().Count < 2)
                {
                    continue;
                }
                ICollection <CoreLabel> coreferentTokens = Generics.NewHashSet();
                foreach (CorefChain.CorefMention mention in corefChain.GetMentionsInTextualOrder())
                {
                    ICoreMap  sentence = annotation.Get(typeof(CoreAnnotations.SentencesAnnotation))[mention.sentNum - 1];
                    CoreLabel token    = sentence.Get(typeof(CoreAnnotations.TokensAnnotation))[mention.headIndex - 1];
                    coreferentTokens.Add(token);
                }
                foreach (CoreLabel token_1 in coreferentTokens)
                {
                    token_1.Set(typeof(CorefCoreAnnotations.CorefClusterAnnotation), coreferentTokens);
                }
            }
        }
Esempio n. 2
0
 public DeterministicCorefAnnotator(Properties props)
 {
     // for backward compatibility
     try
     {
         corefSystem      = new SieveCoreferenceSystem(props);
         mentionExtractor = new MentionExtractor(corefSystem.Dictionaries(), corefSystem.Semantics());
         OldFormat        = bool.Parse(props.GetProperty("oldCorefFormat", "false"));
         allowReparsing   = PropertiesUtils.GetBool(props, Constants.AllowReparsingProp, Constants.AllowReparsing);
         // unless custom mention detection is set, just use the default coref mention detector
         performMentionDetection = !PropertiesUtils.GetBool(props, "dcoref.useCustomMentionDetection", false);
         if (performMentionDetection)
         {
             mentionAnnotator = new CorefMentionAnnotator(props);
         }
     }
     catch (Exception e)
     {
         log.Error("cannot create DeterministicCorefAnnotator!");
         log.Error(e);
         throw new Exception(e);
     }
 }