private Function replaceConstants(Function a, List<Function> filters) { Function atom = (Function)a.clone(); for (int i = 0; i < atom.getTerms().size(); i++) { Term term = atom.getTerm(i); if (term instanceof Constant) { // Found a constant, replacing with a fresh variable // and adding the new equality atom Constant c = (Constant)term; Variable var = valueMap.get(c); if (var == null) { freshVarCount++; var = termFactory.getVariable("?FreshVar" + freshVarCount); valueMap.put(c, var); filters.add(termFactory.getFunctionEQ(var, c)); } atom.setTerm(i, var); } } return atom; }
private Function replaceConstants(Function a, List<Function> filters) { Function atom = (Function)a.clone(); for (int i = 0; i < atom.getTerms().size(); i++) { Term term = atom.getTerm(i); if (term instanceof Constant) { // Found a constant, replacing with a fresh variable // and adding the new equality atom Constant c = (Constant)term; Variable var = valueMap.get(c); if (var == null) { freshVarCount++; var = TERM_FACTORY.getVariable("?FreshVar" + freshVarCount); valueMap.put(c, var); filters.add(TERM_FACTORY.getFunctionEQ(var, c)); } atom.setTerm(i, var); } } return atom; }
private void deleteExplicitTypes(Term term, Function atom, int position) { if(term instanceof Function){ Function castTerm = (Function) term; IntStream.range(0, castTerm.getArity()) .forEach(i -> deleteExplicitTypes( castTerm.getTerm(i), castTerm, i )); if(castTerm.isDataTypeFunction()){ atom.setTerm(position, castTerm.getTerm(0)); } } }
private void deleteExplicitTypes(Term term, Function atom, int position) { if(term instanceof Function){ Function castTerm = (Function) term; IntStream.range(0, castTerm.getArity()) .forEach(i -> deleteExplicitTypes( castTerm.getTerm(i), castTerm, i )); if(castTerm.isDataTypeFunction()){ atom.setTerm(position, castTerm.getTerm(0)); } } }
public CQIE create() { //get the canonical version of the uri and useful columns CQIE canonicalMapping = uriMappingMap.get(templateURI); Function canonHead = canonicalMapping.getHead(); final Function templateCanURI = (Function) canonHead.getTerm(0); //get templateuri Function target = (Function) canonHead.getTerm(1); //get substitution Substitution subs = UnifierUtilities.getMGU(uriTerm, target); CQIE newMapping = SubstitutionUtilities.applySubstitution(mapping, subs, true); Function currentHead = newMapping.getHead(); currentHead.setTerm(termPosition.getPosition(), templateCanURI); List<Function> newURIBody = new ArrayList<>(); newURIBody.addAll(canonicalMapping.getBody()); //get body values from the new mapping that have not been added already from the body of the canonical mapping newURIBody.addAll(newMapping.getBody().stream() .filter(m -> !newURIBody.contains(m)) .collect(Collectors.toList())); newMapping.updateBody(newURIBody); return newMapping; } }
"inferred " + "from the database"); atom.setTerm(position, newTerm); } else if (term instanceof ValueConstant) { Term newTerm = termFactory.getTypedTerm(term, ((ValueConstant) term).getType()); atom.setTerm(position, newTerm); } else { throw new IllegalArgumentException("Unsupported subtype of: " + Term.class.getSimpleName());
"inferred " + "from the database"); atom.setTerm(position, newTerm); } else if (term instanceof ValueConstant) { Term newTerm = TERM_FACTORY.getTypedTerm(term, ((ValueConstant) term).getType()); atom.setTerm(position, newTerm); } else { throw new IllegalArgumentException("Unsupported subtype of: " + Term.class.getSimpleName());
atom.setTerm(i, t2.getTerm(0));
Term normalizedLangTag = TERM_FACTORY.getConstantLiteral(originalLangConstant.getValue().toLowerCase(), originalLangConstant.getType()); typedTerm.setTerm(1, normalizedLangTag);
atom.setTerm(i, t2.getTerm(0));
Term normalizedLangTag = termFactory.getConstantLiteral(originalLangConstant.getValue().toLowerCase(), originalLangConstant.getType()); typedTerm.setTerm(1, normalizedLangTag);
private Function createJoinWithSameAsOnLeftAndRight(Function leftAtom, DatalogProgram pr, String newHeadName) { //ON THE RIGHT //create right atom of the join between the data property and same as //given a data property as hasProperty (x, y) //create an unbound hasProperty (anon-x1, anon-y1) Function unboundleftAtom = termFactory.getFunction(leftAtom.getFunctionSymbol()); unboundleftAtom.updateTerms(leftAtom.getTerms()); unboundleftAtom.setTerm(0, termFactory.getVariable("anon-"+bnode+ leftAtom.getTerm(0))); unboundleftAtom.setTerm(2, termFactory.getVariable("anon-"+bnode +leftAtom.getTerm(2))); //create statement pattern for same as create owl:sameAs(anon-y1, y) //it will be the right atom of the join Term sTerm2 = unboundleftAtom.getTerm(2); Term oTerm2 = leftAtom.getTerm(2); Function rightAtomJoin2 = atomFactory.getMutableTripleBodyAtom(sTerm2, OWL.SAME_AS, oTerm2); //create join rule List<Term> varListJoin2 = getUnion(getVariables(unboundleftAtom), getVariables(rightAtomJoin2)); CQIE joinRule2 = createRule(pr, newHeadName + "0" , varListJoin2, unboundleftAtom, rightAtomJoin2); Function joinRight = joinRule2.getHead(); //ON THE LEFT //given a data property ex hasProperty (x, y) //create statement pattern for same as create owl:sameAs( x, anon-x1) //it will be the left atom of the join Term sTerm = leftAtom.getTerm(0); Term oTerm = unboundleftAtom.getTerm(0); Function leftAtomJoin = atomFactory.getMutableTripleBodyAtom(sTerm, OWL.SAME_AS, oTerm); //create join rule List<Term> varListJoin = getUnion(getVariables(leftAtomJoin), getVariables(joinRight)); CQIE joinRule = createRule(pr, newHeadName , varListJoin, leftAtomJoin, joinRight); return joinRule.getHead(); }
private Function createJoinWithSameAsOnLeft(Function leftAtom, DatalogProgram pr, String newHeadName) { //create left atom of the join between the data property and same as //given a data property as hasProperty (x, y) //create the left atom hasProperty (anon-x, y) Function leftAtomJoin = termFactory.getFunction(leftAtom.getFunctionSymbol()); leftAtomJoin.updateTerms(leftAtom.getTerms()); leftAtomJoin.setTerm(0, termFactory.getVariable("anon-" +bnode +leftAtom.getTerm(0))); //given a data property ex hasProperty (x, y) //create statement pattern for same as create owl:sameAs( anon-x, y) //it will be the right atom of the join Term sTerm = leftAtom.getTerm(0); Term oTerm = termFactory.getVariable("anon-"+ bnode +leftAtom.getTerm(0)); Function rightAtomJoin = atomFactory.getMutableTripleBodyAtom(sTerm, OWL.SAME_AS, oTerm); //create join rule List<Term> varListJoin = getUnion(getVariables(leftAtomJoin), getVariables(rightAtomJoin)); CQIE joinRule = createRule(pr, newHeadName , varListJoin, leftAtomJoin, rightAtomJoin); bnode++; return joinRule.getHead(); }
private Function createJoinWithSameAsOnRight(Function leftAtom, DatalogProgram pr, String newHeadName) { //create right atom of the join between the data property and same as //given a data property as hasProperty (x, y) //create the left atom hasProperty (x, anon-y) Function leftAtomJoin2 = termFactory.getFunction(leftAtom.getFunctionSymbol()); leftAtomJoin2.updateTerms(leftAtom.getTerms()); leftAtomJoin2.setTerm(2, termFactory.getVariable("anon-"+bnode +leftAtom.getTerm(2))); //create statement pattern for same as create owl:sameAs(anon-y, y) //it will be the right atom of the join Term sTerm2 = termFactory.getVariable("anon-"+ bnode +leftAtom.getTerm(2)); Term oTerm2 = leftAtom.getTerm(2); Function rightAtomJoin2 = atomFactory.getMutableTripleBodyAtom(sTerm2, OWL.SAME_AS, oTerm2); //create join rule List<Term> varListJoin2 = getUnion(getVariables(leftAtomJoin2), getVariables(rightAtomJoin2)); CQIE joinRule2 = createRule(pr, newHeadName , varListJoin2, leftAtomJoin2, rightAtomJoin2); bnode++; return joinRule2.getHead(); } }