0

我从网上下载了一个 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>
4

1 回答 1

6

没有区别。用 RDF 编码的 OWL 本体只是另一个 RDF 文档——就 Jena 而言,OWL 语法没有什么特别之处。RDF 文档中重要的是它包含哪些三元组:这就是为什么您可以将 RDF 编码为 XML、Turtle 或 N-三元组,它们都是等价的——只是写下相同三元组的不同方式。

一旦 RDF 工具将三元组加载到图形中(即ModelJena 中的 a),它就可以对命名空间中的术语给出不同的解释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 &amp; 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 属性,因此我将其省略了。

于 2013-10-09T07:17:04.797 回答