コード例 #1
0
        private void ProcessAssignPattern(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            PqlArgument leftRef  = VarRef;
            PqlExpr     rightRef = Expr;

            if (leftRef is PqlString)
            {
                Variable variable = pkb.Variables.GetVariableByName((leftRef as PqlString).Value);
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Assign assignment = Args.GetEntityByIndex(i) as Assign;
                    if (assignment == null || !assignment.Left.Name.Equals(variable.Name))
                    {
                        bindingsManager.RemoveBoundEntity(assignment, Args);
                        i--;
                    }
                }
            }

            if (rightRef != null)
            {
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Assign assignment = Args.GetEntityByIndex(i) as Assign;
                    if (assignment == null)
                    {
                        Args.RemoveEntity(assignment);
                        i--;
                    }
                    else
                    {
                        bool match = Expr.IsExact ? CompareTrees(assignment.Right, Expr.ExprTree, true) : FindTree(assignment.Right, Expr.ExprTree);
                        if (!match)
                        {
                            bindingsManager.RemoveBoundEntity(assignment, Args);
                            i--;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: EntityList.cs プロジェクト: adasinio97/Parserawka
        public IEntityList Intersection(IEntityList otherEntityList, BindingsManager bindingsManager)
        {
            EntityList entityList = otherEntityList as EntityList;

            for (int i = 0; i < list.Count; i++)
            {
                IEntity entity = GetEntityByIndex(i);
                if (!entityList.Contains(entity))
                {
                    bindingsManager.RemoveBoundEntity(entity, this);
                    i--;
                }
            }
            return(this);
        }
コード例 #3
0
        private void ProcessContainerPattern(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            PqlArgument leftRef = VarRef;

            if (leftRef is PqlString)
            {
                Variable variable = pkb.Variables.GetVariableByName((leftRef as PqlString).Value);
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Container container = Args.GetEntityByIndex(i) as Container;
                    if (!container.Condition.Name.Equals(variable.Name))
                    {
                        bindingsManager.RemoveBoundEntity(container, Args);
                        i--;
                    }
                }
            }
        }
コード例 #4
0
        public void Process(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            if (LeftArgs.GetSize() < RightArgs.GetSize())
            {
                IEntityList rightBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    IEntity     arg    = LeftArgs[i];
                    IEntityList result = ProcessLeftSide(pkb, arg);
                    if (LeftRef is PqlSynonym && RightRef is PqlSynonym)
                    {
                        bindingsManager.CreateMultipleBindings(arg, result, LeftArgs, RightArgs);
                    }
                    rightBounds.Sum(result);
                }
                RightArgs.Intersection(rightBounds, bindingsManager);

                IEntityList leftBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < RightArgs.GetSize(); i++)
                {
                    IEntity     arg    = RightArgs[i];
                    IEntityList result = ProcessRightSide(pkb, arg);
                    leftBounds.Sum(result);
                }
                LeftArgs.Intersection(leftBounds, bindingsManager);
            }
            else
            {
                IEntityList leftBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < RightArgs.GetSize(); i++)
                {
                    IEntity     arg    = RightArgs[i];
                    IEntityList result = ProcessRightSide(pkb, arg);
                    leftBounds.Sum(result);
                }
                LeftArgs.Intersection(leftBounds, bindingsManager);

                IEntityList rightBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    IEntity     arg    = LeftArgs[i];
                    IEntityList result = ProcessLeftSide(pkb, arg);
                    if (LeftRef is PqlSynonym && RightRef is PqlSynonym)
                    {
                        bindingsManager.CreateMultipleBindings(arg, result, LeftArgs, RightArgs);
                    }
                    rightBounds.Sum(result);
                }
                RightArgs.Intersection(rightBounds, bindingsManager);
            }

            if (LeftArgs == RightArgs)
            {
                List <IEntity> toRemove = new List <IEntity>();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    if (!CheckFull(pkb, LeftArgs[i], LeftArgs[i]))
                    {
                        toRemove.Add(LeftArgs[i]);
                    }
                }
                foreach (IEntity arg in toRemove)
                {
                    bindingsManager.RemoveBoundEntity(arg, LeftArgs);
                }
            }
        }