Read a remote equivalentClass of ontology in Jena - jena

When I run "getEquivalentClass()" and my equivalentClass is remote (EX: http://dbpedia.org/data3/Film.rdf) raise error:
Cannot convert node http://dbpedia.org/data3/Film.rdf to OntClass: it does not have rdf:type owl:Class or equivalent
My code is:
OntModel m = ModelFactory.createOntologyModel();
m.read("http://localhost/ontology/my_ontology.owl#Film");
Resource r = m.getResource(outputs.get(i).getParamType().getURI().toString());
OntClass filmClass = (OntClass) r.as( OntClass.class );
for (Iterator j = filmClass.listEquivalentClasses(); j.hasNext(); ) {
System.out.println(j.next());
}
Film Ontology (my_ontology.owl#Film):
<owl:Class rdf:about="#Film">
<rdfs:subClassOf rdf:resource="#Media"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
<owl:onProperty rdf:resource="#Title"/>
</owl:Restriction>
</rdfs:subClassOf>
<owl:equivalentClass rdf:resource="http://dbpedia.org/data3/Film.rdf"/>
</owl:Class>
It's is possible? I lost many hours finding this solution.
Thanks for help me!

Answer of Dave Reynolds of Jena users list:
It's not to do with whether the resource is remote but whether the local model knows that the resource really is a class.
The easiest solution is to just set:
m.setStrictMode(false);
An alternative is to enable inference so the inference can deduce from the fact that it is the object of an owl:equivalentClass assertion that http://dbpedia.org/data3/Film.rdf must be a class. But inference is overkill here.
BTW that's the wrong URI, the dbpedia resource URI for film is actually:
http://dbpedia.org/ontology/Film

Related

Not able to generate inference for propertyChainAxiom

I am using propertyChainAxiom to build one of the inference statements. I have defined a basic ontology which defines properties and statements as below :
ex:
:isParent rdf:type owl:ObjectProperty .
:Person1 :hasParent :Person2.
:Person2 :hasParent :Person3.
:hasGrandParent owl:propertyChainAxiom (:hasParent :hasParent) .
:Person1 :hasGrandParent ?o .
I have defined ontology and thesaurus in Ontotext GraphDB and have used the OWL2-horst ruleset.
The statement :Person1 :hasGrandParent doesn't seems to return Person3 as per inferred statement. Am I missing something here ?
As Damyan said, use OWL-RL.
Reposting his comment as answer, so this question doesn't appear again in [graphdb] answers:0

support of owl:maxQualifiedCardinality and owl:minQualifiedCardinality restrictions by APACHE Jena Ont model

I am using APACHE Jena ONT model to parse RDF/XML OWL files and process them. With the current ONT model, restrictions with owl:maxQualifiedCardinality and owl:minQualifiedCardinality are not recognized in the ONT model. I also looked into the Restriction interface of org.apache.jena.ontology package and found that these restrictions are not supported, instead owl:minCardinality and owl:maxCardinality are supported. I am wondering now if there is a way that Jena ONT model can also consider these restrictions : owl:maxQualifiedCardinality, owl:minQualifiedCardinality
I will be happy if you can let me know your experience w.r.t. handlinge such restrictions and processing their data with Jena ont model
<owl:Class rdf:about="http://test#Numeric">
<rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://test#hasUnit"/>
<owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxQualifiedCardinality>
<owl:onClass rdf:resource="http://test#Scale"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:label>Numeric</rdfs:label>
</owl:Class>
Apache Jena ontology API (org.apache.jena.ontology.OntModel) does not support OWL2 DL.
You can take a look at the Jena-based alternative (i.e. ONT-API). This is another jena interface special for OWL-2, which supports such things as owl:maxQualifiedCardinality
Example:
OntModel m = OntModelFactory.createModel();
m.setID("http://test");
OntObjectProperty property = m.createObjectProperty("http://test#hasUnit");
OntClass clazz = m.createOntClass("http://test#Numeric");
clazz.addLabel("Numeric", null);
clazz.addSuperClass(m.createOntClass("http://test#Characteristic"))
.addSuperClass(m.createObjectMaxCardinality(property, 1,
m.createOntClass("http://test#Scale")));
StringWriter sw = new StringWriter();
m.write(sw, "rdf/xml");
System.out.println(sw);
// another way to create OntGraphModel:
InputStream in = new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8));
OntModel reloaded = OntManagers.createONT().loadOntologyFromOntologyDocument(in).asGraphModel();
int cardinality = reloaded.ontObjects(OntClass.ObjectMaxCardinality.class)
.mapToInt(OntClass.CardinalityRestrictionCE::getCardinality)
.findFirst().orElseThrow(IllegalStateException::new);
System.out.println(cardinality);
The Output:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://test"/>
<owl:Class rdf:about="http://test#Characteristic"/>
<owl:Class rdf:about="http://test#Scale"/>
<owl:Class rdf:about="http://test#Numeric">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onClass rdf:resource="http://test#Scale"/>
<owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
>1</owl:maxQualifiedCardinality>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://test#hasUnit"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
<rdfs:label>Numeric</rdfs:label>
</owl:Class>
</rdf:RDF>
1
And if you think that the original Jena Ontology API is more convenient, you can pass the graph back to org.apache.jena.ontology.OntModel interface:
OntModel jena = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, reloaded);
jena.write(System.out, "rdf/xml");

JAX-WS MTOM or BindingType annotation

I am bit confuse in understanding the concept of MTOM in JAX-WS service .
I have a webservice exposing a method that returns an Image .
Below is the SIB and publisher code
//#MTOM
#WebService(endpointInterface= "com.test.clear.TestImageInterface")
#BindingType(value = SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class TestImageImpl implements TestImageInterface{
#WebMethod
#Override
// Create a named image from the raw bytes.
public Image getImageByName(String name) {
Path path = Paths.get("..\..\..\"+name);
try {
byte[ ] bytes = Files.readAllBytes(path);
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Iterator iterators = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader iterator = (ImageReader) iterators.next();
ImageInputStream iis = ImageIO.createImageInputStream(in);
iterator.setInput(iis, true);
return iterator.read(0);
}
catch(IOException e) {
System.err.println(e);
return null;
}
}
}
publisher >>
Endpoint.publish("http://localhost:8080/TestWS/getImage", new TestImageImpl());
The confusion i have is to understand when to use #MTOM and when to use #BindingType annotation .
If i use either one of the annotation or use both together , i do not see any difference in the WSDL published by the publisher class .
Below is the generated WSDL
<wsp:Policy wsu:Id="TestImageImplPortBinding_MTOM_Policy">
<ns1:OptimizedMimeSerialization xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
<binding name="TestImageImplPortBinding" type="tns:TestImageInterface">
<wsp:PolicyReference URI="#TestImageImplPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
...
...
</definitions>
Also i do not see any difference in SOAP response got from Service . ie: i got
< Xop:include href:cid / > and got file as attachment in
Does that mean to enable MTOM at server side one can use either one of the annotation ?
I tried to set MTOM programmatically at publisher side after removing both the annotations from SIB like below :
SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
binding.setMTOMEnabled(true);
But then WSDL generated was not having MTOM policy at all.
So when one needs to set MTOM programmatically ?
Can some one explain the working of MIME type and MTOM .
Thanks much in advance .
I have got answer of the above posted question here >>
[ http://itdoc.hitachi.co.jp/manuals/3020/30203Y2310e/EY230716.HTM ]
[]1
Thank you everyone .

Merging ontologies in OWLAPI with same IRI's

I generally keep my ontologies in two different files.
First ontology file contains the classes, subclasses, data properties and object properties.
The second file containing all the individuals and relationships between the individuals.
So, I need to merge these two files in order to have a complete model. I wonder how this could be achieved using owlapi?
In Jena, I do this as follows:
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
null);
try {
model.read(new FileInputStream(MyOntologyFile), "...");
model.read(new FileInputStream(MyOntologyWithIndividualsFile), "...");
} catch (Exception e) {
log.error("Loading Model failed:" + e);
}
In the similar fashion when I tried to load my ontology files using owlapi, I get error:
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLObjectRenderer renderer = new DLSyntaxObjectRenderer();
File file = new File(MyOntologyFile);
File fileIndividuals = new File(MyOntologyWithIndividualsFile);
OWLOntology localOntology = null;
// Now load the local copy
try {
localOntology = manager.loadOntologyFromOntologyDocument(file);
localOntology = manager
.loadOntologyFromOntologyDocument(fileIndividuals);
} catch (OWLOntologyCreationException ex) {
ex.printStackTrace();
}
Error:
org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException: Ontology already exists. OntologyID(OntologyIRI(<http://www.semanticweb.org/lp4220/ontologies/2014/4/untitled-ontology-35>))
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:880)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:806)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:821)
Update:
As it turns out, merging of ontologies is only possible with those having different IRI's, and hence I presume it is not acceptable to divide an ontology into two with the same IRI. A solution for this (as commented by Joshua) may be to read all individuals and axioms from one ontology and then add them to an already loaded ontology.
For ontologies with distinct IRI's merging can be done as follows (example courtesy Ignazio's OWLED 2011 slides - slide no. 27):
OWLOntologyManager m = create();
OWLOntology o1 = m.loadOntology(pizza_iri);
OWLOntology o2 = m.loadOntology(example_iri);
// Create our ontology merger
OWLOntologyMerger merger = new OWLOntologyMerger(m);
// Merge all of the loaded ontologies, specifying an IRI for the
new ontology
IRI mergedOntologyIRI =
IRI.create(
"http://www.semanticweb.com/mymergedont"
);
OWLOntology merged = merger.createMergedOntology(m,
mergedOntologyIRI);
assertTrue(merged.getAxiomCount() > o1.getAxiomCount());
assertTrue(merged.getAxiomCount() > o2.getAxiomCount());
Your problem is not having the same iri in the data but ontologies with the same iris loaded in the same manager. Load the ontologies in separate managers and add all the axioms from one to the other, that will give you a merged ontology.
In general, you do not make "Individuals and Relationships" an Ontology, unless they require for classifications - say to define Class "American Company" you need an Individual "US". Otherwise, that other part is should be your RDF triples that refer to the Ontology.

Why doesn't the Jena validator give me warnings?

In the following code, the ValidityReport is always valid; there is no inconsistency detected. I expect that it should give me a warning because I am giving a family name to a FOAF document. Why isn't an inconsistency detected?
Model model = ModelFactory.createDefaultModel();
OntModel m = ModelFactory.createOntologyModel();
m.read(FOAF.NS);
Resource persona = model.createResource("http://www.example.org/rdf#Persona", FOAF.Document);
persona.addProperty(FOAF.family_name, "18", XSDDatatype.XSDint);
InfModel infModel = ModelFactory.createRDFSModel(m, model);
ValidityReport validity = infModel.validate();
if (validity.isValid()) {
System.out.println("Valid!");
} else {
System.out.println("Conflicts");
for (Iterator<Report> in = validity.getReports(); in.hasNext();) {
System.out.println(" - " + in.next());
}
}
The instance data that you're creating is this:
#prefix ex: <http://www.example.org/rdf#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Persona a foaf:Document ;
foaf:family_name "18"^^xsd:int .
There's a resource of type foaf:Document, and it has an xsd:int value for the the foaf:family_name property.
Your inference model uses an RDFS reasoner. The domain of foaf:family_name (which, by the way, is described as an archaic spelling of foaf:familyName) is foaf:Person, so ex:Persona can thus be inferred to be a foaf:Person, as we see if we write the inference model. There are a number of other types that ex:Persona is inferred to have as well:
ex:Persona a foaf:Document , foaf:Person , <http://www.w3.org/2000/01/rdf-schema#Resource> , <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing> , foaf:Agent ;
foaf:family_name "18"^^xsd:int .
It's rather hard to have inconsistencies in an RDFS model, since you can't really say a whole lot. You can't declare disjoint classes, for instance, so there's no contradiction between something being a foaf:Document and a foaf:Person.
Even if you use an OWL reasoner, you'd still need to pinpoint some particular logical inconsistency. I don't know whether any of those types that ex:Persona has are disjoint, and if they're not (or if the reasoner can't infer that they are), you're not going to find an inconsistency.

Resources