All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibz.inf.ontop.model.term.functionsymbol.impl.StrSPARQLFunctionSymbolImpl Maven / Gradle / Ivy

package it.unibz.inf.ontop.model.term.functionsymbol.impl;

import com.google.common.collect.ImmutableList;
import it.unibz.inf.ontop.iq.node.VariableNullability;
import it.unibz.inf.ontop.model.term.ImmutableExpression;
import it.unibz.inf.ontop.model.term.ImmutableTerm;
import it.unibz.inf.ontop.model.term.TermFactory;
import it.unibz.inf.ontop.model.type.ObjectRDFType;
import it.unibz.inf.ontop.model.type.RDFDatatype;
import it.unibz.inf.ontop.model.type.RDFTermType;
import it.unibz.inf.ontop.model.type.TermTypeInference;
import it.unibz.inf.ontop.model.vocabulary.SPARQL;

import java.util.Optional;


public class StrSPARQLFunctionSymbolImpl extends ReduciblePositiveAritySPARQLFunctionSymbolImpl {

    private final RDFDatatype xsdStringType;
    private final ObjectRDFType bnodeType;

    protected StrSPARQLFunctionSymbolImpl(RDFTermType abstractRDFType, RDFDatatype xsdStringType, ObjectRDFType bnodeType) {
        super("SP_STR", SPARQL.STR, ImmutableList.of(abstractRDFType));
        this.xsdStringType = xsdStringType;
        this.bnodeType = bnodeType;
    }

    @Override
    protected ImmutableTerm computeLexicalTerm(ImmutableList subLexicalTerms,
                                               ImmutableList typeTerms, TermFactory termFactory, ImmutableTerm returnedTypeTerm) {
        return subLexicalTerms.get(0);
    }

    @Override
    protected ImmutableTerm computeTypeTerm(ImmutableList subLexicalTerms, ImmutableList typeTerms, TermFactory termFactory,
                                            VariableNullability variableNullability) {
        return termFactory.getRDFTermTypeConstant(xsdStringType);
    }

    /**
     * Excludes blank nodes
     */
    @Override
    protected ImmutableExpression.Evaluation evaluateInputTypeError(ImmutableList subLexicalTerms, ImmutableList typeTerms,
                                                                    TermFactory termFactory, VariableNullability variableNullability) {
        ImmutableTerm typeTerm = typeTerms.get(0);

        return termFactory.getDBNot(termFactory.getIsAExpression(typeTerm, bnodeType))
                .evaluate(variableNullability);
    }

    @Override
    public boolean isAlwaysInjectiveInTheAbsenceOfNonInjectiveFunctionalTerms() {
        return false;
    }

    @Override
    public Optional inferType(ImmutableList terms) {
        return Optional.of(TermTypeInference.declareTermType(xsdStringType));
    }

    /**
     * Could be allowed in the future
     */
    @Override
    public boolean canBePostProcessed(ImmutableList arguments) {
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy