Reputation: 131
Anyone knows hoe to add Data Property in protege with Jena. I can easily add Object Property but for Data Property somehow doesn't work, instead of adding Properties in Data Property assertion it's adding the Annotation. Maybe something wrong with my code?
Code
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
String NS = "http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology#";
model.read(in, null);
in.close();
OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel");
Individual AM20 = model.createIndividual(NS + xmlDoc.getDocumentElement().getAttribute("guid")+ theAttribute.getNodeValue(), ApplicationModel);
Individual dom = model.getIndividual(NS + domainElement.getAttribute(attrDomain));
Individual pha = model.getIndividual(NS + neededString.trim());
Individual lev = model.getIndividual(NS + lodElement.getAttribute(attrLOD));
Individual typ = model.getIndividual(NS + theAttrType.getNodeValue());
Property urlAdd = model.createProperty(NS + "http://xxxxx.com");
// Create Object Property
ObjectProperty domain = model.createObjectProperty(NS +"hasDomain");
ObjectProperty fase = model.createObjectProperty(NS +"hasPhase");
ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail");
ObjectProperty type = model.createObjectProperty(NS +"hasType");
model.add(AM20, domain, dom);
model.add(AM20, fase, pha);
model.add(AM20, lod, lev);
model.add(AM20, type, typ);
// Create Data Property
DatatypeProperty url = model.createDatatypeProperty(NS + "hasURL");
model.add(AM20, url, urlAdd );
PrintStream p= new PrintStream("./src/thesis_ontology.owl");
model.write(p, "RDF/XML-ABBREV", null);
p.close();
Upvotes: 1
Views: 925
Reputation: 131
I guess I found the problem. Hope it can help someone someday :D
the code should be like this
OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel");
Individual AM20 = model.createIndividual(NS + xmlDoc.getDocumentElement().getAttribute("guid")+ theAttribute.getNodeValue(), ApplicationModel);
Individual dom = model.getIndividual(NS + domainElement.getAttribute(attrDomain));
Individual pha = model.getIndividual(NS + neededString.trim());
Individual lev = model.getIndividual(NS + lodElement.getAttribute(attrLOD));
Individual typ = model.getIndividual(NS + theAttrType.getNodeValue());
// Create Object Property
ObjectProperty domain = model.createObjectProperty(NS +"hasDomain");
ObjectProperty fase = model.createObjectProperty(NS +"hasPhase");
ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail");
ObjectProperty type = model.createObjectProperty(NS +"hasType");
model.add(AM20, domain, dom);
model.add(AM20, fase, pha);
model.add(AM20, lod, lev);
model.add(AM20, type, typ);
// Create Data Property
DatatypeProperty url = model.createDatatypeProperty(NS + "hasURL");
model.add(AM20, url, "http://...");
Upvotes: 4