1
OntModel onto = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
String inputFileName = "./src/test.xml";
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
onto.read(new InputStreamReader(in), "");
//ns is the namespace...
OntClass userClass = onto.getOntClass(ns+"User");
Individual dada = onto.createIndividual(ns+"Daryl", userClass);
Property prefBathtub = onto.getProperty(ns+"prefersBathtub");
Property prefBathtubWt = onto.getProperty(ns+"prefersBathtubWeight");
dada.addLiteral(prefBathtub, true);
dada.addLiteral(prefBathtubWt, 0.30);
OutputStream out = new FileOutputStream("./src/test2.xml");
onto.write(out, "RDF/XML"); // readable rdf/xml
out.close();
如何使用OntProperty和/或DatatypeProperty而不是隻是Property?使用OntProperty和DatatypeProperty - Jena本體
通過使用屬性我得到相同數量的表現力?
你提到的.as()方法是一個方便的類似「鑄造」的工具,使它成爲一個OntProperty。謝謝伊恩! – daryl