我想通过提供向量以编程方式使用OWL生成本体。我的目标是能够在Protégé中打开生成的OWL文件并使用Jena。
输入矢量
我要传递的向量:
[[layer, network layer, data link layer, physical layer], [network, computer network], [data link], [ontology, ontology extraction]].
预期输出
输出应具有以下树状层次结构:
layer
-network layer
-data link layer
-physical layer
network
-computer network
ontology
-ontology extraction
data link
network layer
低于layer
等等的层次结构非常重要。
这是我想要生成的文件的示例:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Class rdf:about="#network"/>
<owl:Class rdf:about="#ontology"/>
<owl:Class rdf:about="#physical_layer">
<rdfs:subClassOf>
<owl:Class rdf:about="#layer"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="#data_link_layer">
<rdfs:subClassOf rdf:resource="#layer"/>
</owl:Class>
<owl:Class rdf:about="#network_layer">
<rdfs:subClassOf rdf:resource="#layer"/>
</owl:Class>
<owl:Class rdf:about="#computer_network">
<rdfs:subClassOf rdf:resource="#network"/>
</owl:Class>
<owl:Class rdf:about="#ontology_extraction">
<rdfs:subClassOf rdf:resource="#ontology"/>
</owl:Class>
</rdf:RDF>
答案 0 :(得分:5)
你的问题不是很清楚(参见上面的评论)所以我想猜测你想以编程方式创建一个类层次结构。使用Jena执行此操作的大纲代码为:
OntModel m = ... your model ... ;
NS = "http://your.domain/example#";
// define the various classes
OntClass layer = m.createClass( NS + "Layer" );
layer.setLabel( "layer", "en" );
OntClass networkLayer = m.createClass( NS + "NetworkLayer" );
layer.setLabel( "network layer", "en" );
// ...
// create the class hierarchy
layer.addSubClass( networkLayer );
// ...
// save the file
FileWriter out = null;
try {
out = new FileWriter( "./test.owl" );
m.write( out, "RDF/XML-ABBREV" );
}
finally {
if (out != null) {
try {out.close()) ) catch (IOException ignore) {}
}
}