private void insertVariableDataTyping(Term term, Function atom, int position,
                                          Map<String, List<IndexedPosition>> termOccurenceIndex) throws UnknownDatatypeException {


        if (term instanceof Function) {

            Function function = (Function) term;
            Predicate functionSymbol = function.getFunctionSymbol();
            if (function.isDataTypeFunction() ||
                    (functionSymbol instanceof URITemplatePredicate)
                    || (functionSymbol instanceof BNodePredicate)) {
                // NO-OP for already assigned datatypes, or object properties, or bnodes
            }
            else if (function.isOperation()) {
                for (int i = 0; i < function.getArity(); i++) {
                    insertVariableDataTyping(function.getTerm(i), function, i, termOccurenceIndex);
                }
            } else {
                throw new IllegalArgumentException("Unsupported subtype of: " + Function.class.getSimpleName());
            }
        } else if (term instanceof Variable) {

            Variable variable = (Variable) term;
            Term newTerm;
            RDFDatatype type = getDataType(termOccurenceIndex, variable);
            newTerm = termFactory.getTypedTerm(variable, type);
            log.info("Datatype "+type+" for the value " + variable + " of the property " + atom + " has been " +
                    "inferred " +
                    "from the database");
            atom.setTerm(position, newTerm);
        } else if (term instanceof ValueConstant) {
            Term newTerm = termFactory.getTypedTerm(term, ((ValueConstant) term).getType());
            atom.setTerm(position, newTerm);
        } else {
            throw new IllegalArgumentException("Unsupported subtype of: " + Term.class.getSimpleName());
        }
    }
private void insertVariableDataTyping ( Term term , Function atom , int position , Map < String , List < IndexedPosition > > termOccurenceIndex ) throws UnknownDatatypeException { if ( term instanceof Function ) { Function function = ( Function ) term ; Predicate functionSymbol = function . getFunctionSymbol ( ) ; if ( function . isDataTypeFunction ( ) || ( functionSymbol instanceof URITemplatePredicate ) || ( functionSymbol instanceof BNodePredicate ) ) { } else if ( function . isOperation ( ) ) { for ( int i = 0 ; i < function . getArity ( ) ; i ++ ) { insertVariableDataTyping ( function . getTerm ( i ) , function , i , termOccurenceIndex ) ; } } else { throw new IllegalArgumentException ( "Unsupported subtype of: " + Function . class . getSimpleName ( ) ) ; } } else if ( term instanceof Variable ) { Variable variable = ( Variable ) term ; Term newTerm ; RDFDatatype type = getDataType ( termOccurenceIndex , variable ) ; newTerm = termFactory . getTypedTerm ( variable , type ) ; log . info ( "Datatype " + type + " for the value " + variable + " of the property " + atom + " has been " + "inferred " + "from the database" ) ; atom . setTerm ( position , newTerm ) ; } else if ( term instanceof ValueConstant ) { Term newTerm = termFactory . getTypedTerm ( term , ( ( ValueConstant ) term ) . getType ( ) ) ; atom . setTerm ( position , newTerm ) ; } else { throw new IllegalArgumentException ( "Unsupported subtype of: " + Term . class . getSimpleName ( ) ) ; } }
This method wraps the variable that holds data property values with a data type predicate.
It will replace the variable with a new function symbol and update the rule atom.
However, if the users already defined the data-type in the mapping, this method simply accepts the function symbol.