示例#1
0
        private string FindNextParagraphSpeaker(IList <ICoreMap> paragraph, int paragraphOffset, Dictionaries dict)
        {
            ICoreMap lastSent = paragraph[paragraph.Count - 1];
            string   speaker  = string.Empty;

            foreach (CoreLabel w in lastSent.Get(typeof(CoreAnnotations.TokensAnnotation)))
            {
                if (w.Get(typeof(CoreAnnotations.LemmaAnnotation)).Equals("report") || w.Get(typeof(CoreAnnotations.LemmaAnnotation)).Equals("say"))
                {
                    string        word       = w.Get(typeof(CoreAnnotations.TextAnnotation));
                    SemanticGraph dependency = lastSent.Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));
                    IndexedWord   t          = dependency.GetNodeByWordPattern(word);
                    foreach (Pair <GrammaticalRelation, IndexedWord> child in dependency.ChildPairs(t))
                    {
                        if (child.First().GetShortName().Equals("nsubj"))
                        {
                            int subjectIndex = child.Second().Index();
                            // start from 1
                            IntTuple headPosition = new IntTuple(2);
                            headPosition.Set(0, paragraph.Count - 1 + paragraphOffset);
                            headPosition.Set(1, subjectIndex - 1);
                            if (mentionheadPositions.Contains(headPosition) && mentionheadPositions[headPosition].nerString.StartsWith("PER"))
                            {
                                speaker = int.ToString(mentionheadPositions[headPosition].mentionID);
                            }
                        }
                    }
                }
            }
            return(speaker);
        }
示例#2
0
        private bool FindSpeaker(int utterNum, int sentNum, IList <ICoreMap> sentences, int startIndex, int endIndex, Dictionaries dict)
        {
            IList <CoreLabel> sent = sentences[sentNum].Get(typeof(CoreAnnotations.TokensAnnotation));

            for (int i = startIndex; i < endIndex; i++)
            {
                if (sent[i].Get(typeof(CoreAnnotations.UtteranceAnnotation)) != 0)
                {
                    continue;
                }
                string lemma = sent[i].Get(typeof(CoreAnnotations.LemmaAnnotation));
                string word  = sent[i].Get(typeof(CoreAnnotations.TextAnnotation));
                if (dict.reportVerb.Contains(lemma))
                {
                    // find subject
                    SemanticGraph dependency = sentences[sentNum].Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));
                    IndexedWord   w          = dependency.GetNodeByWordPattern(word);
                    if (w != null)
                    {
                        foreach (Pair <GrammaticalRelation, IndexedWord> child in dependency.ChildPairs(w))
                        {
                            if (child.First().GetShortName().Equals("nsubj"))
                            {
                                string subjectString = child.Second().Word();
                                int    subjectIndex  = child.Second().Index();
                                // start from 1
                                IntTuple headPosition = new IntTuple(2);
                                headPosition.Set(0, sentNum);
                                headPosition.Set(1, subjectIndex - 1);
                                string speaker;
                                if (mentionheadPositions.Contains(headPosition))
                                {
                                    speaker = int.ToString(mentionheadPositions[headPosition].mentionID);
                                }
                                else
                                {
                                    speaker = subjectString;
                                }
                                speakers[utterNum] = speaker;
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        SieveCoreferenceSystem.logger.Warning("Cannot find node in dependency for word " + word);
                    }
                }
            }
            return(false);
        }