You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Andreas Grünwald <a....@gmail.com> on 2013/04/04 03:43:07 UTC

Jena SDB - transform between data formats

Hello,
I am new to Jena, and I am wondering, if and how it is possible to convert
ontologies between different formats.

At the moment, I am leveraging Protege and the OWLAPI to store concepts,
properties and individuals in serialized OWL/XML files. I would like to
reuse the concepts (T-Box, R-Box) from these files and save them within the
new Jena triple store (Jena SDB and MYSQL). I managed to establish a
connection to the MYSQL data store via the SDB Java API. However, now I
would like to load the ontology's meta model into the database.

Ideally, it would be also very helpful if it is possible to serialize the
current database entries (either classes and properties, or individuals)
into OWL/XML format and vice versa.

Is this possible with Jena? Can you give me some hints, and code examples?
Thank you very much,
Andreas

Re: Jena SDB - transform between data formats

Posted by Dave Reynolds <da...@gmail.com>.
On 04/04/13 14:02, Shichao Dong wrote:
> hi Andreas,
> I may have the same problem last week, and I do some research and find
> http://blog.sina.com.cn/s/blog_4d2d1c700100hury.html.
> The page is Chinese, here is my translation. Moreover, I think what Dave
> means is when you create ontology using protege, you have to save it as the
> RDF/XML format.

Or Turtle.

> This is an example on read and write from OWL ontology to
> MYSQL.I hope it would help.
>
> public static IDBConnection connectDB(String DB_URL, String DB_USER,
>
> String DB_PASSWD, String DB_NAME) {
>
>       return new DBConnection(DB_URL, DB_USER, DB_PASSWD, DB_NAME);
>
> }

Beware. The code you quote here uses an ancient Jena storage layer 
called RDB. This was deprecated some time ago and has been removed from 
more recent Jena instances.

For documentation on how to use the current persistent storage layers, 
TDB and SDB, see http://jena.apache.org/documentation/index.html

Dave


Re: Jena SDB - transform between data formats

Posted by Shichao Dong <do...@gmail.com>.
hi Andreas,
I may have the same problem last week, and I do some research and find
http://blog.sina.com.cn/s/blog_4d2d1c700100hury.html.
The page is Chinese, here is my translation. Moreover, I think what Dave
means is when you create ontology using protege, you have to save it as the
RDF/XML format.This is an example on read and write from OWL ontology to
MYSQL.I hope it would help.

public static IDBConnection connectDB(String DB_URL, String DB_USER,

String DB_PASSWD, String DB_NAME) {

     return new DBConnection(DB_URL, DB_USER, DB_PASSWD, DB_NAME);

}



public static OntModel createDBModelFromFile(IDBConnection con, String name,

    String filePath) {

     ModelMaker maker = ModelFactory.createModelRDBMaker(con);

     Model base = maker.createModel(name);

     OntModel newmodel = ModelFactory.createOntologyModel(

getModelSpec(maker), base);

     newmodel.read(filePath);

     return newmodel;

}



public static OntModel getModelFromDB(IDBConnection con, String name) {

     ModelMaker maker = ModelFactory.createModelRDBMaker(con);

     Model base = maker.getModel(name);

     OntModel newmodel = ModelFactory.createOntologyModel(

getModelSpec(maker), base);

     return newmodel;

}

public static OntModelSpec getModelSpec(ModelMaker maker) {

     OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);

     spec.setImportModelMaker(maker);

     return spec;

}

//Below is testing code, read from the files and then saved in the DB, and
read from DB.

public static void test() {

     String DB_URL = "jdbc:mysql://localhost/expert";

     String DB_USER = "root";

     String DB_PASSWD = "root";

     String DB = "MySQL";

     String DB_DRIVER = "com.mysql.jdbc.Driver";



     try {

         Class.forName("com.mysql.jdbc.Driver");

     } catch (ClassNotFoundException e) {

         e.printStackTrace();

     }



     String filePath = "file:C://expert//Expert.rdf-xml.owl";

     IDBConnection con = JaneUtils.connectDB(DB_URL,DB_USER, DB_PASSWD, DB);

     System.out.println(con);



     JaneUtils.createDBModelFromFile(con, "expert",filePath);

     OntModel model = JaneUtils.getModelFromDB(con, "expert");

     JaneUtils.SimpleReadOntology(model);

}



public static void SimpleReadOntology(OntModel model) {

     for (Iterator i = model.listClasses(); i.hasNext();) {

         OntClass c = (OntClass) i.next();

         System.out.println(c.getLocalName());

     }

}
source:http://blog.sina.com.cn/s/blog_4d2d1c700100hury.html


2013/4/4 Dave Reynolds <da...@gmail.com>

> On 04/04/13 13:04, Andreas Grünwald wrote:
>
>> Thank you,
>> so as far as I understood, if I want to transform an OWL/XML ontology
>> created via the OWLAPI into Jena SDB and vice versa I have to code this by
>> myself?
>>
>
> No. I believe the OWL API, like protege, can write as well as read the
> various RDF formats including RDF/XML and Turtle.
>
> Dave
>
>
>
>  On Thu, Apr 4, 2013 at 9:18 AM, Dave Reynolds <da...@gmail.com>
>> **wrote:
>>
>>  On 04/04/13 02:43, Andreas Grünwald wrote:
>>>
>>>  Hello,
>>>> I am new to Jena, and I am wondering, if and how it is possible to
>>>> convert
>>>> ontologies between different formats.
>>>>
>>>> At the moment, I am leveraging Protege and the OWLAPI to store concepts,
>>>> properties and individuals in serialized OWL/XML files. I would like to
>>>> reuse the concepts (T-Box, R-Box) from these files and save them within
>>>> the
>>>> new Jena triple store (Jena SDB and MYSQL). I managed to establish a
>>>> connection to the MYSQL data store via the SDB Java API. However, now I
>>>> would like to load the ontology's meta model into the database.
>>>>
>>>> Ideally, it would be also very helpful if it is possible to serialize
>>>> the
>>>> current database entries (either classes and properties, or individuals)
>>>> into OWL/XML format and vice versa.
>>>>
>>>> Is this possible with Jena? Can you give me some hints, and code
>>>> examples?
>>>> Thank you very much,
>>>> Andreas
>>>>
>>>>
>>> Jena does not support OWL/XML.  You would need to export your OWL as an
>>> RDF serialization. RDF/XML is the normative serialization for OWL though
>>> Jena handles any of the RDF formats.
>>>
>>> Dave
>>>
>>>
>>>
>>
>

Re: Jena SDB - transform between data formats

Posted by Dave Reynolds <da...@gmail.com>.
On 04/04/13 13:04, Andreas Grünwald wrote:
> Thank you,
> so as far as I understood, if I want to transform an OWL/XML ontology
> created via the OWLAPI into Jena SDB and vice versa I have to code this by
> myself?

No. I believe the OWL API, like protege, can write as well as read the 
various RDF formats including RDF/XML and Turtle.

Dave


> On Thu, Apr 4, 2013 at 9:18 AM, Dave Reynolds <da...@gmail.com>wrote:
>
>> On 04/04/13 02:43, Andreas Grünwald wrote:
>>
>>> Hello,
>>> I am new to Jena, and I am wondering, if and how it is possible to convert
>>> ontologies between different formats.
>>>
>>> At the moment, I am leveraging Protege and the OWLAPI to store concepts,
>>> properties and individuals in serialized OWL/XML files. I would like to
>>> reuse the concepts (T-Box, R-Box) from these files and save them within
>>> the
>>> new Jena triple store (Jena SDB and MYSQL). I managed to establish a
>>> connection to the MYSQL data store via the SDB Java API. However, now I
>>> would like to load the ontology's meta model into the database.
>>>
>>> Ideally, it would be also very helpful if it is possible to serialize the
>>> current database entries (either classes and properties, or individuals)
>>> into OWL/XML format and vice versa.
>>>
>>> Is this possible with Jena? Can you give me some hints, and code examples?
>>> Thank you very much,
>>> Andreas
>>>
>>
>> Jena does not support OWL/XML.  You would need to export your OWL as an
>> RDF serialization. RDF/XML is the normative serialization for OWL though
>> Jena handles any of the RDF formats.
>>
>> Dave
>>
>>
>


Re: Jena SDB - transform between data formats

Posted by Andreas Grünwald <a....@gmail.com>.
Thank you,
so as far as I understood, if I want to transform an OWL/XML ontology
created via the OWLAPI into Jena SDB and vice versa I have to code this by
myself?

Best regards,
Andreas


On Thu, Apr 4, 2013 at 9:18 AM, Dave Reynolds <da...@gmail.com>wrote:

> On 04/04/13 02:43, Andreas Grünwald wrote:
>
>> Hello,
>> I am new to Jena, and I am wondering, if and how it is possible to convert
>> ontologies between different formats.
>>
>> At the moment, I am leveraging Protege and the OWLAPI to store concepts,
>> properties and individuals in serialized OWL/XML files. I would like to
>> reuse the concepts (T-Box, R-Box) from these files and save them within
>> the
>> new Jena triple store (Jena SDB and MYSQL). I managed to establish a
>> connection to the MYSQL data store via the SDB Java API. However, now I
>> would like to load the ontology's meta model into the database.
>>
>> Ideally, it would be also very helpful if it is possible to serialize the
>> current database entries (either classes and properties, or individuals)
>> into OWL/XML format and vice versa.
>>
>> Is this possible with Jena? Can you give me some hints, and code examples?
>> Thank you very much,
>> Andreas
>>
>
> Jena does not support OWL/XML.  You would need to export your OWL as an
> RDF serialization. RDF/XML is the normative serialization for OWL though
> Jena handles any of the RDF formats.
>
> Dave
>
>

Re: Jena SDB - transform between data formats

Posted by Dave Reynolds <da...@gmail.com>.
On 04/04/13 02:43, Andreas Grünwald wrote:
> Hello,
> I am new to Jena, and I am wondering, if and how it is possible to convert
> ontologies between different formats.
>
> At the moment, I am leveraging Protege and the OWLAPI to store concepts,
> properties and individuals in serialized OWL/XML files. I would like to
> reuse the concepts (T-Box, R-Box) from these files and save them within the
> new Jena triple store (Jena SDB and MYSQL). I managed to establish a
> connection to the MYSQL data store via the SDB Java API. However, now I
> would like to load the ontology's meta model into the database.
>
> Ideally, it would be also very helpful if it is possible to serialize the
> current database entries (either classes and properties, or individuals)
> into OWL/XML format and vice versa.
>
> Is this possible with Jena? Can you give me some hints, and code examples?
> Thank you very much,
> Andreas

Jena does not support OWL/XML.  You would need to export your OWL as an 
RDF serialization. RDF/XML is the normative serialization for OWL though 
Jena handles any of the RDF formats.

Dave