/*** * 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); }
public static UriTemplateMatcher merge(Stream<UriTemplateMatcher> uriTemplateMatchers, TermFactory termFactory) { ImmutableMap<Pattern, Collection<ImmutableFunctionalTerm>> pattern2Terms = uriTemplateMatchers .flatMap(m -> m.getMap().entrySet().stream()) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableMap<Pattern, ImmutableFunctionalTerm> pattern2Term = pattern2Terms.entrySet().stream() .collect(ImmutableCollectors.toMap( e -> e.getKey(), e -> flatten(e.getKey(), e.getValue()) )); UriTemplateMatcher uriTemplateMatcher = new UriTemplateMatcher(termFactory); uriTemplateMatcher.uriTemplateMatcher.putAll(pattern2Term); return uriTemplateMatcher; }
private UriTemplateMatcher mergeURITemplateMatchers(ImmutableSet<Mapping> mappings) { return UriTemplateMatcher.merge( mappings.stream() .map(m -> m.getMetadata().getUriTemplateMatcher()), termFactory ); }
uriTemplateMatcher.generateURIFunction(uri)); if (constantFunction.getArity() == 1 && unknownUrisToTemplates) {
Set<String> templateStrings = new HashSet<>(); UriTemplateMatcher uriTemplateMatcher = new UriTemplateMatcher(termFactory);
Function head = atomFactory.getMutableTripleHeadAtom( immutabilityTools.convertToMutableFunction( uriTemplateMatcher.generateURIFunction(c.getIRI().getIRIString())), classIRI); CQIE rule = datalogFactory.getCQIE(head, Collections.emptyList()); IRI propertyIRI = pa.getProperty().getIRI(); Function head = atomFactory.getMutableTripleHeadAtom( immutabilityTools.convertToMutableTerm(uriTemplateMatcher.generateURIFunction(s.getIRI().getIRIString())), propertyIRI, immutabilityTools.convertToMutableTerm(uriTemplateMatcher.generateURIFunction(o.getIRI().getIRIString()))); CQIE rule = datalogFactory.getCQIE(head, Collections.emptyList());
Set<String> templateStrings = new HashSet<>(); UriTemplateMatcher uriTemplateMatcher = new 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 static UriTemplateMatcher merge(Stream<UriTemplateMatcher> uriTemplateMatchers) { ImmutableMap<Pattern, Collection<ImmutableFunctionalTerm>> pattern2Terms = uriTemplateMatchers .flatMap(m -> m.getMap().entrySet().stream()) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableMap<Pattern, ImmutableFunctionalTerm> pattern2Term = pattern2Terms.entrySet().stream() .collect(ImmutableCollectors.toMap( e -> e.getKey(), e -> flatten(e.getKey(), e.getValue()) )); UriTemplateMatcher uriTemplateMatcher = new UriTemplateMatcher(); uriTemplateMatcher.uriTemplateMatcher.putAll(pattern2Term); return uriTemplateMatcher; }
uriTemplateMatcher.generateURIFunction(c.getURI())); CQIE rule = DATALOG_FACTORY.getCQIE(head, Collections.emptyList()); URIConstant o = (URIConstant) pa.getObject(); Function head = TERM_FACTORY.getFunction(pa.getProperty().getPredicate(), uriTemplateMatcher.generateURIFunction(s.getURI()), uriTemplateMatcher.generateURIFunction(o.getURI())); CQIE rule = DATALOG_FACTORY.getCQIE(head, Collections.emptyList());
private UriTemplateMatcher mergeURITemplateMatchers(ImmutableSet<Mapping> mappings) { return UriTemplateMatcher.merge( mappings.stream() .map(m -> m.getMetadata().getUriTemplateMatcher()) ); }
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()); } }
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()); } } }
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()); } }
ImmutableList<SQLPPTriplesMap> mappingAxioms = ImmutableList.copyOf(mappings); UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( mappingAxioms.stream() .flatMap(ax -> ax.getTargetAtoms().stream())