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)


Similarity Search Model Creation issue
(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)


(Nicky van Oorschot) #6

Is this the right way using the Jena Binding to get the result we would like to have?


(stephen) #7

It appears that using the Jena bindings in Stardog still sends the query through Jena, which is the problem in the first place. Have you tried Lorenz's suggestion regarding registering the aggregate function via ARQ (Stardog similarity search query through jena)?


(Evren Sirin) #8

Lorenz's suggestion should work but you also need to tweak your query.

First, to make SPARQL parsing in Jena work you can register a dummy aggregate function with the following one-liner:

AggregateRegistry.register("tag:stardog:api:analytics:set", (agg, distinct) -> AggNull.createAccNull(), NodeConst.nodeNil);

Second, you should not use the agg: prefix in your query at all. The set aggregate function is defined in the spa namespace and agg: prefix was a workaround in old versions of Stardog that is not needed anymore (we will update the examples in our documentation). So your aggregate expressions can look like (spa:set(?bouwbest) as ?bouwbest2) with the spa namespace declaration you already have.

Best,
Evren


(system) #9

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.