Exemplo n.º 1
0
        public object RelationValidate(object obj, out object objOutput)
        {
            var expr        = obj as Expr;
            var str         = obj as string; // text input
            var shapeSymbol = obj as ShapeSymbol;

            if (shapeSymbol != null)
            {
                expr = ExprG.Generate(shapeSymbol);
            }
            if (str != null)
            {
                expr = Text.Convert(str);
            }
            Debug.Assert(expr != null);
            var rTemp = ExprVisitor.Instance.UserMatch(expr); //input patter match

            Debug.Assert(rTemp != null);
            rTemp = ExprVisitor.Instance.Transform(rTemp);
            object output;

            if (shapeSymbol != null)
            {
                rTemp = shapeSymbol;
            }
            InternalValidate(expr, rTemp, out output);
            objOutput = rTemp;
            return(output);
        }
Exemplo n.º 2
0
        public bool?VerifyConcreteSymbol(string str)
        {
            Expr   expr  = Text.Convert(str);
            object rTemp = ExprVisitor.Instance.Match(expr);

            var ss = rTemp as ShapeSymbol;

            if (ss == null)
            {
                return(null);
            }
            return(ss.Shape.Concrete);
        }
Exemplo n.º 3
0
        private object Load(string fact, ShapeType?st = null,
                            bool tutorMode            = false, bool algebraSide = true)
        {
            if (!tutorMode)
            {
                //pre-fetch
                if (_preCache.ContainsKey(fact))
                {
                    var cachedExpr = _preCache[fact] as Expr;
                    Debug.Assert(cachedExpr != null);
                    foreach (KeyValuePair <object, object> pair in _cache)
                    {
                        if (pair.Key.Equals(cachedExpr))
                        {
                            return(pair.Value);
                        }
                    }
                    throw new Exception("Cannot reach here!");
                }
            }
            if (tutorMode && !algebraSide)
            {
                //pre-fetch
                if (_preCache.ContainsKey(fact))
                {
                    var cachedExpr = _preCache[fact] as Expr;
                    Debug.Assert(cachedExpr != null);
                    foreach (KeyValuePair <object, object> pair in _cache)
                    {
                        if (pair.Key.Equals(cachedExpr))
                        {
                            return(pair.Value);
                        }
                    }
                    throw new Exception("Cannot reach here!");
                }
            }
            Expr   expr   = Text.Convert(fact);
            object result = Load(expr, st, tutorMode);

            if (result == null)
            {
                return(null);
            }
            if (!tutorMode)
            {
                _preCache.Add(fact, expr);
            }
            return(result);
        }