/** * When such substitution DO NOT EXIST, returns an EMPTY OPTIONAL. * When NO renaming is NEEDED returns an EMPTY SUBSTITUTION. * */ private static Optional<InjectiveVar2VarSubstitution> computeRenamingSubstitution( DistinctVariableOnlyDataAtom sourceProjectionAtom, DistinctVariableOnlyDataAtom targetProjectionAtom) { int arity = sourceProjectionAtom.getEffectiveArity(); if (!sourceProjectionAtom.getPredicate().equals(targetProjectionAtom.getPredicate()) || (arity != targetProjectionAtom.getEffectiveArity())) { return Optional.empty(); } else { ImmutableMap<Variable, Variable> newMap = FunctionalTools.zip( sourceProjectionAtom.getArguments(), targetProjectionAtom.getArguments()).stream() .distinct() .filter(e -> !e.getKey().equals(e.getValue())) .collect(ImmutableCollectors.toMap()); return Optional.of(SUBSTITUTION_FACTORY.getInjectiveVar2VarSubstitution(newMap)); } }
/** * When such substitution DO NOT EXIST, returns an EMPTY OPTIONAL. * When NO renaming is NEEDED returns an EMPTY SUBSTITUTION. * */ private Optional<InjectiveVar2VarSubstitution> computeRenamingSubstitution( DistinctVariableOnlyDataAtom sourceProjectionAtom, DistinctVariableOnlyDataAtom targetProjectionAtom) { int arity = sourceProjectionAtom.getEffectiveArity(); if (!sourceProjectionAtom.getPredicate().equals(targetProjectionAtom.getPredicate()) || (arity != targetProjectionAtom.getEffectiveArity())) { return Optional.empty(); } else { ImmutableMap<Variable, Variable> newMap = FunctionalTools.zip( sourceProjectionAtom.getArguments(), targetProjectionAtom.getArguments()).stream() .distinct() .filter(e -> !e.getKey().equals(e.getValue())) .collect(ImmutableCollectors.toMap()); return Optional.of(substitutionFactory.getInjectiveVar2VarSubstitution(newMap)); } } }
private static ImmutableSubstitution<VariableOrGroundTerm> extractSubstitution(DistinctVariableOnlyDataAtom sourceAtom, DataAtom targetAtom) { if (!sourceAtom.getPredicate().equals(targetAtom.getPredicate())) { throw new IllegalStateException("Incompatible predicates"); } else if (sourceAtom.getEffectiveArity() != targetAtom.getEffectiveArity()) { throw new IllegalStateException("Different arities"); } ImmutableMap<Variable, VariableOrGroundTerm> newMap = FunctionalTools.zip( sourceAtom.getArguments(), (ImmutableList<VariableOrGroundTerm>) targetAtom.getArguments()).stream() .collect(ImmutableCollectors.toMap()); return SUBSTITUTION_FACTORY.getSubstitution(newMap); }
private ImmutableSubstitution<VariableOrGroundTerm> extractSubstitution(DistinctVariableOnlyDataAtom sourceAtom, DataAtom targetAtom) { if (!sourceAtom.getPredicate().equals(targetAtom.getPredicate())) { throw new IllegalStateException("Incompatible predicates"); } else if (sourceAtom.getEffectiveArity() != targetAtom.getEffectiveArity()) { throw new IllegalStateException("Different arities"); } ImmutableMap<Variable, VariableOrGroundTerm> newMap = FunctionalTools.zip( sourceAtom.getArguments(), (ImmutableList<VariableOrGroundTerm>) targetAtom.getArguments()).stream() .collect(ImmutableCollectors.toMap()); return substitutionFactory.getSubstitution(newMap); } }