/** * Do not use this construction if you know the language tag! */ public PredefinedTermTypeInferenceRule(Predicate.COL_TYPE predefinedColType) { this(TYPE_FACTORY.getTermType(predefinedColType)); }
@Override protected Optional<TermType> postprocessInferredType(Optional<TermType> optionalTermType) { // No need to call super.postprocessInferredType() return optionalTermType .map(t -> INTEGER_TYPES.contains(t.getColType()) ? TYPE_FACTORY.getTermType(DECIMAL) : t); } }
protected static TermType castStringLangType(TermType termType) { switch (termType.getColType()) { case LANG_STRING: case STRING: return termType; default: return TYPE_FACTORY.getTermType(STRING); } } }
/** * Only base numeric types (double, float, decimal and integer) can be returned by numeric functions and operators */ @Override protected Optional<TermType> postprocessInferredType(Optional<TermType> optionalTermType) { return optionalTermType .map(t -> INTEGER_TYPES.contains(t.getColType()) ? TYPE_FACTORY.getTermType(INTEGER) : t); } }
@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)); }
return TYPE_FACTORY.getTermType(((Constant) term).getType());
return Optional.of(TYPE_FACTORY.getTermType(secondArgument)); return Optional.of(TYPE_FACTORY.getTermType(f.getFunctionSymbol().getType(0))); return Optional.of(TYPE_FACTORY.getTermType(((ValueConstant) term).getType()));
if ((functionSymbol instanceof BNodePredicate) || (functionSymbol instanceof URITemplatePredicate)) { return Optional.of(TYPE_FACTORY.getTermType(OBJECT)); ? Optional.of(TYPE_FACTORY.getTermType(generateFreshVariable())) : Optional.of(TYPE_FACTORY.getTermType(internalDatatype));
defaultTypeBuilder.add(TYPE_FACTORY.getTermType(type));
defaultTypeBuilder.add(TYPE_FACTORY.getTermType(type));