private int IndexOf(Parse child, Parse parent)
        {
            var kids = AbstractBottomUpParser.CollapsePunctuation(parent.Children, Punctuation);

            for (var ki = 0; ki < kids.Length; ki++)
            {
                if (child.Equals(kids[ki]))
                {
                    return(ki);
                }
            }
            return(-1);
        }
 private int NonPunctChildCount(Parse node)
 {
     return(AbstractBottomUpParser.CollapsePunctuation(node.Children, Punctuation).Length);
 }
示例#3
0
 /// <summary>
 /// Checks if the specified child is the first child of the specified parent.
 /// </summary>
 /// <param name="child">The child parse.</param>
 /// <param name="parent">The parent parse.</param>
 /// <returns><c>true</c> if the specified child is the first child of the specified parent, <c>false</c> otherwise.</returns>
 protected bool FirstChild(Parse child, Parse parent)
 {
     return(AbstractBottomUpParser.CollapsePunctuation(parent.Children, Punctuation)[0].Equals(child));
 }
示例#4
0
        public string[] GetContext(Parse parent, Parse[] constituents, int index, bool trimFrontier)
        {
            var features = new List <string> {
                "default"
            };
            var children = AbstractBottomUpParser.CollapsePunctuation(parent.Children, punctSet);
            var pStart   = children[0];
            var pend     = children[children.Length - 1];
            var type     = parent.Type;

            CheckCons(pStart, "begin", type, features);
            CheckCons(pend, "last", type, features);
            var production      = "p=" + Production(parent, false);
            var punctProduction = "pp=" + Production(parent, true);

            features.Add(production);
            features.Add(punctProduction);


            Parse             p1   = null;
            Parse             p2   = null;
            var               p1s  = constituents[index].NextPunctuationSet;
            SortedSet <Parse> p2s  = null;
            var               p_1s = constituents[index].PreviousPunctuationSet;
            SortedSet <Parse> p_2s = null;
            List <Parse>      rf;

            if (index == 0)
            {
                rf = new List <Parse>();
            }
            else
            {
                rf = Parser.GetRightFrontier(constituents[0], punctSet);
                if (trimFrontier)
                {
                    var pi = rf.IndexOf(parent);
                    if (pi == -1)
                    {
                        throw new InvalidOperationException("Parent not found in right frontier:" + parent + " rf=" + rf);
                    }
                    for (var ri = 0; ri <= pi; ri++)
                    {
                        //System.err.println(pi+" removing "+((Parse)rf.get(0)).getType()+" "+rf.get(0)+" "+(rf.size()-1)+" remain");
                        rf.RemoveAt(0);
                    }
                }
            }

            GetFrontierNodes(rf, leftNodes);
            var p_1 = leftNodes[0];
            var p_2 = leftNodes[1];
            var ps  = constituents.Length;

            if (p_1 != null)
            {
                p_2s = p_1.PreviousPunctuationSet;
            }
            if (index + 1 < ps)
            {
                p1  = constituents[index + 1];
                p2s = p1.NextPunctuationSet;
            }
            if (index + 2 < ps)
            {
                p2 = constituents[index + 2];
            }
            Surround(p_1, -1, type, p_1s, features);
            Surround(p_2, -2, type, p_2s, features);
            Surround(p1, 1, type, p1s, features);
            Surround(p2, 2, type, p2s, features);

            return(features.ToArray());
        }