Stardog similarity search query through jena

(Nicky van Oorschot) #1


After testing and playing around with the similarity search, we are trying to integrate it with one of our software tools. At this moment we are able to provide the user with a way to select object attibutes to construct a similarity search model and we are able to create a insert model and a select model. However, we are not able to get the queries to stardog via jena, because Jena does not accept the queries.

For example we run the model insert query as a update query:

UpdateRequest request = UpdateFactory.create(query);
UpdateProcessor updateExec = UpdateExecutionFactory.createRemote(request , endpoint);

And we get back the following error:

Non-group key variable in SELECT: ?bouwbest in expression (urn:aggregatespa:set ?bouwbest)

The query used generated is:

prefix spa: tag:stardog:api:analytics:
prefix :
PREFIX agg: urn:aggregate

INSERT { graph spa:model { :building_model a spa:SimilarityModel; spa:arguments (?bouwbest2 ?functie2 ?status2 ?bag_oppvlk2 ?bouwjaar2 );
spa:predict ?object .}}WHERE {
(agg:spa:set(?bouwbest) as ?bouwbest2) (agg:spa:set(?functie) as ?functie2) (agg:spa:set(?status) as ?status2) (agg:spa:set(?bag_oppvlk) as ?bag_oppvlk2) (agg:spa:set(?bouwjaar) as ?bouwjaar2) ?object { GRAPH {?object ?hasWOZ.
?hasWOZ ?bouwbest.
?object ?hasBuilding.
?hasBuilding ?functie.
?hasBuilding ?status.
?hasBuilding ?bag_oppvlk.
?hasBuilding ?bouwjaar.
}} GROUP BY ?object}

The query works fine via Stardog Studio, I am curious whether there is some experience with such specific stardog query constructions and jena (or other ways to get the query to Stardog)

(Lorenz B.) #2

The Jena parser doesn’t know about the custom aggregate functions.

That being said, there is the possibility to register custom aggregate functions via ARQ, e.g.

/* Registration */
AggregateRegistry.register(aggUri, myAccumulatorFactory, NodeConst.nodeMinusOne);

shown in this example code

I don’t know whether this already exists for Stardog somewhere. The devs should know it better indeed.

(Nicky van Oorschot) #3

So only registering would be enough (without having the aggregation code which is used by Stardog), since the query executed by Stardog and not by Jena?

(stephen) #4

We do offer Jena bindings, which should allow you to run your query on Stardog without having to send it through Jena, but it will work with the rest of your application, as everything implements the Jena interface.

(Nicky van Oorschot) #5

Thanx Stephen,

We tried with a Jena Binding:

public void executeUpdate(String arg0) {
UpdateProcessor updateExec = UpdateExecutionFactory.create(UpdateFactory.create(arg0), getDataset());

In which getDataset() returns a SD dataset:


But we get the same result:

Non-group key variable in SELECT: ?bouwbest in expression (urn:aggregatespa:set ?bouwbest)