Пример #1
0
  /**
   * Adds a knowledge group. Legacy method, replaced by setForbidden, setRequired with patterns.
   * Needed for the interface.
   */
  public void addKnowledgeGroup(KnowledgeGroup group) {
    this.knowledgeGroups.add(group);

    OrderedPair<Set<MyNode>> o = getGroupRule(group);
    knowledgeGroupRules.put(group, o);

    if (group.getType() == KnowledgeGroup.FORBIDDEN) {
      forbiddenRulesSpecs.add(o);
    } else if (group.getType() == KnowledgeGroup.REQUIRED) {
      requiredRulesSpecs.add(o);
    }
  }
Пример #2
0
 private OrderedPair<Set<MyNode>> getGroupRule(KnowledgeGroup group) {
   Set<String> from = group.getFromVariables();
   Set<String> to = group.getToVariables();
   Set<MyNode> fromExtent = new HashSet<>();
   Set<MyNode> toExtent = new HashSet<>();
   for (String s : from) {
     fromExtent.addAll(getExtent(s));
   }
   for (String s : to) {
     toExtent.addAll(getExtent(s));
   }
   return new OrderedPair<>(fromExtent, toExtent);
 }
Пример #3
0
  /** Legacy, do not use. */
  public void setKnowledgeGroup(int index, KnowledgeGroup group) {
    OrderedPair<Set<MyNode>> o = getGroupRule(group);
    OrderedPair<Set<MyNode>> old = knowledgeGroupRules.get(knowledgeGroups.get(index));

    forbiddenRulesSpecs.remove(old);
    requiredRulesSpecs.remove(old);

    if (group.getType() == KnowledgeGroup.FORBIDDEN) {
      forbiddenRulesSpecs.add(o);
    } else if (group.getType() == KnowledgeGroup.REQUIRED) {
      requiredRulesSpecs.add(o);
    }

    knowledgeGroups.set(index, group);
  }
Пример #4
0
  /** Legacy. */
  public final boolean isForbiddenByGroups(String var1, String var2) {
    Set<OrderedPair<Set<MyNode>>> s = new HashSet<>();

    for (KnowledgeGroup group : knowledgeGroups) {
      if (group.getType() == KnowledgeGroup.FORBIDDEN) {
        OrderedPair<Set<MyNode>> o = getGroupRule(group);
        s.add(o);
      }
    }

    for (OrderedPair<Set<MyNode>> rule : s) {
      if (rule.getFirst().contains(namesToVars.get(var1))) {
        if (rule.getSecond().contains(namesToVars.get(var2))) {
          return true;
        }
      }
    }

    return false;
  }
Пример #5
0
  /** Legacy. */
  public final boolean isRequiredByGroups(String var1, String var2) {
    Set<OrderedPair<Set<MyNode>>> s = new HashSet<>();

    for (KnowledgeGroup group : knowledgeGroups) {
      if (group.getType() == KnowledgeGroup.REQUIRED) {
        OrderedPair<Set<MyNode>> o = getGroupRule(group);
        s.add(o);
      }
    }

    for (OrderedPair<Set<MyNode>> rule : s) {
      if (rule.getFirst().contains(getVar(var1))) {
        if (rule.getSecond().contains(getVar(var2))) {
          return true;
        }
      }
    }

    return false;
  }