コード例 #1
0
 public static string Plot(ShapeSymbol ss)
 {
     if (ss.Shape.Concrete)
     {
         return string.Format("Plot shape {0} onto the geometrical side", ss);                
     }
     else
     {
         return string.Format("Write shape {0} onto the algebraic side", ss); 
     }
 }
コード例 #2
0
ファイル: Reasoner.Validate.cs プロジェクト: buptkang/MathCog
 private void InternalValidate(Expr expr, ShapeSymbol ss, out object output)
 {
     output = false;
     foreach (var gn in RelationGraph.Nodes)
     {
         var sn = gn as ShapeNode;
         if (sn == null) continue;
         bool result = sn.ShapeSymbol.ApproximateMatch(ss);
         if (result)
         {
             output = true;
             return;
         }
     }
     output = RelationGraph.RelationExist(ss);
 }
コード例 #3
0
ファイル: GraphNode.cs プロジェクト: buptkang/Relation.Logic
 public ShapeNode(ShapeSymbol shape)
 {
     _shape = shape;
 }
コード例 #4
0
        private ShapeNode CreateShapeNode(ShapeSymbol ss, object obj, out List<object> relGoals)
        {
            var gn = new ShapeNode(ss);
            relGoals = new List<object>();
            var lst = obj as List<Tuple<object, object>>;
            if (lst == null) return gn;

            foreach (var tuple in lst)
            {
                if (tuple.Item1.Equals(ss))
                {
                    BuildRelation(gn, tuple.Item2);
                    relGoals.Add(tuple.Item2);
                }

                if (tuple.Item2.Equals(ss))
                {
                    BuildRelation(tuple.Item1, gn);
                    relGoals.Add(tuple.Item1);
                }
            }

            _nodes.Add(gn);
            return gn;
        }
コード例 #5
0
        public bool ConstraintSatisfy(ShapeSymbol ss, out object obj)
        {
            var graphNodes = _nodes;

            var lst = new List<Tuple<object, object>>();

            #region Unary Relation Checking

            for (var i = 0; i < graphNodes.Count; i++)
            {
                var goalNode = graphNodes[i] as GoalNode;
                if (goalNode != null)
                {
                    var goal = goalNode.Goal as EqGoal;
                    if (goal != null)
                    {
                        if (ss.UnifyExplicitProperty(goal))
                        {
                            lst.Add(new Tuple<object, object>(goalNode, ss));
                        }
                    }                    
                }
                var shapeNode = graphNodes[i] as ShapeNode;
                if (shapeNode != null)
                {
                    var tempSs = shapeNode.ShapeSymbol;
                    if (tempSs != null)
                    {
                        if (ss.UnifyShape(tempSs))
                        {
                            lst.Add(new Tuple<object, object>(ss, tempSs));
                        }
                        if (tempSs.UnifyShape(ss))
                        {
                            lst.Add(new Tuple<object, object>(tempSs, ss));
                        }
                    }
                }                
            }

            #endregion

            obj = lst;
            return lst.Count != 0;
        }
コード例 #6
0
ファイル: Line.cs プロジェクト: buptkang/Relation.Logic
        public override bool UnifyShape(ShapeSymbol ss)
        {
            var ps = ss as PointSymbol;
            if (ps == null) return false;
            var pt = ps.Shape as Point;
            Debug.Assert(pt != null);
            var line = Shape as Line;
            Debug.Assert(line != null);

            Term xTerm = null;
            if (line.A != null)
            {
                xTerm = new Term(Expression.Multiply, new List<object>() {line.A, pt.XCoordinate});
            }
            Term yTerm = null;
            if (line.B != null)
            {
                yTerm = new Term(Expression.Multiply, new List<object>() { line.B, pt.YCoordinate });
            }

            var lst = new List<object>();
            if(xTerm != null) lst.Add(xTerm);
            if(yTerm != null) lst.Add(yTerm);
            if(line.C != null) lst.Add(line.C);

            var lhs = new Term(Expression.Add, lst);
            var eq = new Equation(lhs, 0);

            object obj;
            bool? satisified = eq.Eval(out obj, false);

            if (satisified == null) return false;
            if (satisified.Value) return true;

            return false;
        }
コード例 #7
0
ファイル: Graph.cs プロジェクト: buptkang/Relation.Logic
 private ShapeNode AddShapeNode(ShapeSymbol shape)
 {
     //1. build relation using geometry constraint-solving (synthesize new node) (Top-Down)
     object relations;
     ConstraintSatisfy(shape, out relations);
     List<object> goalRels;
     ShapeNode shapeNode = CreateShapeNode(shape, relations, out goalRels);
     //Search bottom up goalNodes, start reify
     foreach (object obj in goalRels)
     {
         var goalNode = obj as GoalNode;
         if (goalNode == null) continue;
         Reify(goalNode);
     }
     return shapeNode;
 }
コード例 #8
0
        /// <summary>
        /// ShapeSymbol Input Pattern Match
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="ss"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        private bool EvalExprPatterns(Expr expr, ShapeSymbol ss, out object output, bool userInput = false)
        {
            if (!userInput) RelationGraph.AddNode(ss);

            //expr = ExprG.Generate(ss);
            output = new AGShapeExpr(expr, ss);
            return true;
        }
コード例 #9
0
 public ReifyEventArgs(ShapeSymbol ss)
 {
     CurrentShapeSymbol = ss;
 }
コード例 #10
0
ファイル: Reasoner.cs プロジェクト: buptkang/MathCog
 //Geometry Side Input Variation
 private object UnLoad(ShapeSymbol rTemp)
 {
     List<KeyValuePair<object, object>> fact
         = _cache.Where(x => x.Key.Equals(rTemp)).ToList();
     if (fact.Count != 0)
     {
         Debug.Assert(fact.Count == 1);
         bool result = UnEvalExprPatterns(fact[0].Value);
         _cache.Remove(fact[0]);
         return result;
     }
     return false;
 }
コード例 #11
0
ファイル: Reasoner.cs プロジェクト: buptkang/MathCog
 //Geometry Side Input Variation
 private object Load(ShapeSymbol rTemp, bool tutorMode = false)
 {
     Expr expr = ExprG.Generate(rTemp);
     object output;
     EvalExprPatterns(expr, rTemp, null, out output, tutorMode);
     var iKnowledge = output as IKnowledge;
     if (iKnowledge != null && !tutorMode)
     {
         _cache.Add(new KeyValuePair<object, object>(rTemp, iKnowledge));
     }
     return output;
 }
コード例 #12
0
ファイル: ExprGenerator.cs プロジェクト: buptkang/MathCog
        public static Expr Generate(ShapeSymbol ss)
        {
            var ps = ss as PointSymbol;
            if (ps != null) return ps.ToExpr();

            var ls = ss as LineSymbol;
            if (ls != null) return ls.ToExpr();

            var lineSeg = ss as LineSegmentSymbol;
            if (lineSeg != null) return lineSeg.ToExpr();

            var circle = ss as CircleSymbol;
            if (circle != null) return circle.ToExpr();

            return null;
        }
コード例 #13
0
ファイル: Graph.cs プロジェクト: buptkang/Relation.Logic
 public bool RelationExist(ShapeSymbol shape)
 {
     object relations;
     ConstraintSatisfy(shape, out relations);
     var lst = relations as List<Tuple<object, object>>;
     Debug.Assert(lst != null);
     return lst.Count != 0;
 }
コード例 #14
0
ファイル: Graph.cs プロジェクト: buptkang/Relation.Logic
 private bool DeleteShapeNode(ShapeSymbol shape)
 {
     var shapeNode = SearchNode(shape) as ShapeNode;
     if (shapeNode == null) return false;
     _nodes.Remove(shapeNode);
     UpdateUpperQueryNode(shapeNode);
     UnReify(shapeNode);
     DeleteSynNode(shapeNode);
     UnBuildRelation(shapeNode);
     _preCache.Remove(shape);
     return true;
 }
コード例 #15
0
 public override bool UnifyShape(ShapeSymbol ss)
 {
     return false;
 }
コード例 #16
0
 public override bool UnifyShape(ShapeSymbol ss)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public abstract bool UnifyShape(ShapeSymbol ss);
コード例 #18
0
        private bool ShapeVerify(IKnowledge obj, ShapeSymbol shape, out string msg, out object output)
        {
            msg = AGTutorMessage.VerifyWrong;
            output = null;

            List<Tuple<object, object>> trace = null;

            var agShapeExpr = new AGShapeExpr(obj.Expr, shape);
            agShapeExpr.IsSelected = true;
            agShapeExpr.GenerateSolvingTrace();
            trace = agShapeExpr.AutoTrace;

            if (trace == null || trace.Count == 0) return false;

         /*   var lastTuple = trace[trace.Count - 1] as Tuple<object, object>;
            var lastLst = lastTuple.Item2 as List<object>;
            Debug.Assert(lastLst != null);
            Debug.Assert(lastLst.Count != 0);
            var lastTs = lastLst[lastLst.Count - 1] as TraceStepExpr;*/
            bool matchResult = UserGraph.Match(trace); //match and update
            if (!matchResult) return false;

            //insert nodes
            UserGraph.Insert(trace);
            CurrentStateNode = UserGraph.SearchInnerLoopNode(obj); //update _currentStateNode;
            //var nextTuple1 = UserGraph.SearchNextInnerLoopNode(CurrentStateNode);
          /*  if (nextTuple1 == null) // query-end
            {
                msg = AGTutorMessage.SolvedProblem;
                return true;
            }*/
            msg = AGTutorMessage.VerifyCorrect;
            return true;
        }
コード例 #19
0
 private bool DispatchUnreify(ShapeSymbol ss, EqGoal goal)
 {
     var ps = ss as PointSymbol;
     var ls = ss as LineSymbol;
     if (ps != null)
     {
         return ps.UnReify(goal);
     }
     if (ls != null)
     {
         return ls.UnReify(goal);
     }
     return false;
 }
コード例 #20
0
 public ReifyEventArgs(ShapeSymbol ss)
 {
     CurrentShapeSymbol = ss;
 }
コード例 #21
0
ファイル: AGShapeExpr.cs プロジェクト: buptkang/MathCog
 public AGShapeExpr(starPadSDK.MathExpr.Expr expr, ShapeSymbol ss)
     : base(expr)
 {
     _shapeSymbol = ss;
 }