writing ontModel as owl not as rdf by jena - jena

I have a owl ontology, I read it into Jena OntModel. then I update it at runtime. Now I want to write it back as a OWL ontology. I am using the code below:
RDFWriter writer = model.getWriter("RDF/XML");
writer.write(model, out, root_uri);
... gives me RDF syntax and not the OWL syntax. How can I write the OntModel into OWL syntax?
Any solution?

Welcome to StackOverflow! Jena doesn't support the OWL/XML syntax. It only support various RDF syntaxes, including RDF/XML and Turtle. See here for Jena's supported formats.
So you either need to work with one of these syntaxes (which can express all of OWL just fine).
Or switch to a different library that supports OWL/XML, like the OWL API.

Of course, if you are using getWriter("RDF/XML"), it will be written in RDF/XML, which is one serialisation format for RDF and all RDF formats are serialisation syntaxes for OWL.
There is very few cases when one needs to use a non-RDF syntax when writing OWL programmatically but if you want to do so, try using the OWL API, which can write OWL in OWL/XML, in OWL 2 Manchester syntax, or in OWL 2 functional syntax.

Related

XQuery vs. XPath 3.1 (in Saxon)

We are using Saxon purely to query data. We're about to update to XPath 3.1. For reading queries (no insert/update/delete) is there any difference between XPath 3.1 and XQuery (latest version)?
If so, what? I'm asking to determine if we should implement an XQuery API in our system along with the XPath 3.1?
The main differences are:
XQuery has node constructors (e.g. <out>{/x/y}</out>
XQuery has full FLWOR expressions with order by, group by, window clauses etc.
So XQuery is a bit more powerful for complex queries, but more importantly, it allows construction of a new XML document to represent the result.

Usage of rdf & owl to markup WebGL content

i have given scene in webGL of a pizza for example. Now i want to make the content in the scene semantic visible for maschines with a custom owl and rdf for example.
When i make a owl ontologie with protege can i just use this ontology like here
https://support.google.com/webmasters/answer/146898 and instead of linking to
http://rdf.data-vocabulary.org/# i link to my own ontology and use my properties, tags etc. ?
WebGL is an API. Any data is outside the scope of WebGL. There is nothing to markup or add any ontology to.
Maybe you're looking for something like X3DOM?

Using SWRL with Jena and Pellet

I was unable to find some decent simple code examples of using SWRL and Jena with
Pellet, or at least using SWRL? I have studied some examples in Pellet documentation, but there is no example about using SWRL. Most examples on the web are incomplete and confusing.
The only solution I found was with the Jess Rule Engine but it is not free and is under commercial license. I found that Pellet support SWRL rules but could not find running example.
The only example I found is this, but I do not understand it:
OWLOntologyManager m = create();
OWLOntology o = m.createOntology(example_iri);
// Get hold of references to class A and class B.
OWLClass clsA = df.getOWLClass( IRI.create(example_iri + "#A" ));
OWLClass clsB = df.getOWLClass(IRI.create(example_iri + "#B" ));
SWRLVariable var = df.getSWRLVariable(IRI.create(example_iri + "#x" ));
SWRLClassAtom body = df.getSWRLClassAtom(clsA, var);
SWRLClassAtom head = df.getSWRLClassAtom(clsB, var);
SWRLRule rule = df.getSWRLRule(Collections.singleton(body),
Collections.singleton(head));
m.applyChange(new AddAxiom(o, rule));
Pellet Rules and Jena Rules are Very Different™
The short answer is that Pellet supports SWRL rules. If you have an ontology that contains SWRL rules and ask Pellet to reason over it, it will take them into consideration.
Jena has its own rules language, which is described in the documentation page, Reasoners and rule engines: Jena inference support. It supports both forward and backward chaining rules.
However, though both Pellet and Jena support a notion of rules, the intended domains of SWRL rules and Jena rules are very different. SWRL rules are OWL-level constructs; the unary predicates in a SWRL rule are class expressions, and the binary predicates are object and data properties. Additionally, SWRL rules only match on named individuals; they don't match for individuals whose existence is only inferred. Jena rules, on the other hand, are RDF-level, and designed to work on RDF-graphs. While RDF and OWL are often used together, (e.g., OWL data is serialized in RDF), the two are conceptually distinct. An OWL reasoner could be implemented that makes no use of RDF, and a SWRL engine could be built that make no use of RDF graphs.
Jena or OWL API?
The code that you've shown, based on the presence of an OWLOntologyManager, is based on the OWL API, not on Jena's API. The OWL API will have more direct functionality for working with OWL and SWRL rules, while Jena will not. (Jena's OntModels work well with OWL1, but support for OWL2 is not complete (and still “open for contributors”).
Rather than using the OWL API or trying to use Jena's API, you'll probably find it easier to create rules using an editor such as Protégé. Martin Kuba has written a very nice OWL2 and SWRL Tutorial that can help you here.
SWRL rules work with Pellet API. I created my ontology and SWRL rules using Protégé and I was able to create OWL individuals dynamically using Java code. This whole ontology is used as aggregatedOwl in the following code. This code loads ontology (base OWL + individuals if any + SWRL rules) and runs the Pellet reasoner on it and saves the inferred result in a string.
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.StringDocumentTarget;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.util.InferredAxiomGenerator;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator;
import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
try {
manager = OWLManager.createOWLOntologyManager();
InputStream owlInputStream = new ByteArrayInputStream(aggregatedOwl.getBytes("UTF-8"));
inferredOntology = manager.loadOntologyFromOntologyDocument(owlInputStream);
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(inferredOntology);
reasoner.getKB().realize();
List<InferredAxiomGenerator<? extends OWLAxiom>> axiomGenerators = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
axiomGenerators.add( new InferredPropertyAssertionGenerator() );
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,axiomGenerators);
iog.fillOntology(manager, inferredOntology);
// Save the new ontology
OutputStream owlOutputStream = new ByteArrayOutputStream();
manager.saveOntology(inferredOntology, owlOutputStream);
inferredData = owlOutputStream.toString();
}
catch ( Exception e ) {
throw new Exception("Exception occurred in applying reasoner");
}
Hope this is helpful to you.

What "pun", "punning" stand for in terms of Protege?

I'am a new to ontologies and Protege and I sometimes meet such words as "pun" or "punning". However, I do not have a clue what they mean. Can you clarify it for me?
"Punning" is not something that comes from Protégé but it's a feature of the Web Ontology Language OWL 2 DL, which Protégé is an editor for. "Punning" refers to the possibility of naming terms of different natures with the same IRI. For instance, you can use the same IRI for a class and for an instance, for a property and an instance, or for a class and a property. In OWL 2 DL, the context always makes it clear whether the IRI is used as a class, a property or an instance. See Section 2.4.1 of OWL 2 New Features and Rationale.

How to convert ontology from DAML to OWL

I'm trying to convert this DAML ontology into OWL (or any other supported by Protege) format. I found an online converter, but the attempt of opening the result of conversion by protege entailed the following error message:
org.semanticweb.owlapi.rdf.syntax.RDFParserException: [line=21:column=39] IRI '#To Interpret' cannot be resolved against curent base IRI file:/home/citxx/Downloads/musicV1.0.xml
There is the result of conversion.
What is wrong with the mentioned converter? Or is there another ways of conversion DAML ontologies into Protege-compatible format?
Two things, spaces can't be in the rdf:ID unless they are escaped, those have to end up forming valid URI's. Also, it doesnt look like there's a defined xml base in that file, which is also a problem.
You might be better off just doing the conversion by hand, its a very basic ontology, and it would not take you long to recreate it in Protege.

Resources