예제 #1
0
 public List<VariableAssignment> traceAtomEvent(Atom atom) {
   Collection<Atom> atoms = dependence.get(atom.getPredicate());
   List<VariableAssignment> vars = new ArrayList<VariableAssignment>(atoms.size());
   for (Atom entry : atoms) {
     // Check whether arguments match
     VariableAssignment var = new VariableAssignment();
     Term[] argsGround = atom.getArguments();
     Term[] argsTemplate = entry.getArguments();
     assert argsGround.length == argsTemplate.length;
     for (int i = 0; i < argsGround.length; i++) {
       if (argsTemplate[i] instanceof Variable) {
         // Add mapping
         assert argsGround[i] instanceof GroundTerm;
         var.assign((Variable) argsTemplate[i], (GroundTerm) argsGround[i]);
       } else {
         // They must be the same
         if (!argsTemplate[i].equals(argsGround[i])) {
           var = null;
           break;
         }
       }
     }
     if (var != null) vars.add(var);
   }
   return vars;
 }
예제 #2
0
    public DNFClause(List<Atom> posLiterals, List<Atom> negLiterals) {
      this.posLiterals = new ArrayList<Atom>(posLiterals);
      this.negLiterals = new ArrayList<Atom>(negLiterals);
      dependence = ArrayListMultimap.create();
      Set<Variable> allowedVariables = new HashSet<Variable>();
      Set<Variable> variablesToCheck = new HashSet<Variable>();
      boolean tempAllVariablesBound = true;

      /*
       * Checks if all Variables in the clause appear in a positive literal
       * with a StandardPredicate.
       */
      Set<Variable> setToAdd;

      for (Atom atom : posLiterals) {
        if (atom.getPredicate() instanceof StandardPredicate) setToAdd = allowedVariables;
        else setToAdd = variablesToCheck;

        for (Term t : atom.getArguments()) {
          if (t instanceof Variable) setToAdd.add((Variable) t);
        }
      }

      for (Atom atom : negLiterals)
        for (Term t : atom.getArguments())
          if (t instanceof Variable) variablesToCheck.add((Variable) t);

      isGround = (allowedVariables.size() + variablesToCheck.size() == 0) ? true : false;

      for (Variable v : variablesToCheck)
        if (!allowedVariables.contains(v)) tempAllVariablesBound = false;

      allVariablesBound = tempAllVariablesBound;

      /*
       * Processes the positive literals with StandardPredicates further
       */
      for (int i = 0; i < posLiterals.size(); i++)
        if (posLiterals.get(i).getPredicate() instanceof StandardPredicate)
          dependence.put(posLiterals.get(i).getPredicate(), posLiterals.get(i));

      if (posLiterals.size() == 0) query = null;
      else if (posLiterals.size() == 1) query = (allVariablesBound) ? posLiterals.get(0) : null;
      else
        query =
            (allVariablesBound)
                ? new Conjunction(posLiterals.toArray(new Formula[posLiterals.size()]))
                : null;
    }