I am trying to register a function  ( SfIntersectsFunction) , such as 
fulltextquery function, using nativefunction  interface , but it no register.


IN SfIntersectsFunction.java

public class SfIntersectsFunction implements NativeFunction {

    // auto-register for SPARQL environment
    static {
        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL 
.SF_INTERSECTS.toString())) {
            FunctionRegistry.getInstance().add(new SfIntersectsFunction());
        }
    }

    @Override
    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
    }

    @Override
    public String getURI() {
        return FN_GEOSPARQL .SF_INTERSECTS.toString();
    }


    /**
     * Return true if this function has available native support for the given 
dialect
     *
     * @param dialect
     * @return
     */
    @Override
    public boolean isSupported(KiWiDialect dialect) {
        return dialect instanceof PostgreSQLDialect;
    }

    /**
     * Return a string representing how this function is translated into SQL in 
the given dialect
     *
     * @param dialect
     * @param args
     * @return
     */
    @Override
    public String getNative(KiWiDialect dialect, String... args) {
        if(dialect instanceof PostgreSQLDialect) {
            if(args.length == 2) {
                return String.format("(to_tsvector('simple' :: regconfig,%1$s) 
@@ plainto_tsquery('simple' :: regconfig,%2$s))", args[0], args[1]);
            } else if(args.length == 3) {
                return String.format("(to_tsvector(kiwi_ft_lang(%3$s) :: 
regconfig, %1$s) @@ plainto_tsquery(kiwi_ft_lang(%3$s) :: regconfig, %2$s))", 
args[0], args[1], args[2]);
            }

        }
        throw new UnsupportedOperationException("fulltext search not supported 
by dialect "+dialect);
    }

    /**
     * Get the return type of the function. This is needed for SQL type casting 
inside KiWi.
     *
     * @return
     */
    @Override
    public ValueType getReturnType() {
        return ValueType.BOOL;
    }

    /**
     * Get the argument type of the function for the arg'th argument (starting 
to count at 0).
     * This is needed for SQL type casting inside KiWi.
     *
     * @param arg
     * @return
     */
    @Override
    public ValueType getArgumentType(int arg) {
        return ValueType.STRING;
    }

    /**
     * Return the minimum number of arguments this function requires.
     *
     * @return
     */
    @Override
    public int getMinArgs() {
        return 2;
    }

    /**
     * Return the maximum number of arguments this function can take
     *
     * @return
     */
    @Override
    public int getMaxArgs() {
        return 3;
    }
}






IN FN_GEOSPARQL.java


public class FN_GEOSPARQL {

    public static final String NAMESPACE = 
"http://www.opengis.net/def/function/geosparql/ 
<http://www.opengis.net/def/function/geosparql/>";


    public static final String PREFIX = "geof";

    
    public static final Namespace NS = new NamespaceImpl(PREFIX, NAMESPACE);

    //BOOLEAN FUNCTIONS
    public static final URI SF_INTERSECTS;


    static {
        ValueFactory f = new ValueFactoryImpl();

        SF_INTERSECTS = f.createURI(NAMESPACE,"sfIntersects");
   
    }



do I need some aditional step for registering the function?

My first intention is to register the function to avoid the error

org.openrdf.query.QueryEvaluationException: Unknown function 
'http://www.opengis <http://www.opengis/>
.net/def/function/geosparql/sfIntersects'


with this query

PREFIX geof: <http://www.opengis.net/def/function/geosparql/ 
<http://www.opengis.net/def/function/geosparql/>>
SELECT ?subject ?property WHERE {
  ?subject a ?object.
  ?subject ?property ?object.
   FILTER( geof:sfIntersects("valor1", "valor2") )
  }

is right what I am trying to do?



Thanks

Reply via email to