/** * Checks if the atom is unary or not. */ private static boolean isUnary(DataAtom atom) { return atom.getArity() == 1; }
default <T extends ImmutableTerm> ImmutableList<T> updateObject(ImmutableList<T> originalArguments, T newObject) { return updateSPO(originalArguments, getSubject(originalArguments), getProperty(originalArguments), newObject); } }
default <T extends ImmutableTerm> ImmutableList<T> updateSO(ImmutableList<T> originalArguments, T newSubject, T newObject) { return updateSPO(originalArguments, newSubject, getProperty(originalArguments), newObject); }
/** * 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); }
private Variable getVarFromRDFAtom(DistinctVariableOnlyDataAtom atom, Position position) { switch (position) { case SUBJECT: return getRDFAtomPredicate(atom).getSubject(atom.getArguments()); case OBJECT: return getRDFAtomPredicate(atom).getObject(atom.getArguments()); case PROPERTY: return getRDFAtomPredicate(atom).getProperty(atom.getArguments()); default: throw new UnexpectedPositionException(position); } }
@Override public DataAtom applyToDataAtom(DataAtom atom) throws ConversionException { ImmutableList<? extends ImmutableTerm> newArguments = apply(atom.getArguments()); for (ImmutableTerm subTerm : newArguments) { if (!(subTerm instanceof VariableOrGroundTerm)) throw new ConversionException("The sub-term: " + subTerm + " is not a VariableOrGroundTerm"); } return atomFactory.getDataAtom(atom.getPredicate(), (ImmutableList<? extends VariableOrGroundTerm>) newArguments); }
private Optional<IRI> getPropertyIRI(DataAtom atom) { AtomPredicate atomPredicate = atom.getPredicate(); return Optional.of(atomPredicate) .filter(p -> p instanceof RDFAtomPredicate) .map(p -> (RDFAtomPredicate) p) .flatMap(p -> p.getPropertyIRI(atom.getArguments())); }
@Override public Optional<IntermediateQuery> getDefinition(AtomPredicate predicate) { IntermediateQuery query = definitions.get(predicate); return query != null && query.getProjectionAtom().getPredicate().getArity() == predicate.getArity()? Optional.of(query): Optional.empty(); }
@Override public Optional<IRI> getPredicateIRI() { return Optional.of(atom.getPredicate()) .filter(p -> p instanceof RDFAtomPredicate) .map(p -> (RDFAtomPredicate) p) .flatMap(p -> p.getPredicateIRI(getSubstitutedTerms())); }
default <T extends ImmutableTerm> ImmutableList<T> updateSubject(ImmutableList<T> originalArguments, T newSubject) { return updateSPO(originalArguments, newSubject, getProperty(originalArguments), getObject(originalArguments)); }
private String extractPredicateIRI(IntermediateQuery mappingAssertion) { AtomPredicate projectionAtomPredicate = mappingAssertion.getProjectionAtom().getPredicate(); if (projectionAtomPredicate.equals(PredicateImpl.QUEST_TRIPLE_PRED)) throw new RuntimeException("TODO: extract the RDF predicate from a triple atom"); else return projectionAtomPredicate.getName(); }
private TargetAtom getAtom(IRI iri, ImmutableTerm s, ImmutableTerm o) { return targetAtomFactory.getTripleTargetAtom(s, convertIRIIntoGroundFunctionalTerm(iri), o); }
@Override public int getArity() { return predicate.getArity(); }
private ImmutableList<Variable> replaceProjVars(RDFAtomPredicate pred, ImmutableList<Variable> arguments, Position pos, Variable replacementVar) { switch (pos) { case SUBJECT: return pred.updateSubject(arguments, replacementVar); case OBJECT: return pred.updateObject(arguments, replacementVar); case PROPERTY: default: throw new UnexpectedPositionException(pos); } }
private IntensionalDataNode getIDN(Variable formerVariable, Variable newVariable) { return iqFactory.createIntensionalDataNode( atomFactory.getIntensionalTripleAtom( newVariable, Ontop.CANONICAL_IRI, formerVariable )); }
@Override public ImmutableTerm getSubstitutedTerm(int index) { return substitution.apply(atom.getTerm(index)); }
/** * 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); } }
private DataAtom renameDataAtom(DataAtom atom) { ImmutableList.Builder<VariableOrGroundTerm> argListBuilder = ImmutableList.builder(); for (VariableOrGroundTerm term : atom.getArguments()) { argListBuilder.add(renamingSubstitution.applyToTerm(term)); } return ATOM_FACTORY.getDataAtom(atom.getPredicate(), argListBuilder.build()); }
private TargetAtom getAtom(IRI iri, ImmutableTerm s) { return targetAtomFactory.getTripleTargetAtom(s, convertIRIIntoGroundFunctionalTerm(RDF.TYPE), convertIRIIntoGroundFunctionalTerm(iri)); }
private DataAtom renameDataAtom(DataAtom<? extends AtomPredicate> atom) { ImmutableList.Builder<VariableOrGroundTerm> argListBuilder = ImmutableList.builder(); for (VariableOrGroundTerm term : atom.getArguments()) { argListBuilder.add(renamingSubstitution.applyToTerm(term)); } return atomFactory.getDataAtom(atom.getPredicate(), argListBuilder.build()); }