Examples of Topbraid spin api

76 views
Skip to first unread message

Naga Krishna

unread,
Jul 7, 2016, 3:34:21 PM7/7/16
to TopBraid Suite Users
I am new to topbraid spin api, can any share some code examples for using topbraid in creating rules, functions etc.,

Holger Knublauch

unread,
Jul 7, 2016, 4:40:28 PM7/7/16
to topbrai...@googlegroups.com
Rules and functions are created through their RDF triples, not via the API. So once you load a SPIN file that contains them, they should work (assuming the functions are registered as shown in the bundled example file)

Holger



On 8/07/2016 1:27, Naga Krishna wrote:
I am new to topbraid spin api, can any share some code examples for using topbraid in creating rules, functions etc.,
--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbrai...@googlegroups.com
---
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/d/optout.

Naga Krishna

unread,
Jul 8, 2016, 3:50:15 PM7/8/16
to TopBraid Suite Users
Thanks Holger, can you please help on how to invoke a function(defined in rdf file) from java api, in the examples its only shown how to run constraints.

Holger Knublauch

unread,
Jul 8, 2016, 6:31:12 PM7/8/16
to topbrai...@googlegroups.com
You can invoke functions from within any SPARQL query, e.g a constraint or rule. No Java is needed for that.

Holger

Sent from my iPad

Irene Polikoff

unread,
Jul 8, 2016, 6:45:01 PM7/8/16
to topbrai...@googlegroups.com
To add to this, typically, functions are used in BIND and FILTER clauses of SPARQL queries.

Irene Polikoff

 


Naga Krishna

unread,
Jul 9, 2016, 5:11:23 PM7/9/16
to TopBraid Suite Users
Thanks Holger & Irene,

I am using kennedy rdf file. The below code is used to register the functions

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

But this code is not actually registering the user defined function defined in rdf file. Later using below code to check if any functions are registered, but getting this as null

Collection<Function> func = SPINModuleRegistry.get().getFunctions();

Can you guys me with any example on how to define function or read defined function in rdf file. once this is done i can invoke function through sparql query.

Holger Knublauch

unread,
Jul 9, 2016, 8:32:48 PM7/9/16
to topbrai...@googlegroups.com
I would need a minimally, complete example source code to reproduce this. We had many similar questions on this mailing list recently, and often it was a matter of how the ontModel was produced, e.g. missing some subgraphs. Please clarify.

Holger

Naga Krishna

unread,
Jul 9, 2016, 10:38:30 PM7/9/16
to TopBraid Suite Users
Hello Holger,

I am trying to implement as explained in tutorial through spin api, created a user defined function mmddyy2ISO8601. Trying to call this function through sparql query using below code. But getting null values.

        Function function = SPINModuleRegistry.get().getFunction("http://topbraid.org/examples/purchases#mmddyy2ISO8601", ontModel);

        SPINModuleRegistry.get().registerFunctions(ontModel, function);

        String query = "SELECT ?x WHERE { BIND (<http://topbraid.org/examples/purchases#mmddyy2ISO8601>(\"9/6/14\") as ?x) .}";

        QueryExecution exec = QueryExecutionFactory.create(query, ontModel);

        ResultSet resultSet = exec.execSelect();

        ResultSetFormatter.out(resultSet);

Output:

Function call works in topbraid studio, but not with spin api.

Holger Knublauch

unread,
Jul 10, 2016, 8:19:33 PM7/10/16
to topbrai...@googlegroups.com
I see nothing wrong, but this is not a complete example that I could execute. For example I don't have the RDF file and don't see what the ontModel contains.

Holger

Naga Krishna

unread,
Jul 10, 2016, 10:00:52 PM7/10/16
to TopBraid Suite Users
Hello Holger,

I have attached rdf file, below is the code. I have defined a functiommddyy2ISO8601 which takes input a string and outputs data. This function internally uses spif:parseDate. The output of this code is null.

SPINModuleRegistry.get().init();
Model baseModel = ModelFactory.createDefaultModel();
baseModel.read("C:\\Users\\Naga\\TBCFreeWorkspace\\example\\purchases.rdf");
OntModel ontModel = JenaUtil.createOntologyModel(OntModelSpec.OWL_MEM,baseModel);
SPINModuleRegistry.get().registerAll(ontModel, null);

Function function = SPINModuleRegistry.get().getFunction("http://topbraid.org/examples/purchases#mmddyy2ISO8601", ontModel);
SPINModuleRegistry.get().registerFunctions(ontModel, function);
String query = "SELECT ?x WHERE { BIND (<http://topbraid.org/examples/purchases#mmddyy2ISO8601>(\"9/6/14\") as ?x) .}";
QueryExecution exec = QueryExecutionFactory.create(query, ontModel);
ResultSet resultSet = exec.execSelect();
ResultSetFormatter.out(resultSet);

On defining function without using any inbuilt functions from namespaces like spif:parseData or spif:Random(, then not getting any output. If i define a function which returns only a string then it works.
purchases.rdf

Holger Knublauch

unread,
Jul 10, 2016, 10:11:17 PM7/10/16
to topbrai...@googlegroups.com
The spif functions such as spif:parseDate are not part of the open source API. This may explain the difference in behavior compared with TBC.

HTH
Holger

Naga Krishna

unread,
Jul 10, 2016, 11:15:49 PM7/10/16
to TopBraid Suite Users
Thanks Holger,

Can you suggest how to use spif functions using spin API

Holger Knublauch

unread,
Jul 11, 2016, 12:27:41 AM7/11/16
to topbrai...@googlegroups.com
The spif functions are not part of an open source package. You'd need to
reimplement them yourself. The commercial web products of TopBraid Live,
EVN and EDG include these capabilities out of the box.

Holger

Naga Krishna

unread,
Jul 11, 2016, 3:57:12 PM7/11/16
to TopBraid Suite Users
Thanks Holger.
Reply all
Reply to author
Forward
0 new messages