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); }
private DataAtom computeNewRightAtom(AtomPredicate 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 ATOM_FACTORY.getDataAtom(predicate, newArguments); }
private <P extends AtomPredicate> DataAtom<P> replaceVars(DataAtom<P> projectionAtom, ImmutableList<Optional<Variable>> replacements) { Iterator<Optional<Variable>> it = replacements.iterator(); return atomFactory.getDataAtom( projectionAtom.getPredicate(), projectionAtom.getArguments().stream() .map(a -> { Optional<Variable> r = it.next(); return r.isPresent() ? r.get() : a; }) .collect(ImmutableCollectors.toList()) ); }
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()); }
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()); }
/** * TODO: explain */ private DataAtom generateNewStandardDataAtom(DataNode originalFocusNode, ImmutableMap<Integer, VariableRenaming> renamingMap) { DataAtom formerAtom = originalFocusNode.getProjectionAtom(); ImmutableList<? extends VariableOrGroundTerm> formerArguments = formerAtom.getArguments(); ImmutableList.Builder<VariableOrGroundTerm> newArgumentBuilder = ImmutableList.builder(); for (int i = 0; i < formerArguments.size(); i++) { if (renamingMap.containsKey(i)) { VariableRenaming variableRenaming = renamingMap.get(i); newArgumentBuilder.add(variableRenaming.newVariable); } else { newArgumentBuilder.add(formerArguments.get(i)); } } return ATOM_FACTORY.getDataAtom(formerAtom.getPredicate(), newArgumentBuilder.build()); }
protected DataNode generateDataNode(DataNode formerDataNode, ImmutableList<VariableOrGroundTerm> arguments) { DataAtom dataAtom = ATOM_FACTORY.getDataAtom(formerDataNode.getProjectionAtom().getPredicate(), arguments); if (formerDataNode instanceof ExtensionalDataNode) { return iqFactory.createExtensionalDataNode(dataAtom); } else if (formerDataNode instanceof IntensionalDataNode) { return iqFactory.createIntensionalDataNode(dataAtom); } else { throw new RuntimeException("Transformation of a data node of type " + formerDataNode.getClass() + " is not supported yet"); } }
@Override public DataAtom applyToDataAtom(DataAtom atom) throws ConversionException { ImmutableFunctionalTerm newFunctionalTerm = applyToFunctionalTerm(atom); if (newFunctionalTerm instanceof DataAtom) return (DataAtom) newFunctionalTerm; AtomPredicate predicate = (AtomPredicate) newFunctionalTerm.getFunctionSymbol(); /** * Casts all the sub-terms into VariableOrGroundTerm * * Throws a ConversionException if this cast is impossible. */ ImmutableList.Builder<VariableOrGroundTerm> argBuilder = ImmutableList.builder(); for (ImmutableTerm subTerm : newFunctionalTerm.getArguments()) { if (!(subTerm instanceof VariableOrGroundTerm)) throw new ConversionException("The sub-term: " + subTerm + " is not a VariableOrGroundTerm"); argBuilder.add((VariableOrGroundTerm)subTerm); } return ATOM_FACTORY.getDataAtom(predicate, argBuilder.build()); }
@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); }