public static CQIE rule(Function head, List<Function> body){ return DATALOG_FACTORY.getCQIE(head, body); }
public static CQIE rule(Function head, Function... body){ return DATALOG_FACTORY.getCQIE(head, body); }
private void appendRule(Function head, List<Function> body) { CQIE rule = datalogFactory.getCQIE(head, body); program.appendRule(rule); }
public void addRule(Function head, Function body) { CQIE rule = DATALOG_FACTORY.getCQIE(head, body); List<CQIE> list = rules.get(body.getFunctionSymbol()); if (list == null) { list = new LinkedList<>(); rules.put(body.getFunctionSymbol(), list); } list.add(rule); }
TMappingRule(Function head, TMappingRule baseRule) { this.filterAtoms = new ArrayList<>(baseRule.filterAtoms.size()); for (List<Function> baseList: baseRule.filterAtoms) filterAtoms.add(cloneList(baseList)); this.databaseAtoms = cloneList(baseRule.databaseAtoms); this.head = (Function)head.clone(); this.stripped = DATALOG_FACTORY.getCQIE(head, databaseAtoms); this.cqc = baseRule.cqc; }
TMappingRule(TMappingRule baseRule, List<List<Function>> filterAtoms) { this.databaseAtoms = cloneList(baseRule.databaseAtoms); this.head = (Function)baseRule.head.clone(); this.filterAtoms = filterAtoms; this.stripped = DATALOG_FACTORY.getCQIE(head, databaseAtoms); this.cqc = baseRule.cqc; }
TMappingRule(Function head, TMappingRule baseRule, DatalogFactory datalogFactory, TermFactory termFactory, EQNormalizer eqNormalizer, boolean isClass) { this.filterAtoms = new ArrayList<>(baseRule.filterAtoms.size()); this.datalogFactory = datalogFactory; this.termFactory = termFactory; this.eqNormalizer = eqNormalizer; this.isClass = isClass; for (List<Function> baseList: baseRule.filterAtoms) filterAtoms.add(cloneList(baseList)); this.databaseAtoms = cloneList(baseRule.databaseAtoms); this.head = (Function)head.clone(); this.stripped = this.datalogFactory.getCQIE(head, databaseAtoms); this.cqc = baseRule.cqc; }
public CQIE asCQIE() { List<Function> combinedBody; if (!filterAtoms.isEmpty()) { combinedBody = new ArrayList<>(databaseAtoms.size() + filterAtoms.size()); combinedBody.addAll(databaseAtoms); Iterator<List<Function>> iterOR = filterAtoms.iterator(); List<Function> list = iterOR.next(); // IMPORTANT: assume that conditions is non-empty Function mergedConditions = getMergedByAND(list); while (iterOR.hasNext()) { list = iterOR.next(); Function e = getMergedByAND(list); mergedConditions = termFactory.getFunctionOR(e, mergedConditions); } combinedBody.add(mergedConditions); } else combinedBody = databaseAtoms; CQIE cq = datalogFactory.getCQIE(head, combinedBody); eqNormalizer.enforceEqualities(cq); return cq; }
public CQIE asCQIE() { List<Function> combinedBody; if (!filterAtoms.isEmpty()) { combinedBody = new ArrayList<>(databaseAtoms.size() + filterAtoms.size()); combinedBody.addAll(databaseAtoms); Iterator<List<Function>> iterOR = filterAtoms.iterator(); List<Function> list = iterOR.next(); // IMPORTANT: assume that conditions is non-empty Function mergedConditions = getMergedByAND(list); while (iterOR.hasNext()) { list = iterOR.next(); Function e = getMergedByAND(list); mergedConditions = TERM_FACTORY.getFunctionOR(e, mergedConditions); } combinedBody.add(mergedConditions); } else combinedBody = databaseAtoms; CQIE cq = DATALOG_FACTORY.getCQIE(head, combinedBody); EQNormalizer.enforceEqualities(cq); return cq; }
private CQIE createRule(DatalogProgram pr, String headName, List<Term> headParameters, Function... body) { Predicate pred = datalogFactory.getSubqueryPredicate(headName, headParameters.size()); Function head = termFactory.getFunction(pred, headParameters); CQIE rule = datalogFactory.getCQIE(head, body); pr.appendRule(rule); return rule; }
@Override public void visit(SWRLRule node) { head=null; body= new LinkedList<Function>(); for(SWRLAtom a: node.getHead()) { //transform SWRL head in Function getHead(a); //transform SWRL body in list Function getBody(node.getBody()); facts.add(datalogFactory.getCQIE(head, body)); } }
private boolean checkRedundant(CQIE db, Set<Term> groundTerms, Function atomToBeRemoved) { List<Function> atomsToLeave = new ArrayList<>(db.getBody().size() - 1); Set<Term> variablesInAtomsToLeave = new HashSet<>(); for (Function a: db.getBody()) if (a != atomToBeRemoved) { atomsToLeave.add(a); collectVariables(variablesInAtomsToLeave, a); } if (!variablesInAtomsToLeave.containsAll(groundTerms)) { return false; } CQIE q0 = datalogFactory.getCQIE(db.getHead(), atomsToLeave); // if db is homomorphically embeddable into q0 if (computeHomomorphsim(q0, db) != null) { oneAtomQs++; return true; } return false; }
private boolean checkRedundant(CQIE db, Set<Term> groundTerms, Function atomToBeRemoved) { List<Function> atomsToLeave = new ArrayList<>(db.getBody().size() - 1); Set<Term> variablesInAtomsToLeave = new HashSet<>(); for (Function a: db.getBody()) if (a != atomToBeRemoved) { atomsToLeave.add(a); collectVariables(variablesInAtomsToLeave, a); } if (!variablesInAtomsToLeave.containsAll(groundTerms)) { return false; } CQIE q0 = DATALOG_FACTORY.getCQIE(db.getHead(), atomsToLeave); // if db is homomorphically embeddable into q0 if (computeHomomorphsim(q0, db) != null) { oneAtomQs++; return true; } return false; }
TMappingRule(TMappingRule baseRule, List<List<Function>> filterAtoms, DatalogFactory datalogFactory, TermFactory termFactory, EQNormalizer eqNormalizer) { this.databaseAtoms = cloneList(baseRule.databaseAtoms); this.head = (Function)baseRule.head.clone(); this.filterAtoms = filterAtoms; this.datalogFactory = datalogFactory; this.termFactory = termFactory; this.eqNormalizer = eqNormalizer; this.isClass = baseRule.isClass(); this.stripped = this.datalogFactory.getCQIE(head, databaseAtoms); this.cqc = baseRule.cqc; }
/** * add the inverse of the same as present in the mapping */ public static ImmutableList<CQIE> addSameAsInverse(ImmutableList<CQIE> mappingRules) { Stream<CQIE> newRuleStream = mappingRules.stream() // the targets are already split. We have only one target atom .filter(r -> r.getHead().getFunctionSymbol().getName().equals(IriConstants.SAME_AS)) .map(r -> { Function head = r.getHead(); Function inversedHead = TERM_FACTORY.getFunction(head.getFunctionSymbol(), head.getTerm(1), head.getTerm(0)); return DATALOG_FACTORY.getCQIE(inversedHead, new ArrayList<>(r.getBody())); }); return Stream.concat(mappingRules.stream(), newRuleStream) .collect(ImmutableCollectors.toList()); } }
CQIE db = datalogFactory.getCQIE(query.getHead(), databaseAtoms);
CQIE db = DATALOG_FACTORY.getCQIE(query.getHead(), databaseAtoms);
@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; }
/** * This method is used to chase foreign key constraint rule in which the rule * has only one atom in the body. * * IMPORTANT: each rule is applied only ONCE to each atom * * @param atoms * @return set of atoms */ private Set<Function> chaseAtoms(Collection<Function> atoms) { Set<Function> derivedAtoms = new HashSet<>(); for (Function fact : atoms) { derivedAtoms.add(fact); for (LinearInclusionDependency d : dependencies.get(fact.getFunctionSymbol())) { CQIE rule = datalogFactory.getFreshCQIECopy(datalogFactory.getCQIE(d.getHead(), d.getBody())); Function ruleBody = rule.getBody().get(0); Substitution theta = unifierUtilities.getMGU(ruleBody, fact); if (theta != null && !theta.isEmpty()) { Function ruleHead = rule.getHead(); Function newFact = (Function)ruleHead.clone(); // unify to get fact is needed because the dependencies are not necessarily full // (in other words, they may contain existentials in the head) substitutionUtilities.applySubstitution(newFact, theta); derivedAtoms.add(newFact); } } } return derivedAtoms; }
private static CQIE generateTripleMapping(CQIE rule) { Function newhead; Function currenthead = rule.getHead(); if (currenthead.getArity() == 1) { // head is Class(x) Forming head as triple(x,uri(rdf:type), uri(Class)) Function rdfTypeConstant = TERM_FACTORY.getUriTemplate(TERM_FACTORY.getConstantLiteral(IriConstants.RDF_TYPE)); String classname = currenthead.getFunctionSymbol().getName(); Term classConstant = TERM_FACTORY.getUriTemplate(TERM_FACTORY.getConstantLiteral(classname)); newhead = ATOM_FACTORY.getTripleAtom(currenthead.getTerm(0), rdfTypeConstant, classConstant); } else if (currenthead.getArity() == 2) { // head is Property(x,y) Forming head as triple(x,uri(Property), y) String propname = currenthead.getFunctionSymbol().getName(); Function propConstant = TERM_FACTORY.getUriTemplate(TERM_FACTORY.getConstantLiteral(propname)); newhead = ATOM_FACTORY.getTripleAtom(currenthead.getTerm(0), propConstant, currenthead.getTerm(1)); } else { // head is triple(x,uri(Property),y) newhead = (Function) currenthead.clone(); } return DATALOG_FACTORY.getCQIE(newhead, rule.getBody()); } }