Explore Graph in RDF4J custom function

102 Views Asked by At

I'm trying to implement a plugin for Ontotext GraphDB. I hope it will compute the distance between two entities via breath first search (see GraphDB as an undirected graph).

I found RDF4J custom function maybe a good way.

public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    if (values.length!=2 || !values[0].isResource() || !values[1].isResource()){
        throw new ValueExprEvaluationException("Usage Wrong");
        }
    Resource source= (Resource) values[0];
    Resource target= (Resource) values[1];
    return null;
}

However, I can not get the properties (neighbors) of an entity through Value. And it seems that valueFactory can only create an entity.

Now I sucessfully implement the example on Ontotext GraphDB. But the example only involves the string handling.

Is there any way to access the properties of entity in RDF4J custom function?

Appreciate your reply.

1

There are 1 best solutions below

1
On BEST ANSWER

That tutorial is a little out of date unfortunately. See the latest javadoc for the Function interface: it now has a evaluate(TripleSource tripleSource, Value... values) method. The TripleSource can be used to query the current state of the store. It should be possible to use this to get the properties associated with your entity.