Esempio n. 1
0
        private IntPair GetNPSpanOld(IndexedWord headword, SemanticGraph dep, IList <CoreLabel> sent)
        {
            IndexedWord cop = dep.GetChildWithReln(headword, UniversalEnglishGrammaticalRelations.Copula);
            Pair <IndexedWord, IndexedWord> leftRight = SemanticGraphUtils.LeftRightMostChildVertices(headword, dep);
            // headword can be first or last word
            int beginIdx = Math.Min(headword.Index() - 1, leftRight.first.Index() - 1);
            int endIdx   = Math.Max(headword.Index() - 1, leftRight.second.Index() - 1);

            // no copula relation
            if (cop == null)
            {
                return(new IntPair(beginIdx, endIdx));
            }
            // if we have copula relation
            IList <IndexedWord> children = dep.GetChildList(headword);
            int copIdx = children.IndexOf(cop);

            if (copIdx + 1 < children.Count)
            {
                beginIdx = Math.Min(headword.Index() - 1, SemanticGraphUtils.LeftMostChildVertice(children[copIdx + 1], dep).Index() - 1);
            }
            else
            {
                beginIdx = headword.Index() - 1;
            }
            return(new IntPair(beginIdx, endIdx));
        }
Esempio n. 2
0
        /// <summary>
        /// return the left and right most node except copula relation (nsubj & cop) and some others (maybe discourse?)
        /// e.g., you are the person -&gt; return "the person"
        /// </summary>
        private IntPair GetNPSpan(IndexedWord headword, SemanticGraph dep, IList <CoreLabel> sent)
        {
            int headwordIdx = headword.Index() - 1;
            IList <IndexedWord> children = dep.GetChildList(headword);
            //    if(children.size()==0) return new IntPair(headwordIdx, headwordIdx);    // the headword is the only word
            // check if we have copula relation
            IndexedWord cop      = dep.GetChildWithReln(headword, UniversalEnglishGrammaticalRelations.Copula);
            int         startIdx = (cop == null) ? 0 : children.IndexOf(cop) + 1;
            // children which will be inside of NP
            IList <IndexedWord> insideNP = Generics.NewArrayList();

            for (int i = startIdx; i < children.Count; i++)
            {
                IndexedWord       child = children[i];
                SemanticGraphEdge edge  = dep.GetEdge(headword, child);
                if (edge.GetRelation().GetShortName().Matches("dep|discourse|punct"))
                {
                    continue;
                }
                else
                {
                    // skip
                    insideNP.Add(child);
                }
            }
            if (insideNP.Count == 0)
            {
                return(new IntPair(headwordIdx, headwordIdx));
            }
            // the headword is the only word
            Pair <IndexedWord, IndexedWord> firstChildLeftRight = SemanticGraphUtils.LeftRightMostChildVertices(insideNP[0], dep);
            Pair <IndexedWord, IndexedWord> lastChildLeftRight  = SemanticGraphUtils.LeftRightMostChildVertices(insideNP[insideNP.Count - 1], dep);
            // headword can be first or last word
            int beginIdx = Math.Min(headwordIdx, firstChildLeftRight.first.Index() - 1);
            int endIdx   = Math.Max(headwordIdx, lastChildLeftRight.second.Index() - 1);

            return(new IntPair(beginIdx, endIdx));
        }