public PreviousSymbol(LexerResult s, ParseTreeNode p, List <string> r, List <string> n,
                              bool optional)
        {
            symbol = (LexerResult)s.Clone(); // (lex results never mutated)
            parent = p;                      // .clone(); // Capture state of subtree on construction.

            if (s.BLEFT != null)
            {
                parent.children.Add(s.BLEFT);
            }
            if (s.TLEFT != null)
            {
                parent.children.Add(s.TLEFT);
            }

            // Avoid crashing on null values.
            if (r == null)
            {
                regions            = new List <string>();
                regionNonterminals = new List <string>();
            }
            else
            {
                regions            = r;
                regionNonterminals = n;
            }

            regionsOptional = optional;
        }
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is LexerResult))
            {
                return(false);
            }
            LexerResult o = obj as LexerResult;

            if (!segment.GetUniqueName().Equals(o.segment.GetUniqueName()))
            {
                return(false);
            }

            // test classifications
            if (segment.classification.Count != o.segment.classification.Count)
            {
                return(false);
            }
            for (int i = 0; i < segment.classification.Count; i++)
            {
                Classification c1 = segment.classification[i];
                Classification c2 = o.segment.classification[i];
                if (!c1.Equals(c2))
                {
                    return(false);
                }
            }

            return(true);
        }
 public PreviousSymbol(ParseTreeNode p, bool optional)
 {
     symbol             = null;
     parent             = p;
     regions            = new List <string>();
     regionNonterminals = new List <string>();
     regionsOptional    = optional;
 }
 public SymbolTreeNode(LexerResult selectedResult)
 {
     nodeType   = selectedResult.segment.classification[0].symbol;
     symbolData = selectedResult;            // not cloning (assumption: lexer results never modified).
     lexResult  = selectedResult;            // redundant?
     strokes    = selectedResult.segment.strokes;
     lbt        = selectedResult.lbt;
     children   = null;
     id_num     = Interlocked.Increment(ref INST_ID);
 }
        public object Clone()
        {
            LexerResult r = new LexerResult();

            r.segment = segment.Clone() as Segment;
            r.lbt     = new LBT(lbt);
            r.adj     = adj;
            r.TLEFT   = TLEFT;
            r.BLEFT   = BLEFT;
            return(r);
        }
 public int CompareTo(object obj)
 {
     // Need to negate comparison to sort by decreasing probability.
     if (obj is LexerResult)
     {
         LexerResult t = (LexerResult)obj;
         if (t.segment.classification.Count > 0 && segment.classification.Count > 0)
         {
             return(-(segment.classification[0].probability.
                      CompareTo(t.segment.classification[0].probability)));
         }
         else
         {
             throw new ArgumentException("LexerResult::CompareTo applied where object or" +
                                         " comparison has no associated classification results.");
         }
     }
     throw new ArgumentException("LexerResult::CompareTo(): object is not a LexerResultn.");
 }
        public override ParseTreeNode clone()
        {
            // Node labels and stoke data will be fixed for a given node (ref. only), but children will
            // differ for different parse trees (new copy).
            LexerResult    resultCopy = (LexerResult)symbolData.Clone();
            SymbolTreeNode nodeCopy   = new SymbolTreeNode(resultCopy);

            nodeCopy.strokes = strokes;
            nodeCopy.lbt     = null;
            if (lbt != null)
            {
                nodeCopy.lbt = new LBT(lbt);           // copy lbt
            }
            if (children != null)
            {
                foreach (ParseTreeNode child in children)
                {
                    nodeCopy.children.Add(child.clone());
                }
            }
            nodeCopy.symbolData = symbolData;
            return(nodeCopy);
        }