private int getBodySize(List<? extends Function> atoms) { int counter = 0; for (Function atom : atoms) { Predicate predicate = atom.getFunctionSymbol(); if (predicate instanceof AtomPredicate) { counter++; } } return counter; } };
private ImmutableList<QualifiedAttributeID> getGroupBy(List<Function> body, AliasIndex index) { return body.stream() .filter(a -> a.getFunctionSymbol().equals(datalogFactory.getSparqlGroupPredicate())) .map(Function::getVariables) .flatMap(Collection::stream) .map(index::getColumns) .flatMap(Collection::stream) .collect(ImmutableCollectors.toList()); }
private Optional<IRI> extractClassIRI(Function rdfDataAtom) { if (rdfDataAtom.getFunctionSymbol() instanceof RDFAtomPredicate) { RDFAtomPredicate rdfAtomPredicate = (RDFAtomPredicate) rdfDataAtom.getFunctionSymbol(); ImmutableList<ImmutableTerm> arguments = rdfDataAtom.getTerms().stream() .map(immutabilityTools::convertIntoImmutableTerm) .collect(ImmutableCollectors.toList()); return rdfAtomPredicate.getClassIRI(arguments); } return Optional.empty(); } }
private Optional<IRI> extractPropertyIRI(Function rdfDataAtom) { if (rdfDataAtom.getFunctionSymbol() instanceof RDFAtomPredicate) { RDFAtomPredicate rdfAtomPredicate = (RDFAtomPredicate) rdfDataAtom.getFunctionSymbol(); ImmutableList<ImmutableTerm> arguments = rdfDataAtom.getTerms().stream() .map(immutabilityTools::convertIntoImmutableTerm) .collect(ImmutableCollectors.toList()); return rdfAtomPredicate.getPropertyIRI(arguments); } return Optional.empty(); }
public Boolean isLeftJoinOrJoinAtom(Function atom) { Predicate predicate = atom.getFunctionSymbol(); return predicate.equals(datalogFactory.getSparqlLeftJoinPredicate()) || predicate.equals(datalogFactory.getSparqlJoinPredicate()); }
/** * This method takes a rule and populates the ruleIndex field. * @param rule */ private void updateRuleIndexes(CQIE rule) { Function head = rule.getHead(); ruleIndex.put(head.getFunctionSymbol(), rule); updateRuleIndexByBodyPredicate(rule); }
private ImmutableList<Function> getHaving(List<Function> body) { for (Function atom : body) { if (atom.getFunctionSymbol() == DatalogAlgebraOperatorPredicates.SPARQL_HAVING) { return convert(atom.getTerms()); } } return ImmutableList.of(); }
/** * This method takes a rule and populates the ruleIndex field. * @param rule */ private void updateRuleIndexes(CQIE rule) { Function head = rule.getHead(); ruleIndex.put(head.getFunctionSymbol(), rule); updateRuleIndexByBodyPredicate(rule); }
private ImmutableList<Function> getHaving(List<Function> body) { for (Function atom : body) { if (atom.getFunctionSymbol().equals(datalogFactory.getSparqlHavingPredicate())) { return convert(atom.getTerms()); } } return ImmutableList.of(); }
private Function negation(Function arg) { return (arg.getFunctionSymbol() == ExpressionOperation.NOT) ? (Function) arg.getTerm(0) : termFactory.getFunctionNOT(arg); }
@Override public Boolean f(Function atom) { return atom.isOperation() || TYPE_FACTORY.isBoolean(atom.getFunctionSymbol()); } };
private Function negation(Function arg) { return (arg.getFunctionSymbol() == ExpressionOperation.NOT) ? (Function) arg.getTerm(0) : TERM_FACTORY.getFunctionNOT(arg); }
private Term evalIfElseNull(Function term) { Term formerCondition = term.getTerm(0); Term newCondition = eval(formerCondition); if (newCondition.equals(formerCondition)) return term; else if (newCondition.equals(valueFalse)) return valueNull; else if (newCondition.equals(valueTrue)) return term.getTerm(1); else return termFactory.getFunction(term.getFunctionSymbol(), newCondition, term.getTerm(1)); }
private Term evalIsBlank(Function term) { Term teval = eval(term.getTerm(0)); if (teval instanceof Function) { Function function = (Function) teval; Predicate predicate = function.getFunctionSymbol(); return termFactory.getBooleanConstant(predicate instanceof BNodePredicate); } return term; }
private Term evalIsIri(Function term) { Term teval = eval(term.getTerm(0)); if (teval instanceof Function) { Function function = (Function) teval; Predicate predicate = function.getFunctionSymbol(); return termFactory.getBooleanConstant(predicate instanceof URITemplatePredicate); } return term; }
private Function getFreshAtom(Function a, String suffix) { List<Term> termscopy = new ArrayList<>(a.getArity()); for (Term t : a.getTerms()) { if (t instanceof Variable) { Variable v = (Variable)t; termscopy.add(termFactory.getVariable(v.getName() + suffix)); } else termscopy.add(t.clone()); } return termFactory.getFunction(a.getFunctionSymbol(), termscopy); }
private Term evalIsBlank(Function term) { Term teval = eval(term.getTerm(0)); if (teval instanceof Function) { Function function = (Function) teval; Predicate predicate = function.getFunctionSymbol(); return TERM_FACTORY.getBooleanConstant(predicate instanceof BNodePredicate); } return term; }
@Inject private DatalogTools(TermFactory termFactory, DatalogFactory datalogFactory) { this.termFactory = termFactory; this.datalogFactory = datalogFactory; ValueConstant valueTrue = termFactory.getBooleanConstant(true); TRUE_EQ = termFactory.getFunctionEQ(valueTrue, valueTrue); IS_DATA_OR_LJ_OR_JOIN_ATOM_FCT = this::isDataOrLeftJoinOrJoinAtom; IS_NOT_DATA_OR_COMPOSITE_ATOM_FCT = atom -> !isDataOrLeftJoinOrJoinAtom(atom); IS_BOOLEAN_ATOM_FCT = atom -> atom.isOperation() || isXsdBoolean(atom.getFunctionSymbol()); }
private Term evalIsNumeric(Function term) { Term innerTerm = term.getTerm(0); if (innerTerm instanceof Function) { Function function = (Function) innerTerm; return termFactory.getBooleanConstant(function.isDataTypeFunction() && isNumeric(function.getFunctionSymbol())); } else { return term; } }
public void insertDataTyping(CQIE rule) throws UnknownDatatypeException { Function atom = rule.getHead(); Predicate predicate = atom.getFunctionSymbol(); if (predicate.getArity() == 2) { // we check both for data and object property Term term = atom.getTerm(1); // the second argument only Map<String, List<IndexedPosition>> termOccurenceIndex = createIndex(rule.getBody()); // Infer variable datatypes insertVariableDataTyping(term, atom, 1, termOccurenceIndex); // Infer operation datatypes from variable datatypes insertOperationDatatyping(term, atom, 1); } }