/** * Incompatibility detected in an expression */ public IncompatibleTermException(Expression expression, IncompatibleTermException caughtException) { super("In " + expression + ": " + caughtException.getMessage()); }
/** * Checks that all the terms are numeric */ protected void doAdditionalChecks(ImmutableList<Optional<TermType>> argumentTypes) throws IncompatibleTermException { IntStream.range(0, argumentTypes.size()) .forEach(i -> { if(!argumentTypes.get(i) .map(t -> NUMERIC_TYPES.contains(t.getColType())) .orElse(true)) { throw new IncompatibleTermException("numeric term", argumentTypes.get(i).get()); } }); }
/** * Incompatibility detected in an expression */ public IncompatibleTermException(ImmutableExpression expression, IncompatibleTermException caughtException) { super("In " + expression + ": " + caughtException.getMessage()); }
default Optional<TermType> getOptionalTermType(ImmutableList<Optional<TermType>> actualArgumentTypes) { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.inferTypeFromArgumentTypes(actualArgumentTypes); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } } }
/** * Incompatibility detected in an expression */ public IncompatibleTermException(Expression expression, IncompatibleTermException caughtException) { super("In " + expression + ": " + caughtException.getMessage()); } }
@Override public Optional<TermType> inferTypeFromArgumentTypes(ImmutableList<Optional<TermType>> argumentTypes, ImmutableList<Optional<Predicate.COL_TYPE>> expectedBaseTypes) throws IncompatibleTermException { /** * TODO: restore inequality test between the arities */ if (expectedBaseTypes.size() < argumentTypes.size()) { throw new IllegalArgumentException("Arity mismatch between " + argumentTypes + " and " + expectedBaseTypes); } /** * Checks the argument types */ IntStream.range(0, argumentTypes.size()) .forEach(i -> argumentTypes.get(i) .ifPresent(t -> expectedBaseTypes.get(i).ifPresent(expectedBaseType -> { if (!t.isCompatibleWith(expectedBaseType)) { throw new IncompatibleTermException(TYPE_FACTORY.getTermType(expectedBaseType), t); } }))); doAdditionalChecks(argumentTypes); return postprocessInferredType(reduceInferredTypes(argumentTypes)); }
throw new OntopTypingException(e.getMessage());
/** * TODO: inject termFactory and typeFactory * */ default Optional<TermType> getOptionalTermType() throws IncompatibleTermException { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.inferType(getTerms()); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } }
throw new OntopTypingException(e.getMessage());
/** * Can be overloaded */ protected void checkTypes(TermType expectedBaseType, TermType argumentType) { if (argumentType.isAbstract()) throw new AbstractTermTypeException(argumentType); if (!argumentType.isA(expectedBaseType)) { throw new IncompatibleTermException(expectedBaseType, argumentType); } }
throw new OntopTypingException(e.getMessage());
default Optional<TermType> getOptionalTermType(ImmutableList<Optional<TermType>> actualArgumentTypes) { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.getTermTypeInferenceRule().inferTypeFromArgumentTypes( actualArgumentTypes, predicate.getArgumentTypes()); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } } }
/** * TODO: generalize */ default Optional<TermType> getOptionalTermType() throws IncompatibleTermException { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.getTermTypeInferenceRule().inferType( getTerms(), predicate.getArgumentTypes()); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } }