コード例 #1
0
 public virtual void resolveTemplates(Rete.Rete engine)
 {
     ICondition[] cnds = Conditions;
     for (int idx = 0; idx < cnds.Length; idx++)
     {
         ICondition cnd = cnds[idx];
         if (cnd is ObjectCondition)
         {
             ObjectCondition oc  = (ObjectCondition)cnd;
             Deftemplate     dft = (Deftemplate)engine.findTemplate(oc.TemplateName);
             if (dft != null)
             {
                 oc.Deftemplate = dft;
             }
         }
         else if (cnd is ExistCondition)
         {
             ExistCondition exc = (ExistCondition)cnd;
             Deftemplate    dft = (Deftemplate)engine.findTemplate(exc.TemplateName);
             if (dft != null)
             {
                 exc.Deftemplate = dft;
             }
         }
         else if (cnd is TemporalCondition)
         {
             TemporalCondition tempc = (TemporalCondition)cnd;
             Deftemplate       dft   = (Deftemplate)engine.findTemplate(tempc.TemplateName);
             if (dft != null)
             {
                 tempc.Deftemplate = dft;
             }
         }
     }
 }
コード例 #2
0
        public static ExistCondition newExistCondition(ObjectCondition cond)
        {
            ExistCondition exc = new ExistCondition();

            exc.constraints  = cond.constraints;
            exc.negated      = cond.negated;
            exc.nodes        = cond.nodes;
            exc.template     = cond.template;
            exc.templateName = cond.templateName;
            return(exc);
        }
コード例 #3
0
        public void CEType(IList list)
        {
            Token exp;
            Token exp2;
            Object etime;
            Object nested = null;
            IList alpha = new ArrayList();
            ObjectCondition oc = null;
            TemporalCondition tmpc = null;
            if (jj_2_24(2147483647))
            {
                jj_consume_token(CLIPSParserConstants_Fields.NOTCE);
                jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER);
                switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                {
                    case CLIPSParserConstants_Fields.LBRACE:
                        while (true)
                        {
                            templatePatterns(alpha);
                            switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                            {
                                case CLIPSParserConstants_Fields.LBRACE:
                                    ;
                                    break;

                                default:
                                    jj_la1[37] = jj_gen;
                                    //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                    goto label_18_brk;
                            }
                        }
                        //UPGRADE_NOTE: Label 'label_18_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                        label_18_brk:
                        ;

                        break;

                    default:
                        jj_la1[38] = jj_gen;
                        ;
                        break;
                }
                jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                oc = new ObjectCondition();
                oc.Negated = true;
                oc.TemplateName = exp.image;
                IEnumerator itr = alpha.GetEnumerator();
                while (itr.MoveNext())
                {
                    oc.addConstraint((IConstraint) itr.Current);
                }
                list.Add(oc);
                alpha.Clear();
                exp = null;
            }
            else
            {
                switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                {
                    case CLIPSParserConstants_Fields.NOTCE:
                        jj_consume_token(CLIPSParserConstants_Fields.NOTCE);
                        jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                        nested = expr();
                        jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                        TestCondition tc = new TestCondition();
                        tc.Negated = true;
                        if (nested is IFunction)
                        {
                            tc.Function = (IFunction) nested;
                        }
                        list.Add(tc);
                        break;

                    default:
                        jj_la1[47] = jj_gen;
                        if (jj_2_25(2147483647))
                        {
                            jj_consume_token(CLIPSParserConstants_Fields.TEMPORAL);
                            jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                            jj_consume_token(CLIPSParserConstants_Fields.RELATIVETIME);
                            etime = typeExpr();
                            jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                            jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                            jj_consume_token(CLIPSParserConstants_Fields.NOTCE);
                            jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                            exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER);
                            switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                            {
                                case CLIPSParserConstants_Fields.LBRACE:
                                    while (true)
                                    {
                                        templatePatterns(alpha);
                                        switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                        {
                                            case CLIPSParserConstants_Fields.LBRACE:
                                                ;
                                                break;

                                            default:
                                                jj_la1[39] = jj_gen;
                                                //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                                goto label_19_brk;
                                        }
                                    }
                                    //UPGRADE_NOTE: Label 'label_19_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                                    label_19_brk:
                                    ;

                                    break;

                                default:
                                    jj_la1[40] = jj_gen;
                                    ;
                                    break;
                            }
                            jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                            jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                            tmpc = new TemporalCondition();
                            tmpc.TemplateName = exp.image;
                            tmpc.Negated = true;
                            if (etime is Decimal)
                            {
                                tmpc.RelativeTime = Decimal.ToInt32(((Decimal) etime));
                            }
                            IEnumerator itr = alpha.GetEnumerator();
                            while (itr.MoveNext())
                            {
                                tmpc.addConstraint((IConstraint) itr.Current);
                            }
                            list.Add(tmpc);
                            alpha.Clear();
                            exp = null;
                        }
                        else
                        {
                            switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                            {
                                case CLIPSParserConstants_Fields.TEMPORAL:
                                    jj_consume_token(CLIPSParserConstants_Fields.TEMPORAL);
                                    exp2 = jj_consume_token(CLIPSParserConstants_Fields.BIND);
                                    jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                                    jj_consume_token(CLIPSParserConstants_Fields.RELATIVETIME);
                                    etime = typeExpr();
                                    jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                                    jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                                    exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER);
                                    switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                    {
                                        case CLIPSParserConstants_Fields.LBRACE:
                                            while (true)
                                            {
                                                templatePatterns(alpha);
                                                switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                                {
                                                    case CLIPSParserConstants_Fields.LBRACE:
                                                        ;
                                                        break;

                                                    default:
                                                        jj_la1[41] = jj_gen;
                                                        //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                                        goto label_20_brk;
                                                }
                                            }
                                            //UPGRADE_NOTE: Label 'label_20_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                                            label_20_brk:
                                            ;

                                            break;

                                        default:
                                            jj_la1[42] = jj_gen;
                                            ;
                                            break;
                                    }
                                    jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                                    tmpc = new TemporalCondition();
                                    tmpc.TemplateName = exp.image;
                                    tmpc.VariableName = exp2.image.Substring(1);
                                    if (etime is Decimal)
                                    {
                                        tmpc.RelativeTime = Decimal.ToInt32(((Decimal) etime));
                                    }
                                    IEnumerator itr = alpha.GetEnumerator();
                                    while (itr.MoveNext())
                                    {
                                        tmpc.addConstraint((IConstraint) itr.Current);
                                    }
                                    list.Add(tmpc);
                                    alpha.Clear();
                                    exp = null;
                                    break;

                                case CLIPSParserConstants_Fields.TEST:
                                    jj_consume_token(CLIPSParserConstants_Fields.TEST);
                                    jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                                    nested = expr();
                                    jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                                    tc = new TestCondition();
                                    if (nested is IFunction)
                                    {
                                        tc.Function = (IFunction) nested;
                                    }
                                    list.Add(tc);
                                    break;

                                case CLIPSParserConstants_Fields.AND1:
                                    jj_consume_token(CLIPSParserConstants_Fields.AND1);
                                    while (true)
                                    {
                                        jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                                        nested = expr();
                                        jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                                        switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                        {
                                            case CLIPSParserConstants_Fields.LBRACE:
                                                ;
                                                break;

                                            default:
                                                jj_la1[43] = jj_gen;
                                                //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                                goto label_21_brk;
                                        }
                                    }
                                    //UPGRADE_NOTE: Label 'label_21_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                                    label_21_brk:
                                    ;

                                    AndCondition ac = new AndCondition();
                                    ac.addNestedConditionElement(nested);
                                    list.Add(ac);
                                    break;

                                case CLIPSParserConstants_Fields.EXISTS:
                                    jj_consume_token(CLIPSParserConstants_Fields.EXISTS);
                                    while (true)
                                    {
                                        jj_consume_token(CLIPSParserConstants_Fields.LBRACE);
                                        CEType(alpha);
                                        jj_consume_token(CLIPSParserConstants_Fields.RBRACE);
                                        switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                        {
                                            case CLIPSParserConstants_Fields.LBRACE:
                                                ;
                                                break;

                                            default:
                                                jj_la1[44] = jj_gen;
                                                //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                                goto label_22_brk;
                                        }
                                    }
                                    //UPGRADE_NOTE: Label 'label_22_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                                    label_22_brk:
                                    ;

                                    ExistCondition exc = null;
                                    if (alpha.Count > 1)
                                    {
                                        for (int iz = 0; iz < alpha.Count; iz++)
                                        {
                                            exc = ExistCondition.newExistCondition((ObjectCondition) alpha[iz]);
                                            list.Add(exc);
                                        }
                                    }
                                    else
                                    {
                                        exc = ExistCondition.newExistCondition((ObjectCondition) alpha[0]);
                                        list.Add(exc);
                                    }
                                    break;

                                case CLIPSParserConstants_Fields.IDENTIFIER:
                                    exp = jj_consume_token(CLIPSParserConstants_Fields.IDENTIFIER);
                                    switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                    {
                                        case CLIPSParserConstants_Fields.LBRACE:
                                            while (true)
                                            {
                                                templatePatterns(alpha);
                                                switch ((jj_ntk_Renamed_Field == - 1) ? jj_ntk() : jj_ntk_Renamed_Field)
                                                {
                                                    case CLIPSParserConstants_Fields.LBRACE:
                                                        ;
                                                        break;

                                                    default:
                                                        jj_la1[45] = jj_gen;
                                                        //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1012"'
                                                        goto label_23_brk;
                                                }
                                            }
                                            //UPGRADE_NOTE: Label 'label_23_brk' was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1011"'
                                            label_23_brk:
                                            ;

                                            break;

                                        default:
                                            jj_la1[46] = jj_gen;
                                            ;
                                            break;
                                    }
                                    oc = new ObjectCondition();
                                    oc.TemplateName = exp.image;
                                    itr = alpha.GetEnumerator();
                                    while (itr.MoveNext())
                                    {
                                        oc.addConstraint((IConstraint) itr.Current);
                                    }
                                    list.Add(oc);
                                    alpha.Clear();
                                    exp = null;
                                    break;

                                default:
                                    jj_la1[48] = jj_gen;
                                    jj_consume_token(- 1);
                                    throw new ParseException();
                            }
                        }
                        break;
                }
            }
        }
コード例 #4
0
        // CEType checks the Conditional element to see if it's exist, not, test or plain
        public void CEType(ArrayList list)
        {
            Token exp;
            Token exp2;
            Object etime;
            Object nested = null;
            ArrayList alpha = new ArrayList();
            ObjectCondition oc = null;
            TemporalCondition tmpc = null;
            ArrayList parms = new ArrayList();
            if (mcc_2_24(2147483647))
            {
                mcc_consume_token(NOTCE);
                mcc_consume_token(LBRACE);
                exp = mcc_consume_token(IDENTIFIER);
                switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                {
                    case LBRACE:
                        while (true)
                        {
                            templatePatterns(alpha);
                            switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                            {
                                case LBRACE:
                                    ;
                                    break;
                                default:
                                    mcc_la1[37] = mcc_gen;
                                    goto label_18;
                            }
                        }
                        label_18:
                        ;

                        break;
                    default:
                        mcc_la1[38] = mcc_gen;
                        ;
                        break;
                }
                mcc_consume_token(RBRACE);
                oc = new ObjectCondition();
                oc.Negated = true;
                oc.TemplateName = exp.image;
                IEnumerator itr = alpha.GetEnumerator();
                while (itr.MoveNext())
                {
                    oc.addConstraint((IConstraint) itr.Current);
                }
                list.Add(oc);
                alpha.Clear();
                exp = null;
            }
            else
            {
                switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                {
                    case NOTCE:
                        mcc_consume_token(NOTCE);
                        mcc_consume_token(LBRACE);
                        nested = expr();
                        mcc_consume_token(RBRACE);
                        TestCondition tc = new TestCondition();
                        tc.Negated = true;
                        if (nested is IFunction)
                        {
                            tc.Function = ((IFunction) nested);
                        }
                        list.Add(tc);
                        break;
                    case TEMPORAL:
                        mcc_consume_token(TEMPORAL);
                        temporalPattern(list);

                        break;
                    case TEST:
                        mcc_consume_token(TEST);
                        mcc_consume_token(LBRACE);
                        nested = expr();
                        mcc_consume_token(RBRACE);
                        tc = new TestCondition();
                        if (nested is IFunction)
                        {
                            tc.Function = ((IFunction) nested);
                        }
                        list.Add(tc);
                        break;
                    case AND1:
                        mcc_consume_token(AND1);
                        while (true)
                        {
                            mcc_consume_token(LBRACE);
                            nested = expr();
                            mcc_consume_token(RBRACE);
                            switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                            {
                                case LBRACE:
                                    ;
                                    break;
                                default:
                                    mcc_la1[39] = mcc_gen;
                                    goto label_19;
                            }
                        }
                        label_19:
                        ;

                        AndCondition ac = new AndCondition();
                        ac.addNestedConditionElement(nested);
                        list.Add(ac);
                        break;
                    case EXISTS:
                        mcc_consume_token(EXISTS);
                        while (true)
                        {
                            mcc_consume_token(LBRACE);
                            CEType(alpha);
                            mcc_consume_token(RBRACE);
                            switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                            {
                                case LBRACE:
                                    ;
                                    break;
                                default:
                                    mcc_la1[40] = mcc_gen;
                                    goto label_20;
                            }
                        }
                        label_20:
                        ;

                        ExistCondition exc = null;
                        if (alpha.Count > 1)
                        {
                            for (int iz = 0; iz < alpha.Count; iz++)
                            {
                                exc = ExistCondition.newExistCondition((ObjectCondition) alpha[iz]);
                                list.Add(exc);
                            }
                        }
                        else
                        {
                            exc = ExistCondition.newExistCondition((ObjectCondition) alpha[0]);
                            list.Add(exc);
                        }
                        break;
                    case IDENTIFIER:
                        exp = mcc_consume_token(IDENTIFIER);
                        switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                        {
                            case LBRACE:
                                while (true)
                                {
                                    templatePatterns(alpha);
                                    switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                                    {
                                        case LBRACE:
                                            ;
                                            break;
                                        default:
                                            mcc_la1[41] = mcc_gen;
                                            goto label_21;
                                    }
                                }
                                label_21:
                                ;

                                break;
                            default:
                                mcc_la1[42] = mcc_gen;
                                ;
                                break;
                        }
                        oc = new ObjectCondition();
                        oc.TemplateName = exp.image;
                        IEnumerator itr = alpha.GetEnumerator();
                        while (itr.MoveNext())
                        {
                            oc.addConstraint((IConstraint) itr.Current);
                        }
                        list.Add(oc);
                        alpha.Clear();
                        exp = null;
                        break;
                    default:
                        mcc_la1[43] = mcc_gen;
                        mcc_consume_token(-1);
                        throw new ParseException();
                }
            }
        }
コード例 #5
0
        public virtual int analyze(IRule rule)
        {
            int result = Analysis_Fields.VALIDATION_PASSED;

            error   = new ErrorSummary();
            warning = new WarningSummary();
            checkForModule(rule);
            ICondition[] cnds = rule.Conditions;
            for (int idx = 0; idx < cnds.Length; idx++)
            {
                ICondition cnd = cnds[idx];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc  = (ObjectCondition)cnd;
                    Deftemplate     dft = oc.Deftemplate;
                    if (dft != null)
                    {
                        IConstraint[] cntrs = oc.Constraints;
                        for (int idy = 0; idy < cntrs.Length; idy++)
                        {
                            IConstraint cons = cntrs[idy];
                            if (cons is LiteralConstraint)
                            {
                                Slot sl = dft.getSlot(cons.Name);
                                if (sl == null)
                                {
                                    error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist.");
                                    result = Analysis_Fields.VALIDATION_FAILED;
                                }
                            }
                            else if (cons is BoundConstraint)
                            {
                                BoundConstraint bc = (BoundConstraint)cons;
                                if (!bc.isObjectBinding)
                                {
                                    Slot sl = dft.getSlot(bc.Name);
                                    if (sl == null)
                                    {
                                        error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist.");
                                        result = Analysis_Fields.VALIDATION_FAILED;
                                    }
                                }
                            }
                            else if (cons is PredicateConstraint)
                            {
                                PredicateConstraint pc = (PredicateConstraint)cons;
                                IFunction           f  = engine.findFunction(pc.FunctionName);
                                if (f == null)
                                {
                                    addInvalidFunctionError(pc.FunctionName);
                                }
                            }
                        }
                    }
                    else
                    {
                        error.addMessage(INVALID_TEMPLATE + " " + oc.TemplateName + " template does not exist.");
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                }
                else if (cnd is TestCondition)
                {
                    TestCondition tc = (TestCondition)cnd;
                    if (tc.Function == null)
                    {
                        error.addMessage(NO_FUNCTION);
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                    else
                    {
                        IFunction f = tc.Function;
                        if (engine.findFunction(f.Name) == null)
                        {
                            addInvalidFunctionError(f.Name);
                            result = Analysis_Fields.VALIDATION_FAILED;
                        }
                    }
                }
                else if (cnd is ExistCondition)
                {
                }
            }
            // now we check the Right-hand side
            IAction[] acts = rule.Actions;
            for (int idx = 0; idx < acts.Length; idx++)
            {
                IAction act = acts[idx];
                if (act is FunctionAction)
                {
                    FunctionAction fa = (FunctionAction)act;
                    if (engine.findFunction(fa.FunctionName) == null)
                    {
                        addInvalidFunctionError(fa.FunctionName);
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                }
            }
            return(result);
        }