Stardog similarity search query through jena


(Nicky van Oorschot) #1

Best,

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);
updateExec.execute();

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 : http://schema.org/
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 {
SELECT
(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 http://data.resc.info/kro {?object http://vocab.netage.nl/kro#hasWOZ ?hasWOZ.
?hasWOZ http://vocab.netage.nl/kro#bouwbest ?bouwbest.
?object http://vocab.netage.nl/kro#hasBuilding ?hasBuilding.
?hasBuilding http://vocab.netage.nl/kro#functie ?functie.
?hasBuilding http://vocab.netage.nl/kro#status ?status.
?hasBuilding http://vocab.netage.nl/kro#bag_oppvlk ?bag_oppvlk.
?hasBuilding http://vocab.netage.nl/kro#bouwjaar ?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) {
aConn.begin();
UpdateProcessor updateExec = UpdateExecutionFactory.create(UpdateFactory.create(arg0), getDataset());
updateExec.execute();
aConn.commit();
}

In which getDataset() returns a SD dataset:

SDJenaFactory.createDataset(this.aConn);

But we get the same result:

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