SPIN User defined template execution with OWLIM

102 views
Skip to first unread message

Raj

unread,
Apr 24, 2013, 4:16:48 PM4/24/13
to topbrai...@googlegroups.com
Hi,
I am pretty much familiar with OWLIM, but not with SPIN.

Could anyone guide me in executing a simple select user defined template with a filter option upon OWLIM?

Thanks in advance.



Scott Henninger

unread,
Apr 24, 2013, 5:06:34 PM4/24/13
to topbrai...@googlegroups.com
Raj; I'd suggest taking a look at http://topquadrant.com/products/SPIN.html.  There are some tutorials and references on the right-hand side of the page.

-- Scott

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Raj

unread,
May 2, 2013, 5:48:25 AM5/2/13
to topbrai...@googlegroups.com
Hi Thanks. I have gone through http://www.topquadrant.com/spin/tutorial/. I even tried all the samples and works fine for me. Now I would like to register the spin template using SPIN API and execute at the sesame repository (OWLIM-SE). Could you please provide me the sample code.

Thanks
Raj

Scott Henninger

unread,
May 2, 2013, 2:04:18 PM5/2/13
to topbrai...@googlegroups.com
Raj; The best way to do this is to download the OWLIM plug-in for TopBraid.  Then you have both an ontology editor and your back-end.

The plugin is maintained by Ontotext, so go to
http://owlim.ontotext.com/display/OWLIMv50/OWLIM-SE+Installation to download.  There is a section named "Using OWLIM-SE with TopBraid Composer" that explains how to update the OWLIM plug-in.

If you want to execute the SPIN API as a stand-alone package, the API documentation is complete in terms of support for the API.

-- Scott

Anand Raj

unread,
May 3, 2013, 3:01:49 AM5/3/13
to topbrai...@googlegroups.com
I have done the bridging between OWLIM-SE and TopBraid Composer. I have even created simple Functions and executed against OWLIM data from TopBraid Composer.

Now I would like to call this spin function using SPIN API on OWLIM model,

Loading model from OWLIM,
manager = RemoteRepositoryManager.getInstance(Preferences
                    .getRepositoryURL());
manager.initialize();
owlimRepository = manager.getRepository(Preferences.Common.REPOSITORY_NAME);
owlimRepository.initialize();
dataset = new SesameDataset(con);
model = ModelFactory.createModelForGraph(dataset.getDefaultGraph());

Executing SPARQL
queryFromSparqlTxt = "SELECT  ( <http://spinrdf.org/spin#accountage>(30) AS ?user) {}"
QueryExecution qExec = QueryExecutionFactory.create(queryFromSparqlTxt,
                model);
        return qExec.execSelect();

Note:-

http://spinrdf.org/spin#accountage is the function defined in TopBraid Composer and stored back to OWLIM.

Now, When I execute the SPARQL, I don't get the expected output.

Please help me on this. Am I missing any spin registry?

Thanks
Raj


You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/kFCKSd04fEw/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.

Holger Knublauch

unread,
May 3, 2013, 4:44:50 AM5/3/13
to topbrai...@googlegroups.com
Hi Anand,

any SPIN function needs to be registered with the Jena FunctionRegistry. The KennedysInferencingAndConstraintsExample.java shows how to do this:

        // Register locally defined functions
        SPINModuleRegistry.get().registerAll(ontModel, null);

*However* this only registers your SPIN functions to Jena, and with OWLIM you may be in a situation in which the whole query is executed server-side using the native SPARQL engine of OWLIM, bypassing any locally registered Jena functions. In a sense Jena is just the client then. I have not used the OWLIM Jena bridge, but you can verify if an error is reported such as unknown function coming from OWLIM directly.

So please make sure the function is registered at all, and send us any error message if it still happens.

HTH
Holger

Anand Raj

unread,
May 3, 2013, 4:53:48 AM5/3/13
to topbrai...@googlegroups.com

Hi,

I have registered the function, as suggested

registry.registerAll(model, null);
               
Function function = registry.getFunction("http://spinrdf.org/spin#accountage", model);
               
SPINARQFunction spinarqFunction = new SPINARQFunction(function);


I get the function too. Now I need an example how to execute this function using exec or executeBody methods.  I am struck with supplying arguments to methods. How do I create variables and assign value to it.

It would be of great help, if you could share me the sample code.

Thanks
Raj

Holger Knublauch

unread,
May 3, 2013, 4:59:02 AM5/3/13
to topbrai...@googlegroups.com
I don't think calling a function's exec function directly is a good practice in Jena - it would require preparing the environment etc. If you just want to call the body query manually, get a pointer to it via the SPIN.body triple and convert the object of that triple to Select via the SPINFactory. Once you have a Select, you can turn it into a Jena Query object etc. Sorry we cannot walk down all these details, maybe other community members can.

But the cleanest approach would be to call the function embedded in a SPARQL query, so I would investigate this further. The query SELECT  ( <http://spinrdf.org/spin#accountage>(30) AS ?user) {} should work. What is the output - any errors?

Holger

Anand Raj

unread,
May 3, 2013, 5:38:34 AM5/3/13
to topbrai...@googlegroups.com
Hi,

When I don't register the SPINModel and execute the query, I dont get any error but empty result set.

When I register and execute the query, getting following errors,

Exception in thread "main" java.lang.NullPointerException
    at com.ontotext.jena.
StageGeneratorSesame$SesameIter.<init>(Unknown Source)
    at com.ontotext.jena.StageGeneratorSesame.solve(Unknown Source)
    at com.ontotext.jena.StageGeneratorSesame.execute(Unknown Source)
    at com.hp.hpl.jena.sparql.engine.main.StageBuilder.execute(StageBuilder.java:58)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:134)
    at com.ontotext.jena.SesameOpExecutor.execute(Unknown Source)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.visit(ExecutionDispatch.java:59)
    at com.hp.hpl.jena.sparql.algebra.op.OpBGP.visit(OpBGP.java:49)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.exec(ExecutionDispatch.java:47)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.executeOp(OpExecutor.java:123)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:329)
    at com.ontotext.jena.SesameOpExecutor.execute(Unknown Source)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.visit(ExecutionDispatch.java:180)
    at com.hp.hpl.jena.sparql.algebra.op.OpFilter.visit(OpFilter.java:110)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.exec(ExecutionDispatch.java:47)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.executeOp(OpExecutor.java:123)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:459)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.visit(ExecutionDispatch.java:308)
    at com.hp.hpl.jena.sparql.algebra.op.OpGroup.visit(OpGroup.java:51)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.exec(ExecutionDispatch.java:47)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.executeOp(OpExecutor.java:123)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:491)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.visit(ExecutionDispatch.java:292)
    at com.hp.hpl.jena.sparql.algebra.op.OpExtend.visit(OpExtend.java:121)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.exec(ExecutionDispatch.java:47)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.executeOp(OpExecutor.java:123)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:440)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.visit(ExecutionDispatch.java:260)
    at com.hp.hpl.jena.sparql.algebra.op.OpProject.visit(OpProject.java:48)
    at com.hp.hpl.jena.sparql.engine.main.ExecutionDispatch.exec(ExecutionDispatch.java:47)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.executeOp(OpExecutor.java:123)
    at com.hp.hpl.jena.sparql.engine.main.OpExecutor.execute(OpExecutor.java:96)
    at com.hp.hpl.jena.sparql.engine.main.QC.execute(QC.java:52)
    at com.hp.hpl.jena.sparql.engine.main.QueryEngineMain.eval(QueryEngineMain.java:65)
    at com.hp.hpl.jena.sparql.engine.QueryEngineBase.evaluate(QueryEngineBase.java:129)
    at com.hp.hpl.jena.sparql.engine.QueryEngineBase.createPlan(QueryEngineBase.java:99)
    at com.hp.hpl.jena.sparql.engine.QueryEngineBase.getPlan(QueryEngineBase.java:87)
    at com.hp.hpl.jena.sparql.engine.main.QueryEngineMain$1.create(QueryEngineMain.java:113)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.getPlan(QueryExecutionBase.java:532)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.startQueryIterator(QueryExecutionBase.java:509)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execResultSet(QueryExecutionBase.java:517)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execSelect(QueryExecutionBase.java:215)
    at org.topbraid.spin.arq.SPINARQFunction.executeBody(SPINARQFunction.java:198)
    at org.topbraid.spin.arq.SPINARQFunction.exec(SPINARQFunction.java:172)
    at com.hp.hpl.jena.sparql.expr.E_Function.evalSpecial(E_Function.java:71)
    at com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:102)
    at com.hp.hpl.jena.sparql.core.VarExprList.get(VarExprList.java:82)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIterAssign.accept(QueryIterAssign.java:68)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIterProcessBinding.hasNextBinding(QueryIterProcessBinding.java:64)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:108)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:59)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:108)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:108)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:108)
    at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:72)
    at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:95)
    at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:147)
    at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:130)
    at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:118)
    at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:65)
    at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:122)
    at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:74)
    at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:65)
    at me.socure.service.ontoop.service.InferencingService.getRealUser(InferencingService.java:165)
    at me.socure.service.ontoop.service.InferencingService.main(InferencingService.java:153)

Thanks
Raj


Holger Knublauch

unread,
May 3, 2013, 8:31:59 PM5/3/13
to topbrai...@googlegroups.com
Hi Anand,

the root exception is inside of the ontotext API, so I cannot tell what's happening there. I am afraid you would need to ask them (or look at the source code if available) to learn what could be causing the NullPointer.

Overall it looks good that it's calling the SPIN function correctly.

Thanks
Holger

Anand Raj

unread,
May 16, 2013, 8:19:27 AM5/16/13
to topbrai...@googlegroups.com
Hi,

Thanks for your support. I am able to execute the SPIN function, but still I am facing problem in passing argument to the function.

working : SELECT (<http://www.semanticweb.org/socure.me/activityOntology#InvalidUser>() AS ?u) {}
not working: SELECT (<http://www.semanticweb.org/socure.me/activityOntology#checkUser>(5) AS ?u) {}

Am I making any mess here. When I call a function which doest not have argument works fine, at the same time a function having arguments returns empty results.

Code Sample :
        String query = "SELECT (<http://www.semanticweb.org/socure.me/activityOntology#checkUser>(5) AS ?u) {}";

        QueryExecution exec = QueryExecutionFactory.create(query, spinModel);
        ResultSet resultSet = exec.execSelect();

Thanks
Raj


Holger Knublauch

unread,
May 16, 2013, 6:01:42 PM5/16/13
to topbrai...@googlegroups.com
Raj,

what does the spin:body (better: full declaration) of the SPIN function look like? Does it work when you execute it within TBC against an in-memory graph?

Holger

Anand Raj

unread,
May 17, 2013, 1:22:50 AM5/17/13
to topbrai...@googlegroups.com
The function works fine within TBC. Please check the function below,

Function:
SELECT ((GROUP_CONCAT(DISTINCT ?user; SEPARATOR=',')) AS ?users)
WHERE {
    ?user a :Person .
    ?user :accountAge ?age .
    FILTER (?age <= ?arg2) .
}

SPARQL:
spin function.png

Holger Knublauch

unread,
May 17, 2013, 2:58:54 AM5/17/13
to topbrai...@googlegroups.com
Hmm, I cannot see anything wrong. I would suggest the following:

1) Try using sp:arg1 (and ?arg1) instead of sp:arg2 (and ?arg2)

2) If it still does not work from the SPIN API, step through the debugger, with a breakpoint in SPINARQFunction.exec to understand what SPARQL query it is really executing under the hood.

Holger



On May 17, 2013, at 3:22 PM, Anand Raj wrote:

The function works fine within TBC. Please check the function below,

Function:
SELECT ((GROUP_CONCAT(DISTINCT ?user; SEPARATOR=',')) AS ?users)
WHERE {
    ?user a :Person .
    ?user :accountAge ?age .
    FILTER (?age <= ?arg2) .
}

SPARQL:

<spin function.png>
Reply all
Reply to author
Forward
0 new messages