Examples of RuleBlock


Examples of com.github.jknack.antlr4ide.lang.RuleBlock

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    ActionElement actionElement = createMock(ActionElement.class);

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(localsBody);

    ruleBodyList.add(actionElement);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(actionElement.getBody()).andReturn("{$ctx.tree;}");

    rules.add(rule1);
View Full Code Here

Examples of com.github.jknack.antlr4ide.lang.RuleBlock

  private RuleBlock literal(final String literal) {
    Terminal terminal = createMock(Terminal.class);
    expect(terminal.getLiteral()).andReturn(literal);

    EList<EObject> body = new BasicEList<EObject>();
    RuleBlock block = createMock(RuleBlock.class);

    body.add(terminal);

    expect(block.eAllContents()).andReturn(newTreeIterator(body));

    replay(terminal, block);

    return block;
  }
View Full Code Here

Examples of com.github.jknack.antlr4ide.lang.RuleBlock

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    RuleRef ruleRef = createMock(RuleRef.class);
    ParserRule expr = createMock(ParserRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(null);

    ruleBodyList.add(ruleRef);
    ruleBodyList.add(actionElement);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(ruleRef.getReference()).andReturn(expr);

    expect(expr.getName()).andReturn("expr");
View Full Code Here

Examples of com.github.jknack.antlr4ide.lang.RuleBlock

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    ActionElement actionElement = createMock(ActionElement.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(null);

    ruleBodyList.add(actionElement);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(actionElement.getBody()).andReturn("{int v = $expr.v;}");

    PowerMock.expectPrivate(validator, "error", "unknown attribute reference 'expr' in '$expr'",
        actionElement, 9, 5);
View Full Code Here

Examples of com.github.jknack.antlr4ide.lang.RuleBlock

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    LabeledElement labeledElement = createMock(LabeledElement.class);
    Terminal terminal = createMock(Terminal.class);
    LexerRule ID = createMock(LexerRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    ActionOption actionOption = createMock(ActionOption.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(args);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(returnBody);

    expect(locals.getBody()).andReturn(localsBody);

    ruleBodyList.add(labeledElement);
    ruleBodyList.add(terminal);
    ruleBodyList.add(actionElement);
    ruleBodyList.add(actionOption);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(terminal.getReference()).andReturn(ID);

    expect(labeledElement.getName()).andReturn("var");
View Full Code Here

Examples of com.github.jknack.antlr4ide.lang.RuleBlock

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    LabeledElement labeledElement = createMock(LabeledElement.class);
    Terminal terminal = createMock(Terminal.class);
    LexerRule ID = createMock(LexerRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    ActionOption actionOption = createMock(ActionOption.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(args);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(returnBody);

    expect(locals.getBody()).andReturn(localsBody);

    ruleBodyList.add(labeledElement);
    ruleBodyList.add(terminal);
    ruleBodyList.add(actionElement);
    ruleBodyList.add(actionOption);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(terminal.getReference()).andReturn(ID);

    expect(labeledElement.getName()).andReturn("var");
View Full Code Here

Examples of net.sourceforge.jFuzzyLogic.rule.RuleBlock

    //    RULEBLOCK No1
    //       ACCU : MAX;
    //       AND : MIN;
    //       ACT : MIN;
    RuleBlock ruleBlock = new RuleBlock(functionBlock);
    ruleBlock.setName("No1");
    ruleBlock.setRuleAccumulationMethod(new RuleAccumulationMethodMax());
    ruleBlock.setRuleActivationMethod(new RuleActivationMethodMin());

    //       RULE 1 : IF service IS poor OR food is rancid THEN tip IS cheap;
    Rule rule1 = new Rule("Rule1", ruleBlock);
    rule1.addAntecedent(service, "poor", false);
    rule1.addAntecedent(food, "rancid", false);
    rule1.addConsequent(tip, "cheap", false);
    ruleBlock.add(rule1);

    //       RULE 2 : IF service IS good THEN tip IS average;
    Rule rule2 = new Rule("Rule2", ruleBlock);
    rule2.addAntecedent(service, "good", false);
    rule2.addConsequent(tip, "average", false);
    ruleBlock.add(rule2);

    //       RULE 3 : IF ((service IS good) OR (service IS excellent)) AND food IS delicious THEN tip is generous;
    Rule rule3 = new Rule("Rule3", ruleBlock);
    RuleTerm term1 = new RuleTerm(service, "good", false); // Create 'terms'
    RuleTerm term2 = new RuleTerm(service, "excellent", false);
    RuleTerm term3 = new RuleTerm(food, "delicious", false);

    RuleExpression antecedentOr = new RuleExpression(term1, term2, new RuleConnectionMethodOrMax()); // Combine terms using connection methods: OR, AND
    RuleExpression antecedentAnd = new RuleExpression(antecedentOr, term3, new RuleConnectionMethodAndMin());
    rule3.setAntecedents(antecedentAnd); // Set antecedent

    rule3.addConsequent(tip, "generous", false);
    ruleBlock.add(rule3);

    //    END_RULEBLOCK
    //
    //    END_FUNCTION_BLOCK
    HashMap<String, RuleBlock> ruleBlocksMap = new HashMap<String, RuleBlock>();
    ruleBlocksMap.put(ruleBlock.getName(), ruleBlock);
    functionBlock.setRuleBlocks(ruleBlocksMap);

    //---
    // Show generated FIS (FCL) and show animation
    //---
View Full Code Here

Examples of net.sourceforge.jFuzzyLogic.rule.RuleBlock

    // Load FIS (Fuzzy Inference System)
    //---
    FIS fis = FIS.load("fcl/qualify.fcl");
    FunctionBlock functionBlock = fis.getFunctionBlock(null);
    // functionBlock.chart();
    RuleBlock ruleBlock = functionBlock.getFuzzyRuleBlock(null);

    //---
    // Create a list of parameter to optimize
    //---
    ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
    // Add variables.
    // Note: Fuzzy sets' parameters for these (scoring and credLimMul) variables will be optimized
    Parameter.parameterListAddVariable(parameterList, ruleBlock.getVariable("scoring"));
    Parameter.parameterListAddVariable(parameterList, ruleBlock.getVariable("credLimMul"));

    // Add every rule's weight
    for( Rule rule : ruleBlock.getRules() ) {
      Parameter.parameterListAddRule(parameterList, rule);
    }

    //---
    // Create an error function to be optimized (i.e. minimized)
View Full Code Here

Examples of net.sourceforge.jFuzzyLogic.rule.RuleBlock

    fb.setVariable("out", v_out);

    v_out.add(t1);
    v_out.add(t2);

    RuleBlock rules = new RuleBlock(fb);
    rules.setName("No1");

    Rule r = new Rule("Rule1", rules);

    r.addAntecedent(v, "lt1", false);
    r.addConsequent(v_out, "lt2", false);

    rules.add(r);

    HashMap<String, RuleBlock> ruleBlocksMap = new HashMap<String, RuleBlock>();

    ruleBlocksMap.put(rules.getName(), rules);

    fb.setRuleBlocks(ruleBlocksMap);

    // Print, save and load
    System.out.println(fb.toString());
View Full Code Here

Examples of net.sourceforge.jFuzzyLogic.rule.RuleBlock

      else if( leaveName.equalsIgnoreCase("VAR_OUTPUT") ) fclTreeVariables(child);
      else if( leaveName.equalsIgnoreCase("FUZZIFY") ) fclTreeFuzzify(child);
      else if( leaveName.equalsIgnoreCase("DEFUZZIFY") ) fclTreeDefuzzify(child);
      else if( leaveName.equalsIgnoreCase("RULEBLOCK") ) {
        // Create and parse RuleBlock
        RuleBlock ruleBlock = new RuleBlock(this);
        String rbname = ruleBlock.fclTree(child);

        if( rbname.equals("") ) rbname = "RuleBlock_" + ruleBlockCount; // Create name if none is given
        ruleBlockCount++;

        // Add RuleBlock
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.