예제 #1
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /**
   * @param tier the index of the desired tier.
   * @return a copy of this tier.
   */
  public final List<String> getTier(int tier) {
    ensureTiers(tier);

    List<String> names = new ArrayList<>();
    for (MyNode MyNode : tierSpecs.get(tier)) names.add(MyNode.getName());

    return names;
  }
예제 #2
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** @return the list of edges not in any tier. */
  public final List<String> getVariablesNotInTiers() {
    List<MyNode> notInTier = new ArrayList<>(myNodes);

    for (Set<MyNode> tier : tierSpecs) {
      if (tier == null) tier = new HashSet<>();
      notInTier.removeAll(tier);
    }

    List<String> names = new ArrayList<>();
    for (MyNode MyNode : notInTier) names.add(MyNode.getName());

    return names;
  }
예제 #3
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** Iterator over the KnowledgeEdge's representing required edges. */
  public final Iterator<KnowledgeEdge> requiredEdgesIterator() {
    Set<KnowledgeEdge> edges = new HashSet<>();

    for (OrderedPair<Set<MyNode>> o : requiredRulesSpecs) {
      final Set<MyNode> first = o.getFirst();
      for (MyNode s1 : first) {
        final Set<MyNode> second = o.getSecond();
        for (MyNode s2 : second) {
          if (!s1.equals(s2)) {
            edges.add(new KnowledgeEdge(s1.getName(), s2.getName()));
          }
        }
      }
    }

    return edges.iterator();
  }
예제 #4
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  private Set<MyNode> getExtent(String spec) {
    Set<String> split = split(spec);
    Set<MyNode> matches = new HashSet<>();

    for (String _spec : split) {
      _spec = _spec.replace("*", ".*");

      java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(_spec);

      for (MyNode var : myNodes) {
        Matcher matcher = pattern.matcher(var.getName());
        if (matcher.matches()) {
          matches.add(var);
        }
      }
    }

    return matches;
  }
예제 #5
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /**
   * Adds the given variable or wildcard pattern to the given tier. The tier is a non-negative
   * integer.
   */
  public final void addToTier(int tier, String spec) {
    if (tier < 0) {
      throw new IllegalArgumentException();
    }

    if (spec == null) {
      throw new NullPointerException();
    }

    spec = checkSpec(spec);
    final Set<MyNode> vars = getExtent(spec);

    ensureTiers(tier);

    for (MyNode s : vars) {
      if (checkVarName(s.getName())) {
        addVariable(s.getName());
        tierSpecs.get(tier).add(s);
      }
    }
  }
예제 #6
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** Marks the edge var1 --> var2 as required. */
  public final void setRequired(String spec1, String spec2) {
    addVariable(spec1);
    addVariable(spec2);

    spec1 = checkSpec(spec1);
    spec2 = checkSpec(spec2);

    Set<MyNode> f1 = getExtent(spec1);
    Set<MyNode> f2 = getExtent(spec2);

    for (MyNode s : f1) {
      if (checkVarName(s.getName())) {
        addVariable(s.getName());
      }
    }

    for (MyNode s : f2) {
      if (checkVarName(s.getName())) {
        addVariable(s.getName());
      }
    }

    OrderedPair<Set<MyNode>> o = new OrderedPair<>(f1, f2);

    requiredRulesSpecs.add(o);
  }
예제 #7
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** Iterator over the knowledge's explicitly forbidden edges. */
  public final Iterator<KnowledgeEdge> explicitlyForbiddenEdgesIterator() {
    Set<OrderedPair<Set<MyNode>>> copy = new HashSet<>(forbiddenRulesSpecs);
    copy.removeAll(forbiddenTierRules());

    for (KnowledgeGroup group : knowledgeGroups) {
      copy.remove(knowledgeGroupRules.get(group));
    }

    Set<KnowledgeEdge> edges = new HashSet<>();

    for (OrderedPair<Set<MyNode>> o : copy) {
      final Set<MyNode> first = o.getFirst();
      for (MyNode s1 : first) {
        final Set<MyNode> second = o.getSecond();
        for (MyNode s2 : second) {
          edges.add(new KnowledgeEdge(s1.getName(), s2.getName()));
        }
      }
    }

    return edges.iterator();
  }
예제 #8
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
 /** @return a copy of the list of variable, in alphabetical order. */
 public List<String> getVariables() {
   List<String> names = new ArrayList<>();
   for (MyNode MyNode : myNodes) names.add(MyNode.getName());
   return new ArrayList<>(names);
 }