[英]Using OntProperty and DatatypeProperty - Jena Ontology
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?
通过使用Property,我可以获得相同数量的表现力吗?
要从本体模型获取ObjectProperty
对象,请使用OntModel.getObjectProperty
() 。 在数据类型属性等方面也是如此Ont
类在某种意义上更具表现力,因为它们包含方便的API,以便通过一个方法调用来获取例如属性的超级属性。 但是,由于便捷API仅访问图形中的基础三元组,因此严格来说,您无法使用ObjectProperty
来执行与Property
不能执行的任何操作。 这只是更辛苦的工作!
顺便说一句,Jena允许您使用.as()
方法访问基础RDF资源的其他方面。 所以:
Property p = myModel.getProperty( "http://example.com/foo#p" );
OntProperty op = p.as( OntProperty.class );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.