public DatalogDependencyGraphGenerator(DatalogProgram program) { this(program.getRules()); }
public int getUCQSizeAfterRewriting() { int result = 0; if( sizesCollected() ) result = this.programAfterRewriting.getRules().size(); return result; }
public static boolean isBoolean(DatalogProgram query) { for (CQIE rule : query.getRules()) { if (!isBoolean(rule)) return false; } return true; }
/** * @param program */ private void normalizeProgram(DatalogProgram program) { for (CQIE rule : program.getRules()) { normalizeRule(rule); } log.debug("Program normalized for SQL translation: \n"+program); }
public int getUCQSizeAfterUnfolding() { int result = 0; if( sizesCollected() ) result = programAfterUnfolding.getRules().size(); return result; }
public static boolean isBoolean(DatalogProgram query) { for (CQIE rule : query.getRules()) { if (!isBoolean(rule)) return false; } return true; }
/** * Transforms the given <code>DatalogProgram</code> into a string */ public static String encode(DatalogProgram input) { List<CQIE> list = input.getRules(); Iterator<CQIE> it =list.iterator(); StringBuilder sb = new StringBuilder(); while(it.hasNext()){ CQIE q = it.next(); if(sb.length()>0){ sb.append("\n"); } sb.append(q); } return sb.toString(); }
private Stream<CQIE> convertMappingQuery(IntermediateQuery mappingQuery) { ImmutableSet<CQIE> rules = unionSplitter.splitUnion(mappingQuery) .flatMap(q -> iq2DatalogTranslator.translate(q).getRules().stream()) .collect(ImmutableCollectors.toSet()); //CQIEs are mutable rules.forEach(DatalogNormalizer::unfoldJoinTrees); return rules.stream(); } }
private Stream<CQIE> convertMappingQuery(IQ mappingQuery) { return unionSplitter.splitUnion(unionNormalizer.optimize(mappingQuery)) .flatMap(q -> iq2DatalogTranslator.translate(q).getRules().stream()) .collect(ImmutableCollectors.toSet()) .stream(); } }
public int getMinQuerySizeAfterUnfolding() { int toReturn = Integer.MAX_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterUnfolding.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize < toReturn) { toReturn = querySize; } } } return (toReturn == Integer.MAX_VALUE) ? 0 : toReturn; }
public int getMaxQuerySizeAfterRewriting() { int toReturn = Integer.MIN_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterRewriting.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize > toReturn) { toReturn = querySize; } } } return toReturn; }
public int getMinQuerySizeAfterRewriting() { int toReturn = Integer.MAX_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterRewriting.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize < toReturn) { toReturn = querySize; } } } return toReturn; }
public int getMaxQuerySizeAfterUnfolding() { int toReturn = Integer.MIN_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterUnfolding.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize > toReturn) { toReturn = querySize; } } } return (toReturn == Integer.MIN_VALUE) ? 0 : toReturn; }
if (predicateIdx != 0 || !program.getRules().isEmpty()) throw new IllegalStateException("SparqlAlgebraToDatalogTranslator.translate can only be called once.");
private IQ preProcess(InternalSparqlQuery translation) throws OntopInvalidInputQueryException, EmptyQueryException { DatalogProgram program = translation.getProgram(); log.debug("Datalog program translated from the SPARQL query: \n{}", program); if(settings.isSameAsInMappingsEnabled()){ program = sameAsRewriter.getSameAsRewriting(program); log.debug("Datalog program after SameAs rewriting \n{}", program); } log.debug("Replacing equivalences..."); DatalogProgram newprogramEq = datalogFactory.getDatalogProgram(program.getQueryModifiers()); for (CQIE query : program.getRules()) { CQIE rule = query.clone(); // EQNormalizer cannot be removed because it is used in NULL propagation in OPTIONAL eqNormalizer.enforceEqualities(rule); newprogramEq.appendRule(rule); } if (newprogramEq.getRules().isEmpty()) throw new OntopInvalidInputQueryException("Error, the translation of the query generated 0 rules. " + "This is not possible for any SELECT query (other queries are not supported by the translator)."); return datalogConverter.convertDatalogProgram(newprogramEq, ImmutableList.of(), translation.getSignature()); }
@Override public DatalogProgram getSameAsRewriting(DatalogProgram pr) { if (targetPredicates == null) targetPredicates = SameAsTargets.extract(saturatedMapping); DatalogProgram result = datalogFactory.getDatalogProgram(pr.getQueryModifiers()); for (CQIE q: pr.getRules()) { List<Function> body = new ArrayList<>(q.getBody().size()); for (Function a : q.getBody()) { Function ap = addSameAs(a, result, "sameAs" + (rules++)); body.add(ap); } result.appendRule(datalogFactory.getCQIE(q.getHead(), body)); } return result; }
ImmutableList<Variable> signature) throws EmptyQueryException { List<CQIE> rules = queryProgram.getRules();
/** * Translate an intermediate query tree into a Datalog program. * * Each (strict) subquery will be translated as a rule with head Pred(var_1, .., var_n), * where the string for Pred is of the form SUBQUERY_PRED_PREFIX + y, * with y > subqueryCounter. */ @Override public DatalogProgram translate(IQ initialQuery) { IQ orderLiftedQuery = liftOrderBy(initialQuery); Optional<MutableQueryModifiers> optionalModifiers = extractTopQueryModifiers(orderLiftedQuery); // Mutable DatalogProgram dProgram; if (optionalModifiers.isPresent()){ MutableQueryModifiers mutableModifiers = optionalModifiers.get(); dProgram = datalogFactory.getDatalogProgram(mutableModifiers); } else { dProgram = datalogFactory.getDatalogProgram(); } normalizeIQ(orderLiftedQuery) .forEach(q -> translate(q, dProgram)); // CQIEs are mutable dProgram.getRules().forEach(q -> unfoldJoinTrees(q.getBody())); return dProgram; }
ExecutorRegistry executorRegistry) throws InvalidDatalogProgramException, EmptyQueryException { List<CQIE> rules = queryProgram.getRules();