owlcs / owlapi

OWL API main repository
815 stars 314 forks source link

Triple interface for OWLAPI/Jena connection #340

Open rsgoncalves opened 9 years ago

rsgoncalves commented 9 years ago

The N-triples format output by toString() is invalid when the object of a triple is a literal; in the presence of a literal node the object should be wrapped in quotes. For replicating: it suffices to use an ontology with a data property assertion axiom with some string filler. I'm using RDFTranslator to get triples out of the input ontology, and serializing via RDFGraph.dumpTriples(...).

ignazio1977 commented 9 years ago

We can make this more literal friendly, but the toString() on RDFTriple is not supposed to produce NTriples, just a human readable representation of the triple, for debugging purposes. dumpTriples is a public method, but RDFGraph is in parsers, not api, so its interface might change - I wouldn't recommend relying on it.

On a related topic, I've seen questions on StackOverflow asking for a triple interface, for doing things like connecting Jena and OWL API without having to go through serialization/deserialization. This might be good to have, if we can get a well designed interface. Would you be able to use something like this for your purposes? If so, it'd be good if you could comment on what you'd like to have in this interface. We can then see how to fit this in the api package.

rsgoncalves commented 9 years ago

Understood. So I misinterpreted the functionality of dumpTriples(), which uses RDFTriple.toString(). My goal was basically to serialize an RDFGraph, and I expected said triples dump to be valid w.r.t. some format (the output was valid N-triples except for literals).

Getting around having to serialize and deserialize is definitely desirable. Even though this isn't a major problem for me right now, it would surely be convenient to have such interface! So in my situation I'd like to take an OWLOntology instance and serialize it in all triples formats that, e.g., Jena supports. The other use case I'll be looking into is updating a graph database with axioms (or their corresponding sets of triples) built within the OWL API. I'm testing the latter with Stardog. Both of these scenarios seem to require that unfortunate intermediate step.

ignazio1977 commented 9 years ago

I'll make a prototype for this triple interface. You can output NTriples with NTriplesDocumentFormat, in version 4 - the format is provided by the Rio libraries, and I believe it's the same NTriples Jena uses.

sesuncedu commented 9 years ago

I've been thinking quite a bit about this ; there are some big wins to being able to having multiple t and a boxes (as well as non file oriented ontology stores).

Most class & property assertions are irrelevant to classification, so there's all sorts of opportunities to make it nicer to work with instances. On Feb 9, 2015 4:06 PM, "Ignazio Palmisano" notifications@github.com wrote:

We can make this more literal friendly, but the toString() on RDFTriple is not supposed to produce NTriples, just a human readable representation of the triple, for debugging purposes. dumpTriples is a public method, but RDFGraph is in parsers, not api, so its interface might change - I wouldn't recommend relying on it.

On a related topic, I've seen questions on StackOverflow asking for a triple interface, for doing things like connecting Jena and OWL API without having to go through serialization/deserialization. This might be good to have, if we can get a well designed interface. Would you be able to use something like this for your purposes? If so, it'd be good if you could comment on what you'd like to have in this interface. We can then see how to fit this in the api package.

— Reply to this email directly or view it on GitHub https://github.com/owlcs/owlapi/issues/340#issuecomment-73590121.

valentin0h commented 9 years ago

Any update on this?

ansell commented 9 years ago

It shouldn't be too difficult to follow the same pattern that has been implemented for Sesame Rio to stream triples into OWLAPI. For Sesame Rio the code is:

// need to source your OWLAPIManager from somewhere
OWLAPIManager m = OWLManager.createOWLOntologyManager();
OWLOntology ontology = m.createOntology();

// Get any CloseableIteration<Statement> or Iterator<Statement>
// Eg, QueryResult that comes from querying Sesame databases using
RepositoryConnection methods
QueryResult result = <The result of querying a Sesame database>;

try {
    RioMemoryTripleSource source = new RioMemoryTripleSource(result);
    // OWLAPI stores metadata in format objects, so even though there was no typical format, need to push one in to store metadata in
    RioRDFXMLDocumentFormat metadataFactory = new RioRDFXMLDocumentFormatFactory();
    RioParserImpl parser = new RioParserImpl(metadataFactory);
    OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
    OWLOntologyFormat metadata = parser.parse(source, ontology, config);
} finally {
    result.close();
}

I am not familiar with Jena, but if it supplies a lazy iterator, you could stream directly through to OWLAPI in a similar fashion (once the wrapper is written). Alternatively, you could wrap Jena Triple's as Sesame Statement's and use the code above to test it out now.

Even if Jena doesn't supply a lazy iterator, the main point is that you don't need to serialize to disk to push triples through the pattern above, so any Collection would work.

sszuev commented 6 years ago

Hello everyone. There is now ONT-API which is a jena-based owlapi-impl (v5) alternative.
Any contributing are welcome.