private void saveMapping(URI dataSourceUri, String mappingId, String sourceQuery, List<Function> targetQuery) { try { OBDAMappingAxiom mapping = dataFactory.getRDBMSMappingAxiom(mappingId, dataFactory.getSQLQuery(sourceQuery), targetQuery); model.addMapping(dataSourceUri, mapping, false); } catch (DuplicateMappingException e) { // NO-OP: Ignore it as duplicates won't be loaded to the model } }
/** * Get OBDA mapping axiom from R2RML TriplesMap * @param tm * @return * @throws Exception */ private OBDAMappingAxiom getMapping(TriplesMap tm) throws Exception { String sourceQuery = r2rmlParser.getSQLQuery(tm).trim(); List<Function> body = getMappingTripleAtoms(tm); //Function head = getHeadAtom(body); //CQIE targetQuery = fac.getCQIE(head, body); OBDAMappingAxiom mapping = fac.getRDBMSMappingAxiom("mapping-"+tm.hashCode(), fac.getSQLQuery(sourceQuery), body); if (body.isEmpty()){ //we do not have a target query System.out.println("WARNING a mapping without target query will not be introduced : "+ mapping.toString()); return null; } return mapping; }
private ImmutableList<OBDAMappingAxiom> splitMappingAxiom(OBDAMappingAxiom mappingAxiom, String delimiterSubstring) { Multimap<Function, Function> subjectTermToTargetTriples = ArrayListMultimap.create(); for(Function targetTriple : mappingAxiom.getTargetQuery()){ Function subjectTerm = getFirstFunctionalTerm(targetTriple) .orElseThrow( () -> new IllegalStateException("Invalid OBDA mapping")); subjectTermToTargetTriples.put(subjectTerm, targetTriple); } // If the partition per target triple subject is non trivial if(subjectTermToTargetTriples.size() > 1){ // Create ids for the new mapping axioms Map<Function, String> subjectTermToMappingIndex = new HashMap<>(); int i = 1; for (Function subjectTerm : subjectTermToTargetTriples.keySet()){ subjectTermToMappingIndex.put(subjectTerm, mappingAxiom.getId()+delimiterSubstring+i); i++; } // Generate one mapping axiom per subject return subjectTermToTargetTriples.asMap().entrySet().stream() .map(e -> OBDA_DATA_FACTORY.getRDBMSMappingAxiom( subjectTermToMappingIndex.get(e.getKey()), mappingAxiom.getSourceQuery(), new ArrayList<Function>(e.getValue()))) .collect(ImmutableCollectors.toList()); } return ImmutableList.of(mappingAxiom); }
public static Collection<OBDAMappingAxiom> splitMappings(Collection<OBDAMappingAxiom> mappings) { List<OBDAMappingAxiom> newMappings = new LinkedList<>(); OBDADataFactory dfac = OBDADataFactoryImpl.getInstance(); for (OBDAMappingAxiom mapping : mappings) { List<Function> targetQuery = mapping.getTargetQuery(); if (targetQuery.size() == 1) { // For mappings with only one body atom, we do not need to change it newMappings.add(mapping); } else { String id = mapping.getId(); OBDASQLQuery sourceQuery = mapping.getSourceQuery(); for (Function bodyAtom : targetQuery) { String newId = IDGenerator.getNextUniqueID(id + "#"); OBDAMappingAxiom newMapping = dfac.getRDBMSMappingAxiom(newId, sourceQuery, Collections.singletonList(bodyAtom)); newMappings.add(newMapping); } } } return newMappings; } }
OBDAMappingAxiom mapping = fac.getRDBMSMappingAxiom("mapping-join-"+robm.hashCode(), fac.getSQLQuery(sourceQuery), body); System.out.println("WARNING joinMapping introduced : "+mapping.toString()); joinMappings.add(mapping);
OBDASQLQuery newSourceQuery = dfac.getSQLQuery(newSourceQuerySQL); OBDAMappingAxiom newMapping = dfac.getRDBMSMappingAxiom(id, newSourceQuery, Collections.singletonList(newTargetBody)); return newMapping;