2

Jena を使用して次の RDF/XML を生成するにはどうすればよいですか?

<rdfs:Class rdf:about="http://example.com/A#B">
    <rdfs:subClassOf>
            <rdfs:Class rdf:about="http://example.com/A" />
     </rdfs:subClassOf>
        <rdf:Property rdf:about="http://example.com/C">
            <rdfs:range rdf:resource="http://example.com/A" />
        </rdf:Property>
</rdfs:Class>   
4

3 に答える 3

9

Web には多くの Jena チュートリアルがあります。ただし、求めていることは非常に簡単です。ここに1つの解決策があります:

package example;

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;

class RdfXmlExample {
    public static void main( String[] args ) {
        new RdfXmlExample().run();
    }

    public void run() {
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM );
        String NS = "http://example.com/test#";

        OntClass a = m.createClass( NS + "A" );
        OntClass b = m.createClass( NS + "B" );

        a.addSubClass( b );

        OntProperty c = m.createOntProperty( NS + "c" );
        c.addRange( a );

        m.write( System.out, "RDF/XML-ABBREV" );
    }
}

これは以下を生成します:

<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#">
  <rdfs:Class rdf:about="http://example.com/test#B">
    <rdfs:subClassOf>
      <rdfs:Class rdf:about="http://example.com/test#A"/>
    </rdfs:subClassOf>
  </rdfs:Class>
  <rdf:Property rdf:about="http://example.com/test#c">
    <rdfs:range rdf:resource="http://example.com/test#A"/>
  </rdf:Property>
</rdf:RDF>
于 2011-07-14T15:36:42.613 に答える
0

コード + の説明

  • イエナ RDF API チュートリアル
  • SPARQL チュートリアル
  • オントロジー API の概要

http://incubator.apache.org/jena/getting_started/index.html

ジェナから始めるのにまともな場所。

于 2012-02-13T23:18:33.640 に答える