/** * visit. * * @param obj a {@link lupos.rif.model.Conjunction} 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(Conjunction 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; }
/** * 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; }
/** * 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()); } }