Stardog and Jena - JARs to import

66 views
Skip to first unread message

justforthe...@gmail.com

unread,
Jun 24, 2014, 12:58:40 PM6/24/14
to sta...@clarkparsia.com
I am a newbie both in Java and Stardog so please bare with me.

I have been asked to evaluate Stardog and its operability with Java and, while I can test the logic part with no problems, I am having a hard time with the second one. I find the documentation very good and complete in many aspects (for instance, the reasoning or the getting started part), especially when you have background knowledge, but I am a bit lost when it comes to specific examples. On the Web I mostly find a few old examples using old packages and no full examples. I know it doesn't help the fact that I am a Java newbie.



1) My first problem is resolving JARs. I opted to go for Jena and I have already imported Jena packages in my project. I assumed I needed ALL the JARs in the following folders:
client/jena  (or only "stardog-jena-2.1.3.jar" if I have downloaded Jena previously)
server/dbms  ( there are many JARs but I couldn't determine which specific ones I need)

This seemed to resolve all imports except "com.complexible.stardog.protocols.snarl.SNARLProtocolConstants" which is defined in "client/snarl/stardog-snarl-shared-2.1.3.jar" as I discovered after many try-error attempts. I am not sure it was all correct since I got errors of multiple inclusions:
SLF4J: Class path contains multiple SLF4J bindings. -- probably from a JAR I previously included from the downloaded Jena JARs.

My question is, how can I determine what specific JARs from the Stardog distribution I really need?



2) This might be related to the previous question. After solving the import problems, and running the Jena example I get:

1) No implementation for com.complexible.common.protocols.server.ServerFactory annotated with @com.google.inject.name.Named(value=SPEC) was bound.
  while locating com.complexible.common.protocols.server.ServerFactory annotated with @com.google.inject.name.Named(value=SPEC)
    for parameter 0 at com.complexible.stardog.Stardog$StardogServerBuilder.<init>(Stardog.java:166)
  while locating com.complexible.stardog.Stardog$StardogServerBuilder

I understand this is because I am missing some imports, so the code needs something else but I don't know what. Perhaps some JAR from the "snarl" folder?


3) Once I obtain the connection to the database:
Server aServer = Stardog.buildServer().bind(SNARLProtocolConstants.EMBEDDED_ADDRESS).start();
Connection aConn = ConnectionConfiguration.to("myDB").credentials("admin", "admin").connect();

I suppose I can write to the DB by using "aModel.commit();" and read from it with the "QueryFactory" as in the example. Is this correct?


Thanks.

Fernando Hernandez

unread,
Jun 24, 2014, 2:14:58 PM6/24/14
to sta...@clarkparsia.com
Hi,

Since our examples use Stardog in embedded mode you need to include all the server JARs in your classpath as well as all the SNARL JARs. The easiest thing to do is to just include everything, and when you have your evaluation ready you can worry about optimizing your build including only the client JARs for your preferred protocol using Maven [0] or your preferred build tool.


Cheers,
Fernando
 



Thanks.

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Mike Grove

unread,
Jun 25, 2014, 7:04:06 AM6/25/14
to stardog
On Tue, Jun 24, 2014 at 12:58 PM, <justforthe...@gmail.com> wrote:
In the distribution, there's a folder called "examples" which contains a short example of using Stardog with the Jena API, which you might find a good getting started point.

Cheers,

Mike

justforthe...@gmail.com

unread,
Jun 25, 2014, 9:44:10 AM6/25/14
to sta...@clarkparsia.com, fern...@clarkparsia.com
Thanks Fernando and Michael,

I was missing the detail of the embedded mode!!  I included every JAR and it worked!  Many thanks.

I succeed to connect to the running Stardog from Java and create a database. However, I am a bit lost when saving data because "commit" doesn't seem to work (it says "java.lang.UnsupportedOperationException: this model does not support transactions". From my research it seems "Memory models don't support transactions". Am I missing a configuration parameter?). 

Is there any example I can check to write my Jena model in the running Stardog I connected to?
I have been checking the Jena "example" folder in the distribution and in Github but it seems to work only in memory and with the embedded mode.

Mike Grove

unread,
Jun 25, 2014, 9:51:17 AM6/25/14
to stardog
On Wed, Jun 25, 2014 at 9:44 AM, <justforthe...@gmail.com> wrote:
Thanks Fernando and Michael,

I was missing the detail of the embedded mode!!  I included every JAR and it worked!  Many thanks.

I succeed to connect to the running Stardog from Java and create a database. However, I am a bit lost when saving data because "commit" doesn't seem to work (it says "java.lang.UnsupportedOperationException: this model does not support transactions". From my research it seems "Memory models don't support transactions". Am I missing a configuration parameter?). 

That's not an error from Stardog, it's coming from Jena, so probably has something to do with how you've created your Model.  Stardog supports (requires, more specifically) commit in any mode of operation.
 

Is there any example I can check to write my Jena model in the running Stardog I connected to?
I have been checking the Jena "example" folder in the distribution and in Github but it seems to work only in memory and with the embedded mode.

You can easily modify the example in the distribution to start a server which binds to a non-embedded address, such as local host, or avoid starting the server altogether and connect to an existing server.  Similarly, rather than using the convenience method "createMemory" on AdminConnection, you can use "disk" to retrieve a DatabaseBuilder and create a disk-based database.

Cheers,

Mike

justforthe...@gmail.com

unread,
Jun 25, 2014, 9:52:09 AM6/25/14
to sta...@clarkparsia.com, fern...@clarkparsia.com, justforthe...@gmail.com
I am checking if IndexOptions.PERSIST is what I need and how I can use it.

justforthe...@gmail.com

unread,
Jun 25, 2014, 3:11:42 PM6/25/14
to sta...@clarkparsia.com
Thanks, Mike.

Your pointers were very helpful. I actually knew I could access an existing server (and I was doing it). I just asked if there already existed real examples of code interacting with Jena models and Stardog.

I could create a database in both memory and disk from a file with no problems (  .create( myFile ) ). However, when I try to load data from a Java OntModel, I don't get all the triples (it seems the OWL information is lost, like classes were rdfs:Class and not owl:Class, and therefore they don't appear in the "Browse" menu option of my Stardog database)  Can this be because SDJenaFactory uses Model instead of OntModel?

aModel = SDJenaFactory.createModel(aConn);
                OntModel o2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, aModel);
                o2.begin();
                o2= (OntModel) o2.add( my_OntModel );
                o2.commit();
                o2.close();

And this:
aModel = SDJenaFactory.createModel(aConn);
aModel.begin();
aModel= aModel.add( (Model) my_OntModel  );
aModel.commit();

And both seem to have the same results - only partial information is stored.
I know OntModel is not supported (https://groups.google.com/a/clarkparsia.com/forum/#!msg/stardog/f4ekmhOSwqA/PjvA6NwhyM8J) but I am not sure how I should load the info from Jena otherwise.



I've collected some notes that might be useful for others:

- The examples use the embedded mode. Connecting to an existing Stardog can be done via:
aAdminConnection = AdminConnectionConfiguration.toServer("snarl://localhost:5820").credentials("admin", "admin").connect();

- Starting Stardog from a Java application required me to have the licence file in the "." directory of the Java app. Not sure why STARDOG_HOME was not properly accessed.

- I believe the Stardog server cannot be started twice, so make sure your Java code close the server properly (use a "finally" block). If problems happen, Stardog is down but it does not start because it believes there is another copy working: delete the file "system.lock" (note there might be some data corruption if you didn't close properly!)

- When creating a database, the initial file load from ".create( myFile )"  seems to use the extension of the file to identify the format. So having an N3 file with no .n3 extension will raise an exception and will not be recognized.

Mike Grove

unread,
Jun 26, 2014, 7:15:01 AM6/26/14
to stardog
On Wed, Jun 25, 2014 at 3:11 PM, <justforthe...@gmail.com> wrote:
Thanks, Mike.

Your pointers were very helpful. I actually knew I could access an existing server (and I was doing it). I just asked if there already existed real examples of code interacting with Jena models and Stardog.

I could create a database in both memory and disk from a file with no problems (  .create( myFile ) ). However, when I try to load data from a Java OntModel, I don't get all the triples (it seems the OWL information is lost, like classes were rdfs:Class and not owl:Class, and therefore they don't appear in the "Browse" menu option of my Stardog database)  Can this be because SDJenaFactory uses Model instead of OntModel?

aModel = SDJenaFactory.createModel(aConn);
                OntModel o2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, aModel);
                o2.begin();
                o2= (OntModel) o2.add( my_OntModel );
                o2.commit();
                o2.close();

And this:
aModel = SDJenaFactory.createModel(aConn);
aModel.begin();
aModel= aModel.add( (Model) my_OntModel  );
aModel.commit();

And both seem to have the same results - only partial information is stored.
I know OntModel is not supported (https://groups.google.com/a/clarkparsia.com/forum/#!msg/stardog/f4ekmhOSwqA/PjvA6NwhyM8J) but I am not sure how I should load the info from Jena otherwise.


It's not clear what behavior you're expecting to see.  If you can provide a complete, self contained example of the issue, we can take a deeper look.

Cheers,

Mike

justforthe...@gmail.com

unread,
Jun 27, 2014, 2:58:28 PM6/27/14
to sta...@clarkparsia.com
So after loading the model I see nothing under Thing [1].
I can however see the property, so I can reach the instance from there and see the class it belongs to [2].

I have sent you an email with information about the files I used.

[1]

Schema Browser


[2]


John

untitled-ontology-38
John
Reply all
Reply to author
Forward
0 new messages