public static VariableOrGroundTerm convertIntoVariableOrGroundTerm(Term term) { if (term instanceof Variable) { return (Variable) term; } else if (GroundTermTools.isGroundTerm(term)) { return GroundTermTools.castIntoGroundTerm(term); } else { throw new IllegalArgumentException("Not a variable nor a ground term: " + term); } }
protected GroundFunctionalTermImpl(Predicate functor, List<? extends ImmutableTerm> terms) throws GroundTermTools.NonGroundTermException { this(GroundTermTools.castIntoGroundTerms(terms), functor); }
protected NonGroundExpressionImpl(OperationPredicate functor, ImmutableList<? extends ImmutableTerm> terms) { super(functor, terms); checkNonGroundTermConstraint(this); }
protected GroundExpressionImpl(Expression expression) { super(expression); if (!GroundTermTools.isGroundTerm(expression)) { throw new IllegalArgumentException("Non-ground boolean expression given to build a ground expression!"); } }
public static ImmutableList<GroundTerm> castIntoGroundTerms(List<? extends Term> terms) throws NonGroundTermException { ImmutableList.Builder<GroundTerm> termBuilder = ImmutableList.builder(); for (Term term : terms) { termBuilder.add(castIntoGroundTerm(term)); } return termBuilder.build(); }
@Override public boolean isGround() { return areGroundTerms(getArguments()); } }
@Override public ImmutableExpression getImmutableExpression(Expression expression) { if (GroundTermTools.isGroundTerm(expression)) { return new GroundExpressionImpl(expression); } else { return new NonGroundExpressionImpl(expression); } }
public static ImmutableList<GroundTerm> castIntoGroundTerms(List<? extends Term> terms) throws NonGroundTermException { ImmutableList.Builder<GroundTerm> termBuilder = ImmutableList.builder(); for (Term term : terms) { termBuilder.add(castIntoGroundTerm(term)); } return termBuilder.build(); }
@Override public ImmutableExpression getImmutableExpression(OperationPredicate functor, ImmutableList<? extends ImmutableTerm> arguments) { if (GroundTermTools.areGroundTerms(arguments)) { return new GroundExpressionImpl(functor, (ImmutableList<GroundTerm>)arguments); } else { return new NonGroundExpressionImpl(functor, arguments); } }
public static VariableOrGroundTerm convertIntoVariableOrGroundTerm(Term term) { if (term instanceof Variable) { return (Variable) term; } else if (GroundTermTools.isGroundTerm(term)) { return GroundTermTools.castIntoGroundTerm(term); } else { throw new IllegalArgumentException("Not a variable nor a ground term: " + term); } }
@Override public ImmutableFunctionalTerm getImmutableFunctionalTerm(Function functionalTerm) { if (GroundTermTools.isGroundTerm(functionalTerm)) { return new GroundFunctionalTermImpl(functionalTerm); } else { return new NonGroundFunctionalTermImpl(functionalTerm); } }
protected NonGroundExpressionImpl(OperationPredicate functor, ImmutableTerm... terms) { super(functor, terms); checkNonGroundTermConstraint(this); }
@Override public ImmutableExpression getImmutableExpression(OperationPredicate functor, ImmutableList<? extends ImmutableTerm> arguments) { if (GroundTermTools.areGroundTerms(arguments)) { return new GroundExpressionImpl(functor, (ImmutableList<GroundTerm>)arguments); } else { return new NonGroundExpressionImpl(functor, arguments); } }
public GroundFunctionalTermImpl(Function functionalTermToClone) throws GroundTermTools.NonGroundTermException { this(functionalTermToClone.getFunctionSymbol(), GroundTermTools.castIntoGroundTerms(functionalTermToClone.getTerms())); }
else if (isGroundTerm(term)) { Variable newVariable = projectedVariableGenerator.generateNewVariable(); newArgument = newVariable; bindingBuilder.put(newVariable, castIntoGroundTerm(term));
if (isGroundTerm(sourceFunctionalTerm)) { if (sourceFunctionalTerm.equals(targetFunctionalTerm)) { return Optional.of(EMPTY_SUBSTITUTION);
protected NonGroundFunctionalTermImpl(FunctionSymbol functor, ImmutableList<? extends ImmutableTerm> terms) { super(functor, terms); checkNonGroundTermConstraint(this); }
@Override public ImmutableFunctionalTerm getImmutableFunctionalTerm(FunctionSymbol functor, ImmutableList<? extends ImmutableTerm> terms) { if (functor instanceof OperationPredicate) { return getImmutableExpression((OperationPredicate)functor, terms); } if (GroundTermTools.areGroundTerms(terms)) { return new GroundFunctionalTermImpl((ImmutableList<? extends GroundTerm>)terms, functor); } else { // Default constructor return new NonGroundFunctionalTermImpl(functor, terms); } }
public static GroundTerm castIntoGroundTerm(Term term) throws NonGroundTermException{ if (term instanceof GroundTerm) return (GroundTerm) term; if (term instanceof Function) { Function functionalTerm = (Function) term; // Recursive FunctionSymbol functionSymbol = Optional.of(functionalTerm.getFunctionSymbol()) .filter(p -> p instanceof FunctionSymbol) .map(p -> (FunctionSymbol)p) .orElseThrow(() -> new NonGroundTermException(term + "is not using a function symbol but a" + functionalTerm.getFunctionSymbol().getClass())); return new GroundFunctionalTermImpl(castIntoGroundTerms(functionalTerm.getTerms()), functionSymbol); } throw new NonGroundTermException(term + " is not a ground term"); }
else if (isGroundTerm(term)) { Variable newVariable = projectedVariableGenerator.generateNewVariable(); newArgument = newVariable; bindingBuilder.put(newVariable, castIntoGroundTerm(term));