private IQTree createJoinSubtree(int childIndex, IQTree unionGrandChild, ImmutableList<IQTree> initialChildren) { return iqFactory.createNaryIQTree(this, IntStream.range(0, initialChildren.size()) .boxed() .map(i -> i == childIndex ? unionGrandChild : initialChildren.get(i)) .collect(ImmutableCollectors.toList())); }
public static ImmutableList<IRI> validate(ImmutableList<TargetAtom> targetQuery, MutableOntologyVocabulary vocabulary) { return targetQuery.stream() .map(TargetQueryValidator::extractIRI) .filter(iri -> !isValid(iri, vocabulary)) .collect(ImmutableCollectors.toList()); }
protected URITemplatePredicateImpl(int arity, String suffix, TypeFactory typeFactory) { super(URI_PREFIX + arity + suffix, IntStream.range(0, arity) .boxed() // TODO: require strings .map(i -> typeFactory.getAbstractAtomicTermType()) .collect(ImmutableCollectors.toList())); type = typeFactory.getIRITermType(); }
@Override public AtomPredicate getRDFAnswerPredicate(int arity) { ImmutableList<TermType> defaultBaseTypes = IntStream.range(0, arity).boxed() .map(i -> typeFactory.getAbstractRDFTermType()) .collect(ImmutableCollectors.toList()); return new AtomPredicateImpl(PredicateConstants.ONTOP_QUERY, defaultBaseTypes); }
@Override public TermTypeAncestry newAncestry(TermType childType) { ImmutableList<TermType> newAncestors = Stream.concat(Stream.of(childType), getTermTypes()) .collect(ImmutableCollectors.toList()); return new TermTypeAncestryImpl(newAncestors); }
@Override public IQTree propagateDownConstraint(ImmutableExpression constraint, ImmutableList<IQTree> children) { return iqFactory.createNaryIQTree(this, children.stream() .map(c -> c.propagateDownConstraint(constraint)) .collect(ImmutableCollectors.toList())); }
private Stream<Map.Entry<RelationPredicate, ImmutableList<Integer>>> extractUniqueConstraintsFromRelation( DatabaseRelationDefinition relation) { return relation.getUniqueConstraints().stream() .map(uc -> uc.getAttributes().stream() .map(Attribute::getIndex) .collect(ImmutableCollectors.toList())) .map(positions -> new AbstractMap.SimpleEntry<>(relation.getAtomPredicate(), positions)); }
private DataAtom<RelationPredicate> computeNewRightAtom(RelationPredicate predicate, ImmutableList<? extends VariableOrGroundTerm> rightArguments, ImmutableList<Integer> conflictingRightArgumentIndexes, VariableGenerator variableGenerator) { ImmutableList<VariableOrGroundTerm> newArguments = IntStream.range(0, rightArguments.size()) .boxed() .map(i -> conflictingRightArgumentIndexes.contains(i) ? variableGenerator.generateNewVariable() : rightArguments.get(i)) .collect(ImmutableCollectors.toList()); return atomFactory.getDataAtom(predicate, newArguments); }
/** * Renames the projected variables */ private DistinctVariableOnlyDataAtom transformProjectionAtom(DistinctVariableOnlyDataAtom atom) { ImmutableList<Variable> newArguments = atom.getArguments().stream() .map(renamingSubstitution::applyToVariable) .collect(ImmutableCollectors.toList()); return atomFactory.getDistinctVariableOnlyDataAtom(atom.getPredicate(), newArguments); }
/** * Renames the projected variables */ @Override protected DistinctVariableOnlyDataAtom transformProjectionAtom(DistinctVariableOnlyDataAtom atom) { ImmutableList<Variable> newArguments = atom.getArguments().stream() .map(renamingSubstitution::applyToVariable) .collect(ImmutableCollectors.toList()); return ATOM_FACTORY.getDistinctVariableOnlyDataAtom(atom.getPredicate(), newArguments); } }
@Override public ImmutableCollection<IQ> getQueries(RDFAtomPredicate rdfAtomPredicate) { return Stream.concat(classDefinitions.row(rdfAtomPredicate).values().stream(), propertyDefinitions.row(rdfAtomPredicate).values().stream()) .collect(ImmutableCollectors.toList()); }
@Override public IQTree applyDescendingSubstitutionWithoutOptimizing( ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, ImmutableList<IQTree> children) { ImmutableSet<Variable> updatedProjectedVariables = constructionTools.computeNewProjectedVariables( descendingSubstitution, projectedVariables); ImmutableList<IQTree> updatedChildren = children.stream() .map(c -> c.applyDescendingSubstitutionWithoutOptimizing(descendingSubstitution)) .collect(ImmutableCollectors.toList()); UnionNode newRootNode = iqFactory.createUnionNode(updatedProjectedVariables); return iqFactory.createNaryIQTree(newRootNode, updatedChildren); }
@Override public IQTree replaceSubTree(IQTree subTreeToReplace, IQTree newSubTree) { if (equals(subTreeToReplace)) return newSubTree; ImmutableList<IQTree> newChildren = getChildren().stream() .map(c -> c.replaceSubTree(subTreeToReplace, newSubTree)) .collect(ImmutableCollectors.toList()); return iqFactory.createNaryIQTree(getRootNode(), newChildren); }
@Override public List<Function> visitPredicateObject(PredicateObjectContext ctx) { return visitObjectList(ctx.objectList()).stream() .map(t -> makeAtom(currentSubject, visitVerb(ctx.verb()), t)) .collect(ImmutableCollectors.toList()); }
@Override public void visit(AndExpression expression) { ImmutableList<Function> left = translate(expression.getLeftExpression()); ImmutableList<Function> right = translate(expression.getRightExpression()); ImmutableList<Function> and = Stream.of(left, right).flatMap(Collection::stream) .collect(ImmutableCollectors.toList()); result = (expression.isNot()) ? ImmutableList.of(negation(getAND(and))) : and; }
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 Optional<IQ> extractCanIRIDefinition(MappingWithProvenance mapping) { return queryMerger.mergeDefinitions( mapping.getProvenanceMap().keySet().stream() .filter(q -> (MappingTools.extractRDFPredicate(q).getIri().equals(Ontop.CANONICAL_IRI))) .collect(ImmutableCollectors.toList())); }
@Override public IntermediateQuery transform(IntermediateQuery query) throws NotFilterableNullVariableException { QueryNode rootNode = query.getRootNode(); ImmutableList<Variable> nullableProjectedVariables = query.getProjectionAtom().getVariables().stream() .filter(v -> rootNode.isVariableNullable(query, v)) .collect(ImmutableCollectors.toList()); if (nullableProjectedVariables.isEmpty()) return query; ImmutableExpression filterCondition = extractFilteringCondition(query, rootNode, nullableProjectedVariables); return constructQuery(query, rootNode, filterCondition); }
@Override public Mapping rewrite(Mapping mapping, DBMetadata dbMetadata) { if(enabled){ ImmutableList<CQIE> rules = mapping2DatalogConverter.convert(mapping) .collect(ImmutableCollectors.toList()); ImmutableList<CQIE> updatedRules = MappingSameAs.addSameAsInverse(rules); return datalog2MappingConverter.convertMappingRules(updatedRules, dbMetadata, mapping.getExecutorRegistry(), mapping.getMetadata()); } return mapping; } }
private ImmutableList<IQ> normalizeIQ(IQ query) { IQTree tree = query.getTree(); while(tree.getRootNode() instanceof QueryModifierNode){ tree = ((UnaryIQTree)tree).getChild(); } return splitRootUnion(tree) .map(t -> enforceRootCn(t, query.getProjectionAtom().getVariables())) .map(t -> iqFactory.createIQ(query.getProjectionAtom(), t)) .collect(ImmutableCollectors.toList()); }