0

I want to create an ontology using Jena.

In my OntModel, I defined a class Person which is equivalent to foaf:Person because my class Person could have foaf:Person's properties and also a property that I define myself (hasHairColor).

String NS = "http://example.com/ontology#";
model = ModelFactory.createOntologyModel();
OntClass person = model.createClass(NS + "Person");
person.setEquivalentClass(FOAF.Person);

//adding a property that I define myself
DatatypeProperty hairColor = model.createDatatypeProperty(ns + "hasHairColor");
model.getOntClass(ns+"Person").addProperty(hairColor, model.createOntResource(XSD.xstring));
hairColor.setDomain(model.getOntClass(ns+"Person"));
hairColor.setRange(model.getOntResource(XSD.xstring));

I want to add foaf:Person's birthday property into my class Person, I've tried two ways but they don't seem to be the rights ways:

  1. creating a new Datatype property:
String property = "http://xmlns.com/foaf/0.1/birthday";
String typeProperty = "http://www.w3.org/2000/01/rdf-schema#Literal";
DatatypeProperty extenalProperty = model.createDatatypeProperty(property);
model.getOntClass(ns+"Person").addProperty(extenalProperty, model.getOntResource(typeProperty));
extenalProperty.setDomain(model.getOntClass(ns+"Person"));
extenalProperty.setRange(model.getOntResource(typeProperty));

In this way, it writes out the property correctly in my Ontology output file (in turtle format), but it rewrites also the foaf:birthday property:

foaf:birthday  a     owl:DatatypeProperty ;
        rdfs:domain  Lto:Person ;
        rdfs:range   rdfs:Literal .

myOnt:Person  a                         owl:Class ;
        myOnt:hasHairColor            xsd:string ;
        owl:equivalentClass           foaf:Person ;
        foaf:birthday                 rdfs:Literal .
  1. Getting the Property Resource of my OntModel:
String property = "http://xmlns.com/foaf/0.1/birthday";
String typeProperty = "http://www.w3.org/2000/01/rdf-schema#Literal";
model.getOntClass(ns+"Person").addProperty((DatatypeProperty)model.createOntResource(property), model.getOntResource(typeProperty));

In this way, it raises an error of NullPointerException so it doesn't work neither.

Could anyone show me which is the right way to do in this case? Thanks a lot in advance for your help!

Janny
  • 33
  • 6
  • what do you mean by *"rewrites also the foaf:birthday property"*? – UninformedUser Jul 22 '20 at 06:01
  • Also, you want to make generic statements for an OWL class, thus, you should not use plain RDF triples which are just the same as instance data in OWL. You have to use a subClassOf axiom that states `Person SubClassOf foaf:Person AND (hasHairColor some xsd:string) AND (foaf:birthday some rdfs:Literal)` - those `p some X` are called property restrictions, which means https://jena.apache.org/documentation/ontology/#more-complex-class-expressions is the way to go – UninformedUser Jul 22 '20 at 06:04
  • so, OWL is different from RDF, you want make a generic statement about your Person class, like *"my Person is a foaf:Person and has a hair color and has a birthday"* - that is done via OWL axioms and OWL class expressions. `A and B and ...` is called an intersection, `p some C` is called SomeValuesFrom restriction (or existential restriction) – UninformedUser Jul 22 '20 at 06:11
  • Thank you for your comment! i said it _"rewrites also the foaf:birthday property"_ because when doing _model.write(file, "TURTLE")_, the output files contains also lines: `foaf:birthday a owl:DatatypeProperty ;...`. Indeed, since I recreate this data property, it's recreated and wrote out in the output file, that's why I think this is not a proper way to do. – Janny Jul 27 '20 at 07:30
  • Thanks also for the link regarding to Restriction! As I understood, before adding an Restriction, we still need a Property, my problem is how I can import/add an external property properly to a class in my ontology model? – Janny Jul 27 '20 at 07:32

0 Answers0