OWLAPI ObjectPropertyChain axioms - owl

We know that in Protege is possible to create axioms with role chain and since Protege is based on OWLAPI should be possible to create them.
I did not found examples in the official documentation, so it is possible to do it?
One example here:
With the OWL syntax we have:
Declaration( ObjectProperty( :isEmployedAt ) )
ObjectPropertyAssertion( :isEmployedAt :Martin :SC )
SubObjectPropertyOf( ObjectPropertyChain( :isEmployedAt :isPartOf ) :isEmployedAt)
So, what is the equivalent in OWLAPI?

OWLDataFactory::getOWLSubPropertyChainOfAxiom(java.util.List<? extends OWLObjectPropertyExpression> chain,OWLObjectPropertyExpression superProperty)
See Javadoc

Related

SWRL Rules with data property values and range

I am writing a SWRL rule in OWL which can infer if a person is of driving age or not.
Person(?p), xsd:int[>= "18"^^xsd:int <= "65"^^xsd:int](?age), hasAge(?p, ?age) -> isDriverAge(?p, "True"xsd:Boolean)
It gives me Unexpected Character '[' error
I saw similar syntax for Object Property (found here: https://dior.ics.muni.cz/~makub/owl/ ) but that is also not working when I tweaked my ontology as per this code:
Person(?p), int[>= 18 , <= 65](?age), hasAge(?p, ?age) -> hasDriverAge(?p, True)
If you know the answer, could you please also provide me a resource which I can refer to write these rules. I don't want to keep coming back to stack and eat up other dev's time. Thanks

Add or update VersionIRI through OWL API

I have an ontology IRI without version. How to add or update version IRI of a particular OWL ontology ?
You need to create a change object that sets the ontology id.
So, if you have an ontology o with an IRI but no version IRI:
OWLOntology o = ...
IRI versionIRI=IRI.create("version");
SetOntologyID change=new SetOntologyID(o,
new OWLOntologyID(o.getOntologyID().getIR(), Optional.of(versionIRI)));
o.getOWLOntologyManager().applyChange(change);

Reflexive property in protege

This is my ontology created with protege 5 .
If i make cl1 and cl2 disjoint, then the ontology is being inconsistent , but if i uncheck is_friend_of reflexive , the ontology is not inconsistent any more . whats wrong with my ontology ?
I want only cl1 class individuals have is_friend_of property.
Reflexivity of :is_friend_of is essential for inconsistency.
Take a look at Reasoner > Inconsistent ontology explanation :
I'll try to translate this explanation into (poor) English:
Since :is_friend_of is reflexive, then :c2_inst :is_friend_of :c2_inst.
Since the domain of :is_friend_of is :cl1, then c2_inst rdf:type :cl1.
Also, c2_inst rdf:type :cl2.
But :cl1 and :cl2 are disjoint — contradiction.
In fact, the domain of every reflexive property is owl:Thing.
As a workaround, you could uncheck reflexivity of is_friend_of and define :cl1 in this way:
Class: cl1
EquivalentTo:
is_friend_of some owl:Thing,
is_friend_of some Self

How to set the Ontology ID of an anonymous Ontology using the OWL API

I have a file containing an ontology without an ontology id (the ontology tag <Ontology/> is empty). The used serialization format is RDF/XML. My goal is to serialize the file, set an ontology id and write the file back using the OWLAPI. Unfortunatly I don't know how to do this. I tried the following:
ontology = ontologyManager.loadOntologyFromOntologyDocument(new File("filename"));
ontologyManager.setOntologyDocumentIRI(ontology, IRI.create("http://www.mydesiredIri.com/abc"));
ontologyManager.saveOntology(ontology,new FileOutputStream(new File("outputfile")));
By running the code, the Ontology-ID is not added to the ontology. Instead of <Ontology rdf:about="http://www.mydesiredIri.com/abc"/> the tag is still emtpy. What I am doing wrong?
Thank you!
Kind regards
OWLOntologyManager.setOntologyDocumentIRI() is for setting the document IRI of the ontology, not the ontology IRI itself. The difference between the two is that the document IRI is a resolvable URL or a file path (i.e., int can be used to parse the ontology), while the ontology IRI is the symbolic name of the ontology (it does not need to be resolvable and it can even be missing - which is the case for anonymous ontologies).
To set the ontology IRI, use:
//versionIRI can be null
OWLOntologyID newOntologyID = new OWLOntologyID(ontologyIRI, versionIRI);
// Create the change that will set our version IRI
SetOntologyID setOntologyID = new SetOntologyID(ontology, newOntologyID);
// Apply the change
manager.applyChange(setOntologyID);
After this, save the ontology as usual.

SQL Like in OWL API for data properties

In OWL API, classes may have data properties. For e.g. a class may have a date property hasCommonName "Something". In OWL API, is there any facility like the SQL like which allows querying for classes that hasCommonName containing the word "Some", just like SQL like behave
You can use regular expressions to identify the things you need. Consider the following knowledge base:
DataProperty: hasCommonName
Individual: foo
Facts:
hasCommonName "Something"
You can retrieve the individual foo by using the following class expression: hasCommonName some string[pattern "Some.*"]. The string[pattern "Some.*"] specifies the pattern to be matched. Warning, currently not supported by all reasoners (works for Hermit 1.3.7)
You need to look at some SPARQL tutorials. You can write something like this:
SELECT * WHERE
{
?pizza rdfs:subClassof [
owl:onProperty :hasTopping;
owl:someValuesFrom :TomatoTopping ] .
}
Basically, you need to define the correct predicate based on your restriction.

Resources