Example #1
0
        protected override IDerivation ExpandRnd(DerivationContext aContext)
        {
            DictionaryDerivation lList = new DictionaryDerivation(InsertSpace, aContext);
            int lExprCnt = 1;

            for (int i = 0; i < mPhrases.Count; i++)
            {
                IPhrase     lPhr = mPhrases[i];
                IDerivation lRes = lPhr.Expand(aContext);
                string      lKeyName;
                Symbol      lCurrentSymbol = lPhr as Symbol;
                if (lCurrentSymbol != null)
                {
                    lCurrentSymbol.OccurenceInSeq = i;
                    lKeyName = lCurrentSymbol.Text;
                    //взять протокол вывода этого правила
                    //TODO: aContext.RuleSeqProtocol.Add(lCurrentSymbol.Text, lRes);
                    //добавить в его протокол вывода последовательности имя lCurrentSymbol.Text и результат lRes
                }
                else
                {
                    lKeyName = string.Format("Expr{0}", lExprCnt++);
                }
                lList.Add(lKeyName, lRes, aContext);
            }
            return(lList);
        }
Example #2
0
        private string AddObject(object aObject, string aName, string aRootNodeID)
        {
            if (aObject == null)
            {
                return("null!");
            }
            string type  = aObject.GetType().Name;
            string title = type + " " + aName;
            string lNodeId;

            if (typeof(ListDerivation) == aObject.GetType())
            {
                ListDerivation l = aObject as ListDerivation;
                string         s = "\r\n0";
                for (int i = 1; i < l.mList.Count; i++)
                {
                    s += " | " + i.ToString();
                }
                lNodeId = gb.AddNode(title + s);
                gb.SetBGColor(lNodeId, 255, 255, 0);
                if (aRootNodeID != null)
                {
                    gb.AddEdge(aRootNodeID, aName, lNodeId);
                }
                for (int i = 0; i < l.mList.Count; i++)
                {
                    AddObject(l.mList[i], string.Format("[{0}]", i), lNodeId);
                }
                return(lNodeId);
            }
            else if (typeof(TextDerivation) == aObject.GetType())
            {
                if (aRootNodeID != null)
                {
                    TextDerivation l    = aObject as TextDerivation;
                    string         lStr = string.Format("\"{0}\"", l.Text);
                    gb.AddEdge(aRootNodeID, aName, lStr);
                    gb.SetBGColor(lStr, 0, 255, 0);
                }
                return(null);
            }
            else if (typeof(SymbolDerivation) == aObject.GetType())
            {
                SymbolDerivation l = aObject as SymbolDerivation;
                gb.AddEdge(aRootNodeID, aName, l.Symbol.Text + " " + type);
                return(null);
            }
            else if (typeof(DictionaryDerivation) == aObject.GetType())
            {
                DictionaryDerivation l    = aObject as DictionaryDerivation;
                String[]             keys = l.Keys;
                title  += "\r\n" + string.Join("\r\n", keys);
                lNodeId = gb.AddNode(title);
                gb.SetBGColor(lNodeId, 255, 128, 0);
                if (aRootNodeID != null)
                {
                    gb.AddEdge(aRootNodeID, aName, lNodeId);
                }
                foreach (string lKey in keys)
                {
                    AddObject(l[lKey], lKey, lNodeId);
                }
                return(lNodeId);
            }
            //default
            lNodeId = gb.AddNode(title);
            return(lNodeId);
        }