コード例 #1
0
ファイル: Rule.java プロジェクト: codeaudit/opendial
  /**
   * Returns the first rule output whose condition matches the input assignment provided as
   * argument. The output contains the grounded list of effects associated with the satisfied
   * condition.
   *
   * @param input the input assignment
   * @return the matched rule output.
   */
  public RuleOutput getOutput(Assignment input) {

    RuleOutput output = new RuleOutput(ruleType);
    RuleGrounding groundings = getGroundings(input);
    for (Assignment g : groundings.getAlternatives()) {

      Assignment full = !(g.isEmpty()) ? new Assignment(input, g) : input;

      RuleOutput match =
          cases
              .stream()
              .filter(c -> c.condition.isSatisfiedBy(full))
              .map(c -> c.output)
              .findFirst()
              .orElse(new RuleOutput(ruleType));

      match = match.ground(full);
      output.addOutput(match);
    }

    return output;
  }