1
任何人都知道鋤頭將數據屬性添加到Jena中。我可以輕鬆添加對象屬性,但對於數據屬性莫名其妙地不起作用,而不是在數據屬性聲明中添加屬性,而是添加註釋。也許我的代碼有問題?添加DataProperty與Jena保持聯繫
代碼
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();