/*** * 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); }
@Override public Mapping merge(ImmutableSet<Mapping> mappings) { if (mappings.isEmpty()) { throw new IllegalArgumentException("The set of mappings is assumed to be nonempty"); } MappingMetadata metadata = mergeMetadata(mappings); ImmutableTable<RDFAtomPredicate, IRI, IQ> propertyTable = mergeMappingPropertyTables(mappings); ImmutableTable<RDFAtomPredicate, IRI, IQ> classTable = mergeMappingClassTables(mappings); return specificationFactory.createMapping(metadata, propertyTable, classTable); }
OBDASpecification createSpecification(Mapping mapping, DBMetadata dbMetadata, ClassifiedTBox tbox) { Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mapping); Mapping saturatedMapping = mappingSaturator.saturate(sameAsOptimizedMapping, dbMetadata, tbox); Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping); return specificationFactory.createSpecification(normalizedMapping, dbMetadata, tbox); } }
private MappingMetadata mergeMetadata(ImmutableSet<Mapping> mappings) { PrefixManager prefixManager = mergePrefixManagers(mappings); UriTemplateMatcher uriTemplateMatcher = mergeURITemplateMatchers(mappings); return specificationFactory.createMetadata(prefixManager, uriTemplateMatcher); }
private MappingMetadata mergeMetadata(ImmutableSet<Mapping> mappings) { PrefixManager prefixManager = mergePrefixManagers(mappings); UriTemplateMatcher uriTemplateMatcher = mergeURITemplateMatchers(mappings); return specificationFactory.createMetadata(prefixManager, uriTemplateMatcher); }
/*** * 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); }
public SQLPPMapping generatePPMapping() { ImmutableList<SQLPPTriplesMap> triplesMaps = ImmutableList.copyOf(triplesMapMap.values()); try { UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( triplesMaps.stream() .flatMap(ax -> ax.getTargetAtoms().stream()) .flatMap(targetAtom -> targetAtom.getSubstitution().getImmutableMap().values().stream()) .filter(t -> t instanceof ImmutableFunctionalTerm) .map(t -> (ImmutableFunctionalTerm) t), termFactory); return ppMappingFactory.createSQLPreProcessedMapping(triplesMaps, // TODO: give an immutable prefix manager!! specificationFactory.createMetadata(prefixManager, uriTemplateMatcher)); /** * No mapping so should never happen */ } catch(DuplicateMappingException e) { throw new RuntimeException("A DuplicateMappingException has been thrown while no mapping has been given." + "What is going on? Message: " + e.getMessage()); } }
@Override public Mapping toRegularMapping() { ImmutableMultimap<AtomPredicate, IntermediateQuery> assertionMultimap = getMappingAssertions().stream() .collect(ImmutableCollectors.toMultimap( q -> q.getProjectionAtom().getPredicate(), q -> q)); ImmutableMap<AtomPredicate, IntermediateQuery> definitionMap = assertionMultimap.asMap().values().stream() .map(queryMerger::mergeDefinitions) .filter(Optional::isPresent) .map(Optional::get) .collect(ImmutableCollectors.toMap( q -> q.getProjectionAtom().getPredicate(), q -> q)); return specFactory.createMapping(mappingMetadata, definitionMap, executorRegistry); }
OBDASpecification createSpecification(Mapping mapping, DBMetadata dbMetadata, ClassifiedTBox tbox) { Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mapping, dbMetadata); Mapping canonicalMapping = mappingCanonicalRewriter.rewrite(sameAsOptimizedMapping, dbMetadata); Mapping saturatedMapping = mappingSaturator.saturate(canonicalMapping, dbMetadata, tbox); Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping); return specificationFactory.createSpecification(normalizedMapping, dbMetadata, tbox); } }
private SQLPPMapping parse(R2RMLManager manager) throws DuplicateMappingException, InvalidMappingException { try { //TODO: make the R2RMLManager simpler. ImmutableList<SQLPPTriplesMap> sourceMappings = manager.getMappings(manager.getModel()); UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( sourceMappings.stream() .flatMap(ax -> ax.getTargetAtoms().stream()) .flatMap(atom -> atom.getSubstitution().getImmutableMap().values().stream()) .filter(t -> t instanceof ImmutableFunctionalTerm) .map(t -> (ImmutableFunctionalTerm) t), termFactory); //TODO: try to extract prefixes from the R2RML mappings PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.of()); MappingMetadata mappingMetadata = specificationFactory.createMetadata(prefixManager, uriTemplateMatcher); return ppMappingFactory.createSQLPreProcessedMapping(sourceMappings, mappingMetadata); } catch (InvalidR2RMLMappingException e) { throw new InvalidMappingException(e.getMessage()); } }
@Override public Mapping toRegularMapping() { ImmutableMap<IQ, MappingTools.RDFPredicateInfo> iqClassificationMap = getMappingAssertions().stream() .collect(ImmutableCollectors.toMap( iq -> iq, MappingTools::extractRDFPredicate )); return specFactory.createMapping(mappingMetadata, extractTable(iqClassificationMap, false), extractTable(iqClassificationMap, true)); }
public SQLPPMapping createMappings() { OntopMappingConfiguration defaultConfiguration = OntopMappingConfiguration.defaultBuilder() .build(); SpecificationFactory specificationFactory = defaultConfiguration.getInjector().getInstance(SpecificationFactory.class); PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.of()); ImmutableList<SQLPPTriplesMap> mappingAxioms = dataRepository.getMappings(); UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( mappingAxioms.stream() .flatMap(ax -> ax.getTargetAtoms().stream()) .flatMap(atom -> atom.getSubstitution().getImmutableMap().values().stream()) .filter(t -> t instanceof ImmutableFunctionalTerm) .map(t -> (ImmutableFunctionalTerm) t), termFactory); try { return new SQLPPMappingImpl(mappingAxioms, specificationFactory.createMetadata(prefixManager, uriTemplateMatcher)); } catch (DuplicateMappingException e) { throw new IllegalStateException(e.getMessage()); } } }
@Override public Mapping normalize(Mapping mapping) { AtomicInteger i = new AtomicInteger(0); ImmutableTable<RDFAtomPredicate, IRI, IQ> newPropertyTable = normalize(mapping.getRDFPropertyQueries(), i); ImmutableTable<RDFAtomPredicate, IRI, IQ> newClassTable = normalize(mapping.getRDFClassQueries(), i); return specificationFactory.createMapping(mapping.getMetadata(), newPropertyTable, newClassTable); }
@Override public Mapping convert(OntologyABox ontology, boolean isOntologyAnnotationQueryingEnabled, UriTemplateMatcher uriTemplateMatcher) { List<AnnotationAssertion> annotationAssertions = isOntologyAnnotationQueryingEnabled ? ontology.getAnnotationAssertions() : Collections.emptyList(); // Mutable !! // UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create(Stream.empty()); ImmutableList<CQIE> rules = convertAssertions( ontology.getClassAssertions(), ontology.getObjectPropertyAssertions(), ontology.getDataPropertyAssertions(), annotationAssertions, uriTemplateMatcher ); return datalog2QueryMappingConverter.convertMappingRules( rules, mappingFactory.createMetadata( //TODO: parse the ontology prefixes ?? mappingFactory.createPrefixManager(ImmutableMap.of()), uriTemplateMatcher )); }
@Override public Mapping normalize(Mapping mapping) { Stream<IntermediateQuery> queryStream = mapping.getPredicates().stream() .map(mapping::getDefinition) .filter(Optional::isPresent) .map(Optional::get); ImmutableMap<AtomPredicate, IntermediateQuery> normalizedMappingMap = renameQueries(queryStream) .collect(ImmutableCollectors.toMap( q -> q.getProjectionAtom().getPredicate(), q -> q )); return specificationFactory.createMapping(mapping.getMetadata(), normalizedMappingMap, mapping.getExecutorRegistry()); }
PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.copyOf(prefixes)); ImmutableList<SQLPPTriplesMap> mappingAxioms = ImmutableList.copyOf(mappings); termFactory); MappingMetadata metadata = specificationFactory.createMetadata(prefixManager, uriTemplateMatcher); return ppMappingFactory.createSQLPreProcessedMapping(mappingAxioms, metadata);
@Override public Mapping update(ImmutableTable<RDFAtomPredicate, IRI, IQ> propertyUpdateTable, ImmutableTable<RDFAtomPredicate, IRI, IQ> classUpdateTable) { ImmutableTable<RDFAtomPredicate, IRI, IQ> newPropertyDefs = propertyUpdateTable.isEmpty() ? propertyDefinitions : updateDefinitions(propertyDefinitions, propertyUpdateTable); ImmutableTable<RDFAtomPredicate, IRI, IQ> newTripleClassDefs = classUpdateTable.isEmpty() ? classDefinitions : updateDefinitions(classDefinitions, classUpdateTable); return specificationFactory.createMapping(metadata, newPropertyDefs, newTripleClassDefs); }
dummyDBMetadata, executorRegistry, mappingFactory.createMetadata( mappingFactory.createPrefixManager(ImmutableMap.of()), uriTemplateMatcher ));
return specificationFactory.createMapping(mappingMetadata, mappingMap, executorRegistry);
@Override public Mapping merge(ImmutableSet<Mapping> mappings) { if (mappings.isEmpty()) { throw new IllegalArgumentException("The set of mappings is assumed to be nonempty"); } MappingMetadata metadata = mergeMetadata(mappings); ImmutableMap<AtomPredicate, IntermediateQuery> mappingMap = mergeMappingMaps(mappings); // TODO: check that the ExecutorRegistry is identical for all mappings ? return specificationFactory.createMapping( metadata, mappingMap, mappings.iterator().next().getExecutorRegistry() ); }