@Override public ImmutableSet<ImmutableSubstitution<NonVariableTerm>> getPossibleVariableDefinitions(IQTree child) { return child.getPossibleVariableDefinitions(); }
@Override public ImmutableSet<ImmutableSubstitution<NonVariableTerm>> getPossibleVariableDefinitions(IQTree child) { return child.getPossibleVariableDefinitions(); }
private static Stream<Constant> extractIRITemplates(Variable variable, IQTree tree) { return tree.getPossibleVariableDefinitions().stream() .map(s -> s.get(variable)) .filter(t -> !t.equals(variable)) .map(SameAsTargets::tryToExtractIRITemplateString) .filter(t -> t instanceof Constant) .map(t -> (Constant) t); }
@Override public ImmutableSet<ImmutableSubstitution<NonVariableTerm>> getPossibleVariableDefinitions( ImmutableList<IQTree> children) { return children.stream() .flatMap(c -> c.getPossibleVariableDefinitions().stream()) .map(s -> s.reduceDomainToIntersectionWith(projectedVariables)) .collect(ImmutableCollectors.toSet()); }
@Override public ImmutableSet<ImmutableSubstitution<NonVariableTerm>> getPossibleVariableDefinitions(IQTree child) { ImmutableSet<ImmutableSubstitution<NonVariableTerm>> childDefs = child.getPossibleVariableDefinitions(); if (childDefs.isEmpty()) { ImmutableSubstitution<NonVariableTerm> def = substitution.getNonVariableTermFragment(); return def.isEmpty() ? ImmutableSet.of() : ImmutableSet.of(def); } return childDefs.stream() .map(childDef -> childDef.composeWith(substitution)) .map(s -> s.reduceDomainToIntersectionWith(projectedVariables)) .map(ImmutableSubstitution::getNonVariableTermFragment) .collect(ImmutableCollectors.toSet()); }
/** * Returns possible definitions for left and right-specific variables. */ @Override public ImmutableSet<ImmutableSubstitution<NonVariableTerm>> getPossibleVariableDefinitions(IQTree leftChild, IQTree rightChild) { ImmutableSet<ImmutableSubstitution<NonVariableTerm>> leftDefs = leftChild.getPossibleVariableDefinitions(); ImmutableSet<Variable> rightSpecificVariables = Sets.difference(rightChild.getVariables(), leftChild.getVariables()) .immutableCopy(); ImmutableSet<ImmutableSubstitution<NonVariableTerm>> rightDefs = leftChild.getPossibleVariableDefinitions().stream() .map(s -> s.reduceDomainToIntersectionWith(rightSpecificVariables)) .collect(ImmutableCollectors.toSet()); if (leftDefs.isEmpty()) return rightDefs; else if (rightDefs.isEmpty()) return leftDefs; else return leftDefs.stream() .flatMap(l -> rightDefs.stream() .map(r -> combine(l, r))) .collect(ImmutableCollectors.toSet()); }
public static RDFPredicateInfo extractRDFPredicate(IQ mappingAssertion) { DistinctVariableOnlyDataAtom projectionAtom = mappingAssertion.getProjectionAtom(); RDFAtomPredicate rdfAtomPredicate = Optional.of(projectionAtom.getPredicate()) .filter(p -> p instanceof RDFAtomPredicate) .map(p -> (RDFAtomPredicate) p) .orElseThrow(() -> new MappingPredicateIRIExtractionException("The following mapping assertion " + "is not having a RDFAtomPredicate: " + mappingAssertion)); ImmutableSet<ImmutableList<? extends ImmutableTerm>> possibleSubstitutedArguments = mappingAssertion.getTree().getPossibleVariableDefinitions().stream() .map(s -> s.apply(projectionAtom.getArguments())) .collect(ImmutableCollectors.toSet()); IRI propertyIRI = extractIRI(possibleSubstitutedArguments, rdfAtomPredicate::getPropertyIRI); return propertyIRI.equals(RDF.TYPE) ? new RDFPredicateInfo(true, extractIRI(possibleSubstitutedArguments, rdfAtomPredicate::getClassIRI)) : new RDFPredicateInfo(false, propertyIRI); }