@Override public Optional<InjectiveVar2VarSubstitution> composeWithAndPreserveInjectivity( InjectiveVar2VarSubstitution g, Set<Variable> variablesToExcludeFromTheDomain) { ImmutableMap<Variable, Variable> newMap = composeRenaming(g) // Removes some excluded entries .filter(e -> !variablesToExcludeFromTheDomain.contains(e.getKey())) .collect(ImmutableCollectors.toMap()); return Optional.of(newMap) .filter(InjectiveVar2VarSubstitutionImpl::isInjective) .map(substitutionFactory::getInjectiveVar2VarSubstitution); }
@Override public Var2VarSubstitution getVar2VarFragment() { ImmutableMap<Variable, Variable> newMap = map.entrySet().stream() .filter(e -> e.getValue() instanceof Variable) .collect(ImmutableCollectors.toMap(Map.Entry::getKey, e -> (Variable)e.getValue())); return substitutionFactory.getVar2VarSubstitution(newMap); }
@Override public ImmutableSubstitution<GroundTerm> getGroundTermFragment() { ImmutableMap<Variable, GroundTerm> newMap = map.entrySet().stream() .filter(e -> e.getValue() instanceof GroundTerm) .collect(ImmutableCollectors.toMap(Map.Entry::getKey, e -> (GroundTerm)e.getValue())); return substitutionFactory.getSubstitution(newMap); }
@Override public void visit(AllColumns allColumns) { map = attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() == null) .collect(ImmutableCollectors.toMap()); }
public ImmutableMap<QualifiedAttributeID, Term> expandStar(ImmutableMap<QualifiedAttributeID, Term> attributes) { return attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() == null) .collect(ImmutableCollectors.toMap()); }
@Override public ImmutableSubstitution<ImmutableTerm> normalizeValues() { return substitutionFactory.getSubstitution(getImmutableMap().entrySet().stream() .map(e -> Maps.immutableEntry(e.getKey(), (ImmutableTerm) e.getValue())) .map(this::applyNullNormalization) .collect(ImmutableCollectors.toMap())); }
@Override public ImmutableMap<CQIE, PPMappingAssertionProvenance> convert(MappingWithProvenance mappingWithProvenance) { return mappingWithProvenance.getProvenanceMap().entrySet().stream() .flatMap(e -> convertMappingQuery(e.getKey()) .map(r -> new AbstractMap.SimpleEntry<>(r, e.getValue()))) .collect(ImmutableCollectors.toMap()); }
/** * TODO: refactor so as to work with quads */ private static ImmutableMap<IRI, VocabularyEntry> extractVocabulary(@Nonnull Mapping mapping) { return mapping.getRDFAtomPredicates().stream() .filter(p -> p instanceof TriplePredicate) .map(p -> (TriplePredicate) p) .findFirst() .map(p -> extractTripleVocabulary(mapping, p) .collect(ImmutableCollectors.toMap(e -> e.name, e -> e))) .orElseGet(ImmutableMap::of); }
private ImmutableSubstitution<ImmutableTerm> mergeChildSubstitutions( ImmutableSet<Variable> projectedVariables, ImmutableCollection<ImmutableSubstitution<ImmutableTerm>> childSubstitutions, VariableGenerator variableGenerator) { ImmutableMap<Variable, ImmutableTerm> substitutionMap = projectedVariables.stream() .flatMap(v -> mergeDefinitions(v, childSubstitutions, variableGenerator) .map(d -> Stream.of(new SimpleEntry<>(v, d))) .orElseGet(Stream::empty)) .collect(ImmutableCollectors.toMap()); return substitutionFactory.getSubstitution(substitutionMap); }
@Override public ImmutableSubstitution<VariableOrGroundTerm> getVariableOrGroundTermFragment() { ImmutableMap<Variable, VariableOrGroundTerm> newMap = getImmutableMap().entrySet().stream() .filter(e -> e.getValue() instanceof VariableOrGroundTerm) .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> (VariableOrGroundTerm) e.getValue())); return substitutionFactory.getSubstitution(newMap); }
@Override public ImmutableSubstitution<GroundFunctionalTerm> getGroundFunctionalTermFragment() { ImmutableMap<Variable, GroundFunctionalTerm> newMap = getImmutableMap().entrySet().stream() .filter(e -> e.getValue() instanceof GroundFunctionalTerm) .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> (GroundFunctionalTerm) e.getValue())); return substitutionFactory.getSubstitution(newMap); }
private VariableNullability updateVariableNullability( ImmutableSubstitution<ImmutableTerm> nonNestedSubstitution, VariableNullability childNullability) { // TODO: find a better name ImmutableMap<Variable, Variable> nullabilityBindings = nonNestedSubstitution.getImmutableMap().entrySet().stream() .flatMap(e -> evaluateTermNullability(e.getValue(), childNullability, e.getKey()) .map(Stream::of) .orElseGet(Stream::empty)) .collect(ImmutableCollectors.toMap()); return childNullability.appendNewVariables(nullabilityBindings); }
private InjectiveVar2VarSubstitution computeOtherChildrenRenaming(ImmutableSubstitution<ImmutableFunctionalTerm> nonDownPropagatedFragment, ImmutableSet<Variable> otherChildrenVariables, VariableGenerator variableGenerator) { ImmutableMap<Variable, Variable> substitutionMap = nonDownPropagatedFragment.getImmutableMap().keySet().stream() .filter(otherChildrenVariables::contains) .collect(ImmutableCollectors.toMap( v -> v, variableGenerator::generateNewVariableFromVar)); return substitutionFactory.getInjectiveVar2VarSubstitution(substitutionMap); }
@Override public MaterializedGraphResultSet materialize(@Nonnull OntopSystemConfiguration configuration, @Nonnull ImmutableSet<IRI> selectedVocabulary, @Nonnull MaterializationParams params) throws OBDASpecificationException { OBDASpecification obdaSpecification = configuration.loadSpecification(); ImmutableMap<IRI, VocabularyEntry> vocabularyMap = extractVocabulary(obdaSpecification.getSaturatedMapping()).entrySet().stream() .filter(e -> selectedVocabulary.contains(e.getKey())) .collect(ImmutableCollectors.toMap()); return apply(obdaSpecification, vocabularyMap, params, configuration); }
/** * Can be overloaded by sub-classes */ @Override protected ImmutableMap<Class<? extends QueryOptimizationProposal>, Class<? extends ProposalExecutor>> generateOptimizationConfigurationMap() { return Stream.concat( super.generateOptimizationConfigurationMap().entrySet().stream(), systemConfiguration.generateOptimizationConfigurationMap().entrySet().stream()) .distinct() .collect(ImmutableCollectors.toMap()); }
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()) )); }
public ImmutableMap<QualifiedAttributeID, Term> expandStar(ImmutableMap<QualifiedAttributeID, Term> attributes, Table table) { RelationID id = idfac.createRelationID(table.getSchemaName(), table.getName()); return attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() != null && e.getKey().getRelation().equals(id)) .collect(ImmutableCollectors.toMap( e -> new QualifiedAttributeID(null, e.getKey().getAttribute()), 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); }
@Override public void visit(AllColumns allColumns) { builder.putAll(sqae.expandStar(attributes).keySet().stream() .collect(ImmutableCollectors.toMap( id -> id.getAttribute(), id -> new SelectExpressionItem(new Column(id.getAttribute().getSQLRendering()))))); }
@Override public void visit(AllTableColumns allTableColumns) { Table table = allTableColumns.getTable(); builder.putAll(sqae.expandStar(attributes, table).keySet().stream() .collect(ImmutableCollectors.toMap( id -> id.getAttribute(), id -> new SelectExpressionItem(new Column(table, id.getAttribute().getSQLRendering()))))); }