开发者

Adding blank nodes in triples

The code written below gives the following output:

Code:

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)))

Output:

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

<rdf:De开发者_如何学Goscription 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>

But I need following output, could you please guide what is wrong with it.

<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>

Thanks in advance.


It seems that you are looping somehow wrongly over the bNode person. You are using always the same bNode, that might be the cause of the error.

So if your code looks like ...

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)))

Then the error is that you are using the same bNode instance. Your code should look like the snippet below. Notice that the bNode creation is inside the loop, that is the main difference.

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)))


Your question is a little vague here, for a start your desired output is actually invalid RDF/XML so you couldn't generate it even if you wanted to. Did you even try to run it through the W3C RDF Validator and where exactly did it come from?

Is there a reason why you are trying to generate RDF/XML that fits a particular pattern?

IMHO this is very bad practise and you really shouldn't try to do this.
The whole point of RDF is that it is a triple based data model that is separate from the actual serialization of the data. You should really never try to create RDF based on a desired serialization, you should be creating RDF triples that express your data which from the minimal code snippet you have shown seems to be what you are doing.

So I'd reiterate again, why do you need to generate RDF/XML in a particular style? Assuming you have some reason for this there may be a better way of achieving whatever your actual goal is and if you provide more detail people will have a better chance of being able to help you appropriately

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜