2

以下に記述されたコードは、次の出力を提供します。

コード:

person = BNode()
dataStore.add((URIRef(stringrd),FOAF_NS['knows'],person))
dataStore.add((person,FOAF_NS['Person'],URIRef(fetchKnowsRowString)))
dataStore.add((person,TRUST_NS['hasValue'],Literal(trustString)))

出力:

<rdf:Description rdf:about="http://www.iamresearcher.com/profiles/id/luc.moreau">
  <foaf:knows rdf:nodeID="kdOAGjqG160"/>
</rdf:Description>

<rdf:Description rdf:nodeID="kdOAGjqG160">
  <t:data>1</t:data>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/patrick.hayes"/>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/christian.queinnec"/>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/thanassis.tiropanis"/>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/ian.foster"/>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/nicholas.gibbins"/>
</rdf:Description>

しかし、次の出力が必要です。何が問題なのか教えてください。

<rdf:Description rdf:about="http://www.iamresearcher.com/profiles/id/luc.moreau">
<foaf:knows>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/patrick.hayes">
    <t:data>1</t:data>
  </foaf:Person>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/christian.queinnec">
    <t:data>1</t:data>
  </foaf:Person>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/thanassis.tiropanis">
    <t:data>1</t:data>
  </foaf:Person>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/ian.foster">
    <t:data>1</t:data>
  </foaf:Person>
  <foaf:Person rdf:resource="http://www.iamresearcher.com/profiles/id/nicholas.gibbins">
    <t:data>1</t:data>
  </foaf:Person>
</foaf:knows>
</rdf:Description>

前もって感謝します。

4

2 に答える 2

0

ここでの質問は少しあいまいです。最初は、目的の出力が実際には無効な RDF/XML であるため、生成したくても生成できませんでした。W3C RDF Validatorを介して実行しようとさえしましたか? それは正確にはどこから来たのですか?

特定のパターンに適合する RDF/XML を生成しようとしている理由はありますか?

IMHOこれは非常に悪い習慣であり、実際にこれを行うべきではありません。
RDF の要点は、データの実際のシリアル化とは別のトリプル ベースのデータ モデルであるということです。目的のシリアライゼーションに基づいて RDF を作成しようとするべきではありません。データを表現する RDF トリプルを作成する必要があります。

繰り返しになりますが、なぜ RDF/XML を特定のスタイルで生成する必要があるのでしょうか? これに何らかの理由があると仮定すると、実際の目標が何であれ、それを達成するためのより良い方法があるかもしれません.

于 2011-09-18T17:22:49.603 に答える
0

bNode を何らかの形で間違ってループしているようですperson。常に同じ bNode を使用しているため、エラーの原因である可能性があります。

したがって、コードが次のようになっている場合...

person = BNode()
for (fetchKnowsRowString, trustString) in friends:
   dataStore.add((URIRef(stringrd),FOAF_NS['knows'],person))
   dataStore.add((person,FOAF_NS['Person'],URIRef(fetchKnowsRowString)))
   dataStore.add((person,TRUST_NS['hasValue'],Literal(trustString)))

エラーは、同じ bNode インスタンスを使用していることです。コードは以下のスニペットのようになります。bNode の作成はループ内にあることに注意してください。これが主な違いです。

for (fetchKnowsRowString, trustString) in friends:
   person = BNode()
   dataStore.add((URIRef(stringrd),FOAF_NS['knows'],person))
   dataStore.add((person,FOAF_NS['Person'],URIRef(fetchKnowsRowString)))
   dataStore.add((person,TRUST_NS['hasValue'],Literal(trustString)))
于 2011-09-16T04:05:06.790 に答える