[英]How to create OWL document
我已經從網上下載了OWL文件,我需要知道如何使用Jena編寫該文件。 我可以編寫普通的RDF文檔,但不能理解編寫OWL文檔。 OWL文件的內容如下。
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<!-- OWL Header Example -->
<owl:Ontology rdf:about="http://www.linkeddatatools.com/plants">
<dc:title>The LinkedDataTools.com Example Plant Ontology</dc:title>
<dc:description>An example ontology written for the LinkedDataTools.com RDFS & OWL introduction tutorial</dc:description>
</owl:Ontology>
<!-- OWL Class Definition Example -->
<owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype">
<rdfs:label>The plant type</rdfs:label>
<rdfs:comment>The class of plant types.</rdfs:comment>
<rdfs:description> Plant type description </rdfs:description>
</owl:Class>
</rdf:RDF>
沒有區別 用RDF編碼的OWL本體只是另一個RDF文檔-就Jena而言,OWL語法沒有什么特別之處。 RDF文檔中重要的是它包含的三元組:這就是為什么您可以將RDF編碼為XML,Turtle或N-triples,它們都是等效的-只是寫下相同三元組的方式不同。
一旦RDF工具將三元組加載到圖形中(即Jena中的Model
),就可以對owl:
名稱空間中的術語進行不同的解釋。
更新資料
好的,以下注釋中的請求是生成您的輸出樣本的代碼:
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屬性,因此我將其省略。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.