0

私は Jena を使用してオントロジーをクエリしています。このチュートリアルの Step 8: Querying a Modelに従っています。ここで照会されるRDF ファイルvc-db-1.rdfは、ステップ 3: RDFの作成から生成され、以下に示されています。

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" > 
  <rdf:Description rdf:nodeID="A0">
    <vcard:Family>Smith</vcard:Family>
    <vcard:Given>John</vcard:Given>
  </rdf:Description>
  <rdf:Description rdf:about="http://somewhere/JohnSmith">
    <vcard:N rdf:nodeID="A0"/>
    <vcard:FN>John Smith</vcard:FN>
  </rdf:Description>
</rdf:RDF>

サンプル コードはチュートリアル 7で、ここからダウンロードできます。

ラインで気づいた

ResIterator iter = model.listResourcesWithProperty(VCARD.FN);

VCARD.FNは RDF からのプロパティ名にすぎませんが、私のコードで定義された変数ではありません。ただし、ここでは正常に認識され、コードは問題なく実行されます。

しかし、これは私自身の RDF ファイルには当てはまりません。Protege でオントロジーpottery.owlを作成し、RDF/XML 言語で保存しました。ファイルの内容は次のとおりです。

<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
    xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns="http://www.owl-ontologies.com/Ontology1369190090.owl#"
    xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://www.owl-ontologies.com/Ontology1369190090.owl" > 
  <rdf:Description rdf:about="">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
  <rdf:Description rdf:about="#pottery">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="#pottery_instance_1">
    <rdf:type rdf:resource="#pottery"/>
    <pottery.colors rdf:datatype="http://www.w3.org/2001/XMLSchema#string">blue</pottery.colors>
  </rdf:Description>
  <rdf:Description rdf:about="#pottery.colors">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#pottery"/>
  </rdf:Description>
</rdf:RDF>

<!-- Created with Protege (with OWL Plugin 3.4.8, Build 629)  http://protege.stanford.edu -->

オントロジーにはクラスpottery、インスタンスpottery_instance_1、およびデータ型プロパティpottery.colorsが含まれています。

そして、元のコードでこれらの行を変更しました。

static final String inputFileName = "pottery.owl";
// ...
ResIterator iter = model.listResourcesWithProperty(pottery.colors);
// ...
System.out.println("  " + iter.nextResource()
                              .getProperty(pottery.colors)
                              .getString());

今回は「陶器は変数に解決できません」というエラーが出ました。

ここでのトリックは何ですか?2 つの RDF のフォーマットの違いと関係がありますか? または、他の何か?ありがとうございました。

4

1 に答える 1

1

VCARDpackage で定義されている Java クラスcom.hp.hpl.jena.vocabularyです。これには、(現在は古い) VCard ボキャブラリのすべての項目の Java 定数が含まれています。

オントロジーから独自のクラスを生成したい場合は、schemagenJena に同梱されているアプリケーションを見てください。

于 2013-05-22T08:08:41.847 に答える