@Override public void removeRules(Collection<CQIE> rs) { for (CQIE rule : rs) { this.rules.remove(rule); Predicate predicate = rule.getHead().getFunctionSymbol(); List<CQIE> indexedRules = this.predicateIndex.get(predicate); if (indexedRules != null) indexedRules.remove(rule); } }
@Override public void appendRule(CQIE rule) { if (rule == null) { throw new IllegalArgumentException("DatalogProgram: Recieved a null rule."); } if (rules.contains(rule)) { return; // Skip if the rule already exists! } rules.add(rule); Function head = rule.getHead(); if (head != null) { Predicate predicate = rule.getHead().getFunctionSymbol(); List<CQIE> indexedRules = predicateIndex.get(predicate); if (indexedRules == null) { indexedRules = new LinkedList<CQIE>(); predicateIndex.put(predicate, indexedRules); } indexedRules.add(rule); } }
@Override public int deletePredicate(Predicate predicate) { int modifiedCount = 0; for (OBDADataSource source : datasources.values()) { List<OBDAMappingAxiom> mp = new ArrayList<OBDAMappingAxiom>(mappings.get(source.getSourceID())); for (OBDAMappingAxiom mapping : mp) { List<Function> body = mapping.getTargetQuery(); for (int idx = 0; idx < body.size(); idx++) { Function oldatom = body.get(idx); if (!oldatom.getFunctionSymbol().equals(predicate)) { continue; } modifiedCount += 1; body.remove(idx); } if (body.size() != 0) { fireMappigUpdated(source.getSourceID()); } else { removeMapping(source.getSourceID(), mapping.getId()); } } } return modifiedCount; }
private Term getFreshTerm(Term term, int suff) { Term newTerm; if (term instanceof Variable) { Variable variable = (Variable) term; newTerm = getVariable(variable.getName() + "_" + suff); } else if (term instanceof Function) { Function functionalTerm = (Function) term; List<Term> innerTerms = functionalTerm.getTerms(); List<Term> newInnerTerms = new LinkedList<>(); for (int j = 0; j < innerTerms.size(); j++) { Term innerTerm = innerTerms.get(j); newInnerTerms.add(getFreshTerm(innerTerm, suff)); } Predicate newFunctionSymbol = functionalTerm.getFunctionSymbol(); Function newFunctionalTerm = getFunction(newFunctionSymbol, newInnerTerms); newTerm = newFunctionalTerm; } else if (term instanceof Constant) { newTerm = term.clone(); } else { throw new RuntimeException("Unsupported term: " + term); } return newTerm; }
/** * check if the term is {@code URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")} * @param term * @return */ private static boolean isURIRDFType(Term term) { boolean result = true; if(term instanceof Function){ Function func = (Function) term; if (func.getArity() != 1){ result = false; } else { result = result && (func.getFunctionSymbol() instanceof URITemplatePredicate); result = result && (func.getTerm(0) instanceof ValueConstant) && ((ValueConstant) func.getTerm(0)).getValue(). equals(OBDAVocabulary.RDF_TYPE); } } else { result = false; } return result; }
if (term instanceof Function) { Function uri = ((Function) term); if (uri.getFunctionSymbol() instanceof URITemplatePredicate) { String uriName = ((ValueConstant) uri.getTerm(0)).getValue(); if (uriName.startsWith(oldPrefix)) { if (!oldAtom.getFunctionSymbol().equals(removedPredicate)) { continue;
if (term instanceof Function) { Function function = (Function) term; Predicate functionSymbol = function.getFunctionSymbol(); String fname = getAbbreviatedName(functionSymbol.toString(), prefixManager, false); if (function.isDataTypeFunction()) {
Predicate pred = bodyAtom.getFunctionSymbol();
if (term0 instanceof Function) { Function constPred = (Function) term0; Predicate newpred = constPred.getFunctionSymbol(); Function bodyAtom = fac.getFunction(newpred, subjectAtom); body.add(bodyAtom);
String name = head.getFunctionSymbol().getName(); int size = variableList.size();
Predicate pred = func.getFunctionSymbol(); if (predf.getFunctionSymbol() instanceof URITemplatePredicate) { if (predf.getTerms().size() == 1) //fixed string } else if (object instanceof Function) { Predicate objectPred = ((Function) object).getFunctionSymbol(); if (objectPred instanceof URITemplatePredicate) { String objectURI = URITemplates.getUriTemplateString((Function)object, prefixmng);
newTerms.add(renameVariables(innerTerm, lookupTable, idfac)); return fac.getFunction(func.getFunctionSymbol(), newTerms);
for (Function atom : body) { String subject, predicate, object = ""; String originalString = atom.getFunctionSymbol().toString(); if (isUnary(atom)) { Term subjectTerm = atom.getTerm(0);
} else { if (object instanceof Function) { if (((Function) object).getFunctionSymbol() instanceof URITemplatePredicate) {
Predicate pred = func.getFunctionSymbol(); String predName = pred.getName(); URI predUri = null; String predURIString =""; if (predf.getFunctionSymbol() instanceof URITemplatePredicate) { if (predf.getTerms().size() == 1) { //fixed string pred = OBDADataFactoryImpl.getInstance().getPredicate(((ValueConstant)(predf.getTerm(0))).getValue(), 1); Predicate objectPred = o.getFunctionSymbol(); if (objectPred instanceof URITemplatePredicate) { Predicate functionSymbol = ((Function) objectTerm).getFunctionSymbol();