public SQLPPMappingToR2RMLConverter(SQLPPMapping ppMapping, OWLOntology ontology, RDF rdfFactory) { this.ppMappingAxioms = ppMapping.getTripleMaps(); this.prefixmng = ppMapping.getMetadata().getPrefixManager(); this.ontology = ontology; this.rdfFactory = rdfFactory; }
/*** * extract all the mappings from a datasource * * @return a new OBDA Model containing all the extracted mappings */ private SQLPPMapping extractPPMapping(Optional<SQLPPMapping> ppMapping) throws MappingException, SQLException { SQLPPMapping mapping; if (!ppMapping.isPresent()) { it.unibz.inf.ontop.spec.mapping.PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.of()); MappingMetadata mappingMetadata = specificationFactory.createMetadata(prefixManager, UriTemplateMatcher.create(Stream.empty())); mapping = ppMappingFactory.createSQLPreProcessedMapping(ImmutableList.of(), mappingMetadata); } else mapping = ppMapping.get(); currentMappingIndex = mapping.getTripleMaps().size() + 1; return bootstrapMappings(mapping); }
private SQLPPMapping bootstrapMappings(RDBMetadata metadata, SQLPPMapping ppMapping) throws DuplicateMappingException { if (baseIRI == null || baseIRI.isEmpty()) this.baseIRI = ppMapping.getMetadata().getPrefixManager().getDefaultPrefix(); Collection<DatabaseRelationDefinition> tables = metadata.getDatabaseRelations(); List<SQLPPTriplesMap> mappingAxioms = new ArrayList<>(); for (DatabaseRelationDefinition td : tables) { mappingAxioms.addAll(getMapping(td, baseIRI)); } List<SQLPPTriplesMap> mappings = new ArrayList<>(); mappings.addAll(ppMapping.getTripleMaps()); mappings.addAll(mappingAxioms); return ppMappingFactory.createSQLPreProcessedMapping(ImmutableList.copyOf(mappings), ppMapping.getMetadata()); }
/** * Assumption: one CQIE per mapping axiom (no nested union) */ private ImmutableMap<CQIE, PPMappingAssertionProvenance> convertIntoDatalog(SQLPPMapping ppMapping, RDBMetadata dbMetadata) throws InvalidMappingSourceQueriesException { /* * May also add views in the DBMetadata! */ ImmutableMap<CQIE, PPMappingAssertionProvenance> datalogMap = ppMapping2DatalogConverter.convert( ppMapping.getTripleMaps(), dbMetadata); LOGGER.debug("Original mapping size: {}", datalogMap.size()); // Normalizing language tags and equalities (SIDE-EFFECT!) normalizeMapping(datalogMap.keySet()); return datalogMap; }
/** * Assumption: one CQIE per mapping axiom (no nested union) */ private ImmutableMap<CQIE, PPMappingAssertionProvenance> convertIntoDatalog(SQLPPMapping ppMapping, RDBMetadata dbMetadata) throws InvalidMappingSourceQueriesException { /* * May also add views in the DBMetadata! */ ImmutableMap<CQIE, PPMappingAssertionProvenance> datalogMap = SQLPPMapping2DatalogConverter.convert( ppMapping.getTripleMaps(), dbMetadata); LOGGER.debug("Original mapping size: {}", datalogMap.size()); // Normalizing language tags and equalities (SIDE-EFFECT!) normalizeMapping(datalogMap.keySet()); return datalogMap; }
private SQLPPMapping bootstrapMappings(RDBMetadata metadata, SQLPPMapping ppMapping) throws DuplicateMappingException { if (baseIRI == null || baseIRI.isEmpty()) this.baseIRI = ppMapping.getMetadata().getPrefixManager().getDefaultPrefix(); Collection<DatabaseRelationDefinition> tables = metadata.getDatabaseRelations(); List<SQLPPTriplesMap> mappingAxioms = new ArrayList<>(); for (DatabaseRelationDefinition td : tables) { mappingAxioms.addAll(getMapping(td, baseIRI)); } List<SQLPPTriplesMap> mappings = new ArrayList<>(); mappings.addAll(ppMapping.getTripleMaps()); mappings.addAll(mappingAxioms); return ppMappingFactory.createSQLPreProcessedMapping(ImmutableList.copyOf(mappings), ppMapping.getMetadata()); }
/*** * extract all the mappings from a datasource * * @return a new OBDA Model containing all the extracted mappings */ private SQLPPMapping extractPPMapping(Optional<SQLPPMapping> ppMapping) throws MappingException, SQLException { SQLPPMapping mapping; if (!ppMapping.isPresent()) { it.unibz.inf.ontop.spec.mapping.PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.of()); MappingMetadata mappingMetadata = specificationFactory.createMetadata(prefixManager, UriTemplateMatcher.create(Stream.empty(), termFactory)); mapping = ppMappingFactory.createSQLPreProcessedMapping(ImmutableList.of(), mappingMetadata); } else mapping = ppMapping.get(); currentMappingIndex = mapping.getTripleMaps().size() + 1; return bootstrapMappings(mapping); }
private void writeMappingDeclaration(BufferedWriter writer) throws IOException { writer.write(OntopNativeMappingParser.MAPPING_DECLARATION_TAG + " " + OntopNativeMappingParser.START_COLLECTION_SYMBOL); writer.write("\n"); boolean needLineBreak = false; for (SQLPPTriplesMap axiom : ppMapping.getTripleMaps()) { if (needLineBreak) { writer.write("\n"); } writer.write(OntopNativeMappingParser.Label.mappingId.name() + "\t" + axiom.getId() + "\n"); ImmutableList<TargetAtom> targetQuery = axiom.getTargetAtoms(); writer.write(OntopNativeMappingParser.Label.target.name() + "\t\t" + printTargetQuery(targetQuery) + "\n"); OBDASQLQuery sourceQuery = axiom.getSourceQuery(); writer.write(OntopNativeMappingParser.Label.source.name() + "\t\t" + printSourceQuery(sourceQuery) + "\n"); needLineBreak = true; } writer.write(OntopNativeMappingParser.END_COLLECTION_SYMBOL); writer.write("\n\n"); }
public void refresh() { OBDADataSource source = obdaModel.getDatasource(); List<SQLPPTriplesMap> mappingList = obdaModel.generatePPMapping().getTripleMaps(); HashMap<String, Integer> mappingStat = new HashMap<String, Integer>(); for (SQLPPTriplesMap mapping : mappingList) { String mappingId = mapping.getId(); int triplesCount = 0; try { OBDASQLQuery sourceQuery = mapping.getSourceQuery(); int tuples = getTuplesCount(sourceQuery, source); ImmutableList<TargetAtom> targetQuery = mapping.getTargetAtoms(); int atoms = targetQuery.size(); triplesCount = tuples * atoms; } catch (Exception e) { triplesCount = -1; // fails to count log.error(e.getMessage()); } mappingStat.put(mappingId, triplesCount); } statistics.put(source.getSourceID().toString(), mappingStat); }
Set<RelationID> realTables = getRealTables(metadata.getQuotedIDFactory(), ppMapping.getTripleMaps()); implicitConstraints.ifPresent(c -> {
Set<RelationID> realTables = getRealTables(metadata.getQuotedIDFactory(), ppMapping.getTripleMaps()); implicitConstraints.ifPresent(c -> {
public void parseMapping(Reader mappingReader, Properties properties) throws DuplicateMappingException, InvalidMappingException, IOException, MappingIOException { OntopMappingSQLAllConfiguration configuration = OntopMappingSQLAllConfiguration.defaultBuilder() .nativeOntopMappingReader(mappingReader) .properties(properties) .build(); SQLMappingParser mappingParser = configuration.getInjector().getInstance(SQLMappingParser.class); SQLPPMapping ppMapping = mappingParser.parse(mappingReader); prefixManager.addPrefixes(ppMapping.getMetadata().getPrefixManager().getPrefixMap()); // New map triplesMapMap = ppMapping.getTripleMaps().stream() .collect(collectTriplesMaps( SQLPPTriplesMap::getId, m -> m)); }
currentMappingIndex = ppMapping.getTripleMaps().size() + 1;
/** * NOT THREAD-SAFE (not reentrant) */ private BootstrappingResults bootstrapMappingAndOntology(String baseIRI, Optional<SQLPPMapping> inputPPMapping, Optional<OWLOntology> inputOntology) throws MappingBootstrappingException { this.baseIRI = fixBaseURI(baseIRI); try { SQLPPMapping newPPMapping = extractPPMapping(inputPPMapping); OWLOntology ontology = inputOntology.isPresent() ? inputOntology.get() : OWLManager.createOWLOntologyManager().createOntology(IRI.create(baseIRI)); // update ontology OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLDeclarationAxiom> declarationAxioms = extractDeclarationAxioms(manager, newPPMapping.getTripleMaps().stream() .flatMap(ax -> ax.getTargetAtoms().stream())); manager.addAxioms(ontology, declarationAxioms); return new DefaultBootstrappingResults(newPPMapping, ontology); } catch (SQLException | MappingException | OWLOntologyCreationException e) { throw new MappingBootstrappingException(e); } }
/** * NOT THREAD-SAFE (not reentrant) */ private BootstrappingResults bootstrapMappingAndOntology(String baseIRI, Optional<SQLPPMapping> inputPPMapping, Optional<OWLOntology> inputOntology) throws MappingBootstrappingException { this.baseIRI = fixBaseURI(baseIRI); try { SQLPPMapping newPPMapping = extractPPMapping(inputPPMapping); OWLOntology ontology = inputOntology.isPresent() ? inputOntology.get() : OWLManager.createOWLOntologyManager().createOntology(IRI.create(baseIRI)); // update ontology OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLDeclarationAxiom> declarationAxioms = extractDeclarationAxioms(manager, newPPMapping.getTripleMaps().stream() .flatMap(ax -> ax.getTargetAtoms().stream())); manager.addAxioms(ontology, declarationAxioms); return new DefaultBootstrappingResults(newPPMapping, ontology); } catch (SQLException | MappingException | OWLOntologyCreationException e) { throw new MappingBootstrappingException(e); } }
for (SQLPPTriplesMap mapping : obdaModel.generatePPMapping().getTripleMaps()) { ImmutableList<TargetAtom> tq = mapping.getTargetAtoms(); if (!TargetQueryValidator.validate(tq, obdaModel.getCurrentVocabulary()).isEmpty()) {
protected SQLPPMapping expandPPMapping(SQLPPMapping ppMapping, OntopMappingSQLSettings settings, RDBMetadata dbMetadata) throws MetaMappingExpansionException { MetaMappingExpander expander = new MetaMappingExpander(ppMapping.getTripleMaps(), termFactory, substitutionFactory); final ImmutableList<SQLPPTriplesMap> expandedMappingAxioms; if (expander.hasMappingsToBeExpanded()) { try (Connection connection = LocalJDBCConnectionUtils.createConnection(settings)) { expandedMappingAxioms = expander.getExpandedMappings(connection, dbMetadata); } // Problem while creating the connection catch (SQLException e) { throw new MetaMappingExpansionException(e.getMessage()); } } else expandedMappingAxioms = expander.getNonExpandableMappings(); try { return new SQLPPMappingImpl(expandedMappingAxioms, ppMapping.getMetadata()); } catch (DuplicateMappingException e) { // Internal bug throw new IllegalStateException(e); } }
protected SQLPPMapping expandPPMapping(SQLPPMapping ppMapping, OntopMappingSQLSettings settings, RDBMetadata dbMetadata) throws MetaMappingExpansionException { MetaMappingExpander expander = new MetaMappingExpander(ppMapping.getTripleMaps()); final ImmutableList<SQLPPTriplesMap> expandedMappingAxioms; if (expander.hasMappingsToBeExpanded()) { try (Connection connection = LocalJDBCConnectionUtils.createConnection(settings)) { expandedMappingAxioms = expander.getExpandedMappings(connection, dbMetadata); } // Problem while creating the connection catch (SQLException e) { throw new MetaMappingExpansionException(e.getMessage()); } } else expandedMappingAxioms = expander.getNonExpandableMappings(); try { return new SQLPPMappingImpl(expandedMappingAxioms, ppMapping.getMetadata()); } catch (DuplicateMappingException e) { // Internal bug throw new IllegalStateException(e); } }
public void run(File file) throws Exception { /** * Uses the predefined data source for creating the OBDAModel. */ OBDADataSource dataSource = obdaModelController.getSources().get(0); OntopMappingSQLAllConfiguration configuration = OntopMappingSQLAllConfiguration.defaultBuilder() .properties(DataSource2PropertiesConvertor.convert(dataSource)) .r2rmlMappingFile(file) .build(); SQLPPMapping parsedModel = configuration.loadProvidedPPMapping(); try{ /** * TODO: improve this inefficient method (batch processing, not one by one) */ for (SQLPPTriplesMap mapping : parsedModel.getTripleMaps()) { if (mapping.getTargetAtoms().toString().contains("BNODE")) { JOptionPane.showMessageDialog(getWorkspace(), "The mapping " + mapping.getId() + " contains BNode. -ontoPro- does not support it yet."); } else { obdaModelController.addTriplesMap(mapping, false); } } } catch (DuplicateMappingException dm) { JOptionPane.showMessageDialog(getWorkspace(), "Duplicate mapping id found. Please correct the Resource node name: " + dm.getLocalizedMessage()); throw new RuntimeException("Duplicate mapping found: " + dm.getMessage()); } }