@Override public boolean equals(Object other) { return Optional.ofNullable(other) .filter(o -> (o instanceof TermType)) .map(o -> (TermType) o) .filter(o -> colType == o.getColType()) .filter(o -> optionalLangTagConstant .map(tag1 -> o.getLanguageTagConstant() .map(tag1::equals) .orElse(false)) .orElseGet(() -> !o.getLanguageTagConstant().isPresent())) .filter(o -> optionalLangTagTerm .map(tag1 -> o.getLanguageTagTerm() .map(tag1::equals) .orElse(false)) .orElseGet(() -> !o.getLanguageTagTerm().isPresent())) .isPresent(); }
/** * Unifies the input cast types * * For instance, * * [INTEGER, DOUBLE] -> DOUBLE * [INTEGER, LITERAL] -> LITERAL * [INTEGER, INTEGER] -> INTEGER * * TODO: refactor * */ private static TermType unifyCastTypes(TermType type1, TermType type2) { // TODO: the common denominator is not the right mechanism for casting return type1.getCommonDenominator(type2); } }
/** * 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); } }
private static Predicate.COL_TYPE getCastType(TermType termType) { Predicate.COL_TYPE type = termType.getColType(); switch (type) { case OBJECT: case BNODE: case NULL: return LITERAL; default: return type; } }
+ declaredDatatype.getPredicate().getName() + "")); if (!tripleObjectType.isCompatibleWith(internalType)) { declaredDatatype.getPredicate().getName() + " in the ontology, but has datatype " + TYPE_FACTORY.getTypePredicate(tripleObjectType.getColType()).getName() + " according to the following triplesMap (either declared in the triplesMap, or " + "inferred from its source):\n[\n" +
@Override public void validate(ImmutableList<Optional<TermType>> argumentTypes) { super.validate(argumentTypes); Optional<TermType> optionalFirstType = argumentTypes.get(0); Optional<TermType> optionalSecondType = argumentTypes.get(1); if (optionalFirstType.isPresent() && optionalSecondType.isPresent()) { if (!optionalFirstType.get().isA(optionalSecondType.get())) throw new FirstTypeIsNotASecondTypeException( optionalFirstType.get(), optionalSecondType.get()); } }
@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)); }
/** * Can be overloaded */ @Override public TermType getCommonDenominator(TermType otherTermType){ if (equals(otherTermType)) return this; if (ancestry.contains(otherTermType)) return otherTermType; TermTypeAncestry otherAncestry = otherTermType.getAncestry(); if (otherAncestry.contains(this)) return this; return ancestry.getClosestCommonAncestor(otherAncestry); }
private static Predicate.COL_TYPE getCastType(TermType termType) { Predicate.COL_TYPE type = termType.getColType(); switch (type) { case OBJECT: case BNODE: case NULL: return LITERAL; default: return type; } }
.isA(typeFactory.getUnsupportedDatatype())) { throw new RuntimeException("Unsupported type in the query: " + function);
rootRDFTermType = RDFTermTypeImpl.createRDFTermRoot(rootTermType.getAncestry());
private String getLangColumnForSELECT(Term ht, AliasIndex index, Optional<TermType> optionalTermType) { if (ht instanceof Variable) { return index.getLangColumn((Variable) ht) .map(QualifiedAttributeID::getSQLRendering) .orElse(sqladapter.getNullForLang()); } else { return optionalTermType .filter(t -> t.getColType() == LANG_STRING) .map(t -> t.getLanguageTagConstant() .map(tag -> "'" + tag.getFullString() + "'") .orElseGet(() -> t.getLanguageTagTerm() .map(tag -> getSQLString(tag, index, false)) .orElseThrow(() -> new IllegalStateException( "Inconsistent term type: the language tag must be defined for any LANG_STRING")))) .orElse(sqladapter.getNullForLang()); } }
UndeterminedTripleObjectType(String predicateName, TermType tripleObjectType) { super("Internal bug: undetermined type (" + tripleObjectType.getColType() + ") for " + predicateName); } }
/** * Can be overwritten */ protected TermType unifyTypes(TermType type1, TermType type2) { return type1.getCommonDenominator(type2) // This should have detected before .orElseThrow(() -> new IllegalStateException("Try to \"unify\" incompatible types (" + type1 + " and " + type2 + ". This should have been detected before")); }
if (colType == LANG_STRING && otherTermType.getColType() == LANG_STRING) { Optional<LanguageTag> newOptionalLangTag = otherTermType.getLanguageTagConstant() .flatMap(langTag::getCommonDenominator); if (otherTermType.getLanguageTagTerm() .filter(langTagTerm::equals) .isPresent()) { return TermTypeInferenceTools.getCommonDenominatorType(colType, otherTermType.getColType()) .map(TermTypeImpl::new);
@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); } }
/** * Unifies the input cast types * * For instance, * * [INTEGER, DOUBLE] -> DOUBLE * [INTEGER, LITERAL] -> LITERAL * [INTEGER, INTEGER] -> INTEGER * */ private static TermType unifyCastTypes(TermType type1, TermType type2) { return type1.getCommonDenominator(type2) /** * Every head argument must have a TermType. By default, * we cast it as a LITERAL (VARCHAR) */ .orElse(LITERAL_TYPE); } }
private String getLangColumnForSELECT(Term ht, String signatureVarName, QueryAliasIndex index, Set<String> sqlVariableNames, Optional<TermType> optionalTermType) { /** * Creates a variable name that fits to the restrictions of the SQL dialect. */ String langVariableName = sqladapter.nameTopVariable(signatureVarName, LANG_SUFFIX, sqlVariableNames); sqlVariableNames.add(langVariableName); final String lang; if (ht instanceof Variable) { lang = getLangFromVariable((Variable) ht, index); } else { lang = optionalTermType .filter(t -> t.getColType() == LITERAL_LANG) .map(t -> t.getLanguageTagConstant() .map(tag -> "'" + tag.getFullString() + "'") .orElseGet(() -> t.getLanguageTagTerm() .map(tag -> getSQLString(tag, index, false)) .orElseThrow(() -> new IllegalStateException( "Inconsistent term type: the language tag must be defined " + "for any LITERAL_LANG")))) .orElse("NULL"); } return String.format(LANG_STR, lang, langVariableName); }
protected static TermType castStringLangType(TermType termType) { switch (termType.getColType()) { case LANG_STRING: case STRING: return termType; default: return TYPE_FACTORY.getTermType(STRING); } } }
/** * Unifies the input cast types * * For instance, * * [INTEGER, DOUBLE] -> DOUBLE * [INTEGER, LITERAL] -> LITERAL * [INTEGER, INTEGER] -> INTEGER * */ private static TermType unifyCastTypes(TermType type1, TermType type2) { return type1.getCommonDenominator(type2) /** * Every head argument must have a TermType. By default, * we cast it as a LITERAL (VARCHAR) */ .orElse(LITERAL_TYPE); } }