Janny
Janny

Reputation: 33

How to include a remote vocabulary/namespace to OntModel using Jena?

I'm new to Semantic Web and Jena.

I want to generate an ontology from a OntModel in Jena and I need to use vocabulary and ontologies predefined to caracterize my classes and properties.

In Jena, there are default ontologies like RDF, FOAF...So we can specify class and add property to resource like:

ontClass.setSameAs(FOAF.Person);
ontClass.addProperty(FOAF.name, "name");

or

ontProperty.setRange(XSD.xstring);

But how can I refer my ontClass to another vocabulary/ontology that does not exist in Jena (GeoSparql, Geofla, vocabulary that I defined myself,etc.)? Knowing that I can have the URI for these vocabularies?

This question's already been raised in this topic: How to add vocabulary in Jena? which suggests using Jena Schemagen but I can't see how to do it.

Thank you a lot for helping!

Upvotes: 0

Views: 132

Answers (1)

mgc
mgc

Reputation: 5443

I guess one of the option is to import (or read) theses vocabularies/ontologies so that you can use them using Jena Ontology API.

For example (if we assume that your ontModel is named m) you can read the OWL-Time ontology into your model like so :

m.read("http://www.w3.org/2006/time")

and then you can use the elements it defines using Jena's programmatic API :

OntClass instant = dataModel.getOntClass("http://www.w3.org/2006/time#Instant");

If you don't wan't to read the whole ontology within your model, you can also just "create" the necessary ressource / property using its URI :

Property inXSDDateTime = m.createDatatypeProperty(
    "http://www.w3.org/2006/time#inXSDDateTime");
Resource resource = m.createResource("someURIForThisRessource");
Statement s = m.createStatement(
    resource, inXSDDateTime, m.createTypedLiteral(someValue));
m.add(s);

It should write the result as expected (but, by doing this, you are not loading the axioms of the ontology you are referencing, so you won't be able to reason about it - but according to your comment, I'm thinking maybe that's what you want)

Upvotes: 1

Related Questions