private ImmutableMultimap<RelationPredicate, ImmutableList<Integer>> extractUniqueConstraints() { return getDatabaseRelations().stream() .flatMap(this::extractUniqueConstraintsFromRelation) .collect(ImmutableCollectors.toMultimap()); }
private ImmutableMultimap<AtomPredicate, ImmutableList<Integer>> extractUniqueConstraints() { Map<Predicate, AtomPredicate> predicateCache = new HashMap<>(); return getDatabaseRelations().stream() .flatMap(relation -> extractUniqueConstraintsFromRelation(relation, predicateCache)) .collect(ImmutableCollectors.toMultimap()); }
/** * Predicates not having a DatabaseRelationDefinition are ignored */ private ImmutableMultimap<RelationDefinition, ExtensionalDataNode> extractDataNodeMap(IntermediateQuery query, InnerJoinNode joinNode) { return query.getChildren(joinNode).stream() .filter(c -> c instanceof ExtensionalDataNode) .map(c -> (ExtensionalDataNode) c) .map(c -> Maps.immutableEntry(c.getProjectionAtom().getPredicate().getRelationDefinition(), c)) .collect(ImmutableCollectors.toMultimap()); }
/** * *@param sigma * A set of ABox dependencies */ public CQContainmentCheckUnderLIDs(ImmutableList<LinearInclusionDependency> dependencies, DatalogFactory datalogFactory, UnifierUtilities unifierUtilities, SubstitutionUtilities substitutionUtilities, TermFactory termFactory) { // index dependencies this.dependencies = dependencies.stream() .collect(ImmutableCollectors.toMultimap( d -> d.getHead().getFunctionSymbol(), d -> d)); this.datalogFactory = datalogFactory; this.unifierUtilities = unifierUtilities; this.substitutionUtilities = substitutionUtilities; this.termFactory = termFactory; }
/** * Predicates not having a DatabaseRelationDefinition are ignored */ private ImmutableMultimap<DatabaseRelationDefinition, DataNode> extractDataNodeMap(IntermediateQuery query, InnerJoinNode joinNode) { DBMetadata dbMetadata = query.getDBMetadata(); return query.getChildren(joinNode).stream() .filter(c -> c instanceof DataNode) .map(c -> (DataNode) c) .map(c -> getDatabaseRelationByName(dbMetadata, c.getProjectionAtom().getPredicate()) .map(r -> new SimpleEntry<DatabaseRelationDefinition, DataNode>(r, c))) .filter(Optional::isPresent) .map(Optional::get) .collect(ImmutableCollectors.toMultimap()); }
/** * Produces a map from datatypeProperty to corresponding datatype according to the ontology (the datatype may * be inferred). * This is a rewriting of method: * it.unibz.inf.ontop.owlrefplatform.core.mappingprocessing.MappingDataTypeRepair#getDataTypeFromOntology * from Ontop v 1.18.1 */ private ImmutableMultimap<IRI, Datatype> computeDataTypeMap(ClassifiedTBox reasoner) { // TODO: switch to guava > 2.1, and replace by Streams.stream(iterable) return StreamSupport.stream(reasoner.dataRangesDAG().spliterator(), false) .flatMap(n -> getPartialPredicateToDatatypeMap(n, reasoner).entrySet().stream()) .collect(ImmutableCollectors.toMultimap( e -> e.getKey(), Map.Entry::getValue)); }
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; }
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; }
private ImmutableTable<RDFAtomPredicate, IRI, IQ> extractTable( ImmutableMap<IQ, MappingTools.RDFPredicateInfo> iqClassificationMap, boolean isClass) { ImmutableMultimap<Map.Entry<RDFAtomPredicate, IRI>, IQ> multimap = iqClassificationMap.entrySet().stream() .filter(e -> e.getValue().isClass() == isClass) .collect(ImmutableCollectors.toMultimap( e -> Maps.immutableEntry( (RDFAtomPredicate) e.getKey().getProjectionAtom().getPredicate(), e.getValue().getIri()), Map.Entry::getKey)); return multimap.asMap().entrySet().stream() .map(e -> Tables.immutableCell( e.getKey().getKey(), e.getKey().getValue(), mergeDefinitions(e.getValue()))) .collect(ImmutableCollectors.toTable()); }
private ImmutableMap<AtomPredicate, IntermediateQuery> mergeMappingMaps(ImmutableSet<Mapping> mappings) { ImmutableMap<AtomPredicate, Collection<IntermediateQuery>> atomPredicate2IQs = mappings.stream() .flatMap(m -> getMappingMap(m).entrySet().stream()) .collect(ImmutableCollectors.toMultimap()) .asMap(); return atomPredicate2IQs.entrySet().stream() .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> mergeDefinitions(e.getValue()) )); }
/** * Produces a map from datatypeProperty to corresponding datatype according to the ontology (the datatype may * be inferred). * This is a rewriting of method: * it.unibz.inf.ontop.owlrefplatform.core.mappingprocessing.MappingDataTypeRepair#getDataTypeFromOntology * from Ontop v 1.18.1 */ private ImmutableMultimap<String, Datatype> computeDataTypeMap(ClassifiedTBox reasoner) { // TODO: switch to guava > 2.1, and replace by Streams.stream(iterable) return StreamSupport.stream(reasoner.dataRangesDAG().spliterator(), false) .flatMap(n -> getPartialPredicateToDatatypeMap(n, reasoner).entrySet().stream()) .collect(ImmutableCollectors.toMultimap( e -> e.getKey().getName(), Map.Entry::getValue)); }
private PrefixManager mergePrefixManagers(ImmutableSet<Mapping> mappings) { ImmutableMap<String, Collection<String>> prefixToUris = mappings.stream() .flatMap(m -> m.getMetadata().getPrefixManager().getPrefixMap().entrySet().stream()) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableMap<String, String> prefixToUri = prefixToUris.entrySet().stream() .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> flattenURIList(e.getKey(), e.getValue()) )); return new SimplePrefixManager(prefixToUri); }
private ImmutableCollection<Collection<ExtensionalDataNode>> groupDataNodesPerConstraint( FunctionalDependency constraint, ImmutableCollection<ExtensionalDataNode> initialNodes) { ImmutableList<Integer> constraintDeterminantIndexes = constraint.getDeterminants().stream() .map(Attribute::getIndex) .collect(ImmutableCollectors.toList()); ImmutableMultimap<ImmutableList<VariableOrGroundTerm>, ExtensionalDataNode> nodeMultiMap = initialNodes.stream() .collect(ImmutableCollectors.toMultimap( n -> extractDeterminantArguments(n.getProjectionAtom(), constraintDeterminantIndexes), n -> n)); return nodeMultiMap.asMap().values(); }
private PrefixManager mergePrefixManagers(ImmutableSet<Mapping> mappings) { ImmutableMap<String, Collection<String>> prefixToUris = mappings.stream() .flatMap(m -> m.getMetadata().getPrefixManager().getPrefixMap().entrySet().stream()) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableMap<String, String> prefixToUri = prefixToUris.entrySet().stream() .collect(ImmutableCollectors.toMap( e -> e.getKey(), e -> flattenURIList(e.getKey(), e.getValue()) )); return new SimplePrefixManager(prefixToUri); }
@Override public VariableNullability getVariableNullability(ImmutableList<IQTree> children) { ImmutableMap<Variable, Collection<IQTree>> variableProvenanceMap = children.stream() .flatMap(c -> c.getVariables().stream() .map(v -> Maps.immutableEntry(v, c))) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableSet<Variable> coOccuringVariables = variableProvenanceMap.entrySet().stream() .filter(e -> e.getValue().size() > 1) .map(Map.Entry::getKey) .collect(ImmutableCollectors.toSet()); ImmutableSet<ImmutableSet<Variable>> nullableGroups = children.stream() .flatMap(c -> c.getVariableNullability().getNullableGroups().stream()) .filter(g -> g.stream() .noneMatch(coOccuringVariables::contains)) .collect(ImmutableCollectors.toSet()); return getOptionalFilterCondition() .map(e -> updateWithFilter(e, nullableGroups)) .orElseGet(() -> new VariableNullabilityImpl(nullableGroups)); }
private ImmutableCollection<Collection<DataNode>> groupDataNodesPerConstraint( FunctionalDependency constraint, ImmutableCollection<DataNode> initialNodes) { ImmutableList<Integer> constraintDeterminantIndexes = constraint.getDeterminants().stream() .map(Attribute::getIndex) .collect(ImmutableCollectors.toList()); ImmutableMultimap<ImmutableList<VariableOrGroundTerm>, DataNode> nodeMultiMap = initialNodes.stream() .collect(ImmutableCollectors.toMultimap( n -> extractDeterminantArguments(n.getProjectionAtom(), constraintDeterminantIndexes), n -> n)); return nodeMultiMap.asMap().values(); }
private ImmutableTable<RDFAtomPredicate, IRI, IQ> mergeMappingPropertyTables(ImmutableSet<Mapping> mappings) { ImmutableMap<Map.Entry<RDFAtomPredicate, IRI>, Collection<IQ>> multiTable = mappings.stream() .flatMap(m -> extractCellStream(m, p -> m.getRDFProperties(p).stream(), (p, i) -> m.getRDFPropertyDefinition(p, i).get())) .collect(ImmutableCollectors.toMultimap( c -> Maps.immutableEntry(c.getRowKey(), c.getColumnKey()), Table.Cell::getValue)) .asMap(); return multiTable.entrySet().stream() .map(e -> Tables.immutableCell( e.getKey().getKey(), e.getKey().getValue(), mergeDefinitions(e.getValue()))) .collect(ImmutableCollectors.toTable()); }
private ImmutableTable<RDFAtomPredicate, IRI, IQ> mergeMappingClassTables(ImmutableSet<Mapping> mappings) { ImmutableMap<Map.Entry<RDFAtomPredicate, IRI>, Collection<IQ>> multiTable = mappings.stream() .flatMap(m -> extractCellStream(m, p -> m.getRDFClasses(p).stream(), (p, i) -> m.getRDFClassDefinition(p, i).get())) .collect(ImmutableCollectors.toMultimap( c -> Maps.immutableEntry(c.getRowKey(), c.getColumnKey()), Table.Cell::getValue)) .asMap(); return multiTable.entrySet().stream() .map(e -> Tables.immutableCell( e.getKey().getKey(), e.getKey().getValue(), mergeDefinitions(e.getValue()))) .collect(ImmutableCollectors.toTable()); }
@Override public VariableNullability getVariableNullability(ImmutableList<IQTree> children) { ImmutableSet<VariableNullability> variableNullabilities = children.stream() .map(IQTree::getVariableNullability) .collect(ImmutableCollectors.toSet()); ImmutableMultimap<Variable, ImmutableSet<Variable>> multimap = variableNullabilities.stream() .flatMap(vn -> vn.getNullableGroups().stream()) .flatMap(g -> g.stream() .map(v -> Maps.immutableEntry(v, g))) .collect(ImmutableCollectors.toMultimap()); ImmutableMap<Variable, ImmutableSet<Variable>> preselectedGroupMap = multimap.asMap().entrySet().stream() .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> intersect(e.getValue()))); ImmutableSet<ImmutableSet<Variable>> nullableGroups = preselectedGroupMap.keySet().stream() .map(v -> computeNullableGroup(v, preselectedGroupMap, variableNullabilities)) .collect(ImmutableCollectors.toSet()); return new VariableNullabilityImpl(nullableGroups); }
@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); }