I have instance1
of class1
and instance2
of class2
。我也定义了HasName(object property)
在我的本体论中。现在,我如何添加三重(instance1 HasName instance2
)到 jena 的本体论?
这是一种无需处理中间的方法Statements
.
// RDF Nodes -- you can make these immutable in your own vocabulary if you want -- see Jena's RDFS, RDF, OWL, etc vocabularies
Resource class1 = ResourceFactory.createResource(yourNamespace + "class1");
Resource class2 = ResourceFactory.createResource(yourNamespace + "class1");
Property hasName = ResourceFactory.createProperty(yourNamespace, "hasName"); // hasName property
// The RDF Model
Model model = ... // Use your preferred method to get an OntModel, InfModel, or just regular Model
Resource instance1 = model.createResource(instance1Uri);
Resource instance2 = model.createResource(instance2Uri);
// Create statements
instance1.addProperty(RDF.type, class1); // Classification of instance1
instance2.addProperty(RDF.type, class2); // Classification of instance2
instance1.addProperty(hasName, instance2); // Edge between instance1 and instance2
您还可以以构建器式模式链接其中一些调用。
Resource instance2 = model.createResource(instance2Uri).addProperty(RDF.type, class2);
model.createResource(instance1Uri).addProperty(RDF.type, class1).addProperty(hasName, instance2);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)