/**
  * visit.
  *
  * @param obj a {@link lupos.rif.model.Disjunction} object.
  * @param arg a {@link lupos.rif.IRuleNode} object.
  * @return a {@link lupos.rif.IRuleNode} object.
  * @throws lupos.rif.RIFException if any.
  */
 public IRuleNode visit(Disjunction obj, IRuleNode arg) throws RIFException {
   obj.setParent(arg);
   List<IExpression> items = new ArrayList<IExpression>(obj.exprs);
   obj.exprs.clear();
   for (IExpression expr : items) obj.addExpr((IExpression) expr.accept(this, obj));
   return obj;
 }
예제 #2
0
 @Override
 public boolean equals(Object obj) {
   if (obj != null && obj instanceof Equality) {
     final Equality eq = (Equality) obj;
     return leftExpr.equals(eq.leftExpr) && rightExpr.equals(eq.rightExpr);
   } else return false;
 }
 /**
  * visit.
  *
  * @param obj a {@link lupos.rif.model.RuleList} object.
  * @param arg a {@link lupos.rif.IRuleNode} object.
  * @return a {@link lupos.rif.IRuleNode} object.
  * @throws lupos.rif.RIFException if any.
  */
 public IRuleNode visit(RuleList obj, IRuleNode arg) throws RIFException {
   try {
     // Wenn Liste leer
     if (obj.getItems().isEmpty()) {
       return new Constant(
           LiteralFactory.createURILiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>"),
           arg);
     }
     Conjunction conjunction = new Conjunction();
     conjunction.setParent(arg);
     int iteration = 0;
     // Listenidentifikator erstellen
     String baseName = aliasString + "list" + listCtr++ + "it";
     conjunction.addExpr(new RuleVariable(baseName + iteration));
     int ctr = obj.getItems().size();
     for (IExpression expr : obj.getItems()) {
       ctr--;
       IRuleNode result = expr.accept(this, conjunction);
       final String itVar = baseName + iteration++;
       if (result instanceof Conjunction) {
         for (IExpression item : new ArrayList<IExpression>(((Conjunction) result).exprs))
           if (item instanceof RulePredicate) conjunction.addExpr(item);
           else if (item instanceof RuleVariable) result = item;
       }
       final RulePredicate item =
           new RulePredicate(
               new RuleVariable(itVar),
               new Constant(
                   LiteralFactory.createURILiteral(
                       "<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>"),
                   arg),
               (IExpression) result);
       conjunction.addExpr(item);
       final RulePredicate next =
           new RulePredicate(
               new RuleVariable(itVar),
               new Constant(
                   LiteralFactory.createURILiteral(
                       "<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>"),
                   arg),
               ctr == 0
                   ? new Constant(
                       LiteralFactory.createURILiteral(
                           "<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>"),
                       arg)
                   : new RuleVariable(baseName + iteration));
       conjunction.addExpr(next);
       currentVariableScope.addVariable(new RuleVariable(itVar));
     }
     return conjunction;
   } catch (URISyntaxException e) {
     throw new RIFException(e.getMessage());
   }
 }
 /**
  * visit.
  *
  * @param obj a {@link lupos.rif.model.Rule} object.
  * @param arg a {@link lupos.rif.IRuleNode} object.
  * @return a {@link lupos.rif.IRuleNode} object.
  * @throws lupos.rif.RIFException if any.
  */
 public IRuleNode visit(Rule obj, IRuleNode arg) throws RIFException {
   listCtr = 0;
   obj.setParent(arg);
   currentVariableScope = obj;
   obj.setBody((IExpression) obj.getBody().accept(this, obj));
   List<IExpression> listOfNots = new ArrayList<IExpression>(obj.getNots().size());
   for (IExpression iExpression : obj.getNots()) {
     listOfNots.add((IExpression) iExpression.accept(this, obj));
   }
   obj.setNots(listOfNots);
   currentVariableScope = null;
   return obj;
 }
예제 #5
0
 public Object evaluate(
     Bindings binding, Object result, Multimap<IExpression, IExpression> equalities) {
   // Mehrere M�glichkeiten die auftreten k�nnen
   boolean leftHasUnbound = false;
   boolean rightHasUnbound = false;
   boolean leftAssign = false;
   boolean rightAssign = false;
   Set<Variable> bindingVars = binding.getVariableSet();
   for (RuleVariable var : leftExpr.getVariables())
     if (!bindingVars.contains(var.getVariable())) {
       leftHasUnbound = true;
       // Linke ungebunden, muss allein stehen
       if (leftExpr instanceof RuleVariable) leftAssign = true;
     }
   for (RuleVariable var : rightExpr.getVariables())
     if (!bindingVars.contains(var.getVariable())) {
       rightHasUnbound = true;
       // Linke ungebunden, muss allein stehen
       if (rightExpr instanceof RuleVariable) rightAssign = true;
     }
   if (rightAssign && leftAssign)
     throw new RIFException("All Variables in Assignment " + toString() + " are unbound!");
   if (rightAssign ^ leftAssign) {
     // Einzelne ungebundene variable auf einer seite, dann einfach die
     // andere auswerten und ergebniss reinschreiben
     Literal assignValue =
         (Literal) (leftAssign ? rightExpr.evaluate(binding) : leftExpr.evaluate(binding));
     RuleVariable var = (RuleVariable) (leftAssign ? leftExpr : rightExpr);
     binding.add(var.getVariable(), assignValue);
     return BooleanLiteral.TRUE;
   } else {
     // fester wert auf jeder seite, also erst aussage mit gebundenen
     // variable auswerten und anderem als result mitgeben.
     Item left = null;
     Item right = null;
     if (rightHasUnbound) {
       left = (Item) leftExpr.evaluate(binding);
       right = (Item) rightExpr.evaluate(binding, left);
     } else if (leftHasUnbound) {
       right = (Item) rightExpr.evaluate(binding);
       left = (Item) leftExpr.evaluate(binding, right);
     } else {
       left = (Item) leftExpr.evaluate(binding);
       right = (Item) rightExpr.evaluate(binding);
     }
     return BooleanLiteral.create(left.equals(right));
   }
 }
 /**
  * visit.
  *
  * @param obj a {@link lupos.rif.model.RulePredicate} object.
  * @param arg a {@link lupos.rif.IRuleNode} object.
  * @return a {@link lupos.rif.IRuleNode} object.
  * @throws lupos.rif.RIFException if any.
  */
 public IRuleNode visit(RulePredicate obj, IRuleNode arg) throws RIFException {
   obj.setParent(arg);
   Conjunction conjunction = null;
   List<IExpression> items = new ArrayList<IExpression>(obj.termParams);
   obj.termParams.clear();
   for (IExpression expr : items) {
     final IRuleNode result = expr.accept(this, obj);
     if (result instanceof Conjunction) {
       conjunction = conjunction == null ? new Conjunction() : conjunction;
       for (IExpression item : ((Conjunction) result).exprs)
         if (item instanceof RulePredicate) conjunction.addExpr(item);
         else if (item instanceof RuleVariable) obj.termParams.add(item);
     } else obj.termParams.add((IExpression) result);
   }
   if (conjunction != null) conjunction.addExpr(obj);
   return conjunction == null ? obj : conjunction;
 }
예제 #7
0
 public boolean isBound(RuleVariable var, Collection<RuleVariable> boundVars) {
   if (leftExpr.equals(var) && !boundVars.contains(var)) {
     if (rightExpr instanceof RuleVariable) if (!boundVars.contains(rightExpr)) return false;
     boundVars.add(var);
     return true;
   }
   if (rightExpr.equals(var) && !boundVars.contains(var)) {
     if (leftExpr instanceof RuleVariable) if (!boundVars.contains(leftExpr)) return false;
     boundVars.add(var);
     return true;
   }
   // TODO:Testen ob ?var = External() muster vorhanden ist, ?x gebunden
   // ist und External die gesuchte Variable enth�lt, die restlichen aber
   // gebunden sind, dann gebunden.
   if (leftExpr instanceof RuleVariable
       && boundVars.contains(leftExpr)
       && rightExpr instanceof External) {
     Set<RuleVariable> extVars = rightExpr.getVariables();
     boolean found = false;
     boolean bound = true;
     for (final RuleVariable ruleVar : extVars)
       if (ruleVar.equals(var)) found = true;
       else if (!boundVars.contains(ruleVar)) bound = false;
     if (found && bound && rightExpr.isBound(var, boundVars)) {
       return true;
     }
   }
   if (rightExpr instanceof RuleVariable
       && boundVars.contains(rightExpr)
       && leftExpr instanceof External) {
     Set<RuleVariable> extVars = leftExpr.getVariables();
     boolean found = false;
     boolean bound = true;
     for (final RuleVariable ruleVar : extVars)
       if (ruleVar.equals(var)) found = true;
       else if (!boundVars.contains(ruleVar)) bound = false;
     if (found && bound && leftExpr.isBound(var, boundVars)) {
       return true;
     }
   }
   return false;
 }
예제 #8
0
 public List<Uniterm> getPredicates() {
   List<Uniterm> terms = new ArrayList<Uniterm>();
   terms.addAll(rightExpr.getPredicates());
   terms.addAll(leftExpr.getPredicates());
   return terms;
 }
예제 #9
0
 public Set<RuleVariable> getVariables() {
   Set<RuleVariable> variables = new HashSet<RuleVariable>();
   variables.addAll(rightExpr.getVariables());
   variables.addAll(leftExpr.getVariables());
   return variables;
 }
예제 #10
0
 public boolean containsOnlyVariables() {
   return rightExpr.containsOnlyVariables() && leftExpr.containsOnlyVariables();
 }
예제 #11
0
 public String getLabel() {
   return leftExpr.toString() + " = " + rightExpr.toString();
 }
예제 #12
0
 public String toString(Prefix prefixInstance) {
   return leftExpr.toString(prefixInstance) + " = " + rightExpr.toString(prefixInstance);
 }