没有区别。以RDF编码的OWL本体只是另一个RDF文档 - 就Jena而言,OWL语法没有特别之处。 RDF文档中的重要性在于其包含的三元组:这就是为什么您可以使用XML,海龟或N三元组编码RDF,并且它们都是等价的 - 只是写下相同三元组的不同方式。
一旦RDF工具将三元组加载到图形中(即Jena中的Model
),则它可以对来自owl:
名称空间的术语给出不同的解释。
更新
OK,在这里评论以下请求的代码生成的输出样本:
package example;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.vocabulary.*;
public class OWLOutputExample
{
public static final String PLANTS = "http://www.linkeddatatools.com/plants";
public static void main(String[] args) {
new OWLOutputExample().run();
}
public void run() {
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
setNamespaces(m);
populateOntology(m);
writeOntology(m);
}
private void setNamespaces(OntModel m) {
m.setNsPrefix("owl", OWL.getURI());
m.setNsPrefix("rdf", RDF.getURI());
m.setNsPrefix("rdfs", RDFS.getURI());
m.setNsPrefix("dc", DC_11.getURI());
m.setNsPrefix("plants", PLANTS);
}
private void populateOntology(OntModel m) {
Ontology ont = m.createOntology(PLANTS);
ont.addProperty(DC_11.title, "The LinkedDataTools.com Example Plant Ontology")
.addProperty(DC_11.description, "An example ontology written for the " +
"LinkedDataTools.com RDFS & OWL introduction tutorial");
OntClass plantType = m.createClass(PLANTS + "#planttype");
plantType.addProperty(RDFS.label, "The plant type")
.addProperty(RDFS.comment, "The class of plant types.");
}
private void writeOntology(OntModel m) {
m.write(System.out, "RDF/XML-ABBREV");
}
}
输出:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:plants="http://www.linkeddatatools.com/plants"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.linkeddatatools.com/plants">
<dc:description>An example ontology written for the LinkedDataTools.com RDFS & OWL introduction tutorial</dc:description>
<dc:title>The LinkedDataTools.com Example Plant Ontology</dc:title>
</owl:Ontology>
<owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype">
<rdfs:comment>The class of plant types.</rdfs:comment>
<rdfs:label>The plant type</rdfs:label>
</owl:Class>
</rdf:RDF>
注意rdfs:description
不是已知RDFS属性,所以我把它排除了。
我明白你在说什么,但是我想知道的是如何在Jena上面写OWL文档,你能否给我编写生成该OWL文档的代码。 – user360321
太棒了!非常感谢你。这正是我想知道的。 如果你不介意,我还有一个问题给你。我想使用这个OWL文档并为我在OWL文档中的类动态添加子类?你能告诉我一个好办法吗? – user360321
@ user360321这真的是一个单独的问题。不过,[这个答案](http://stackoverflow.com/a/18804302/1281433)有一些添加子类的例子。 –