在三元组中添加空白节点
下面编写的代码给出以下输出:
代码:
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>
提前致谢。
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: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>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您在 bNode
person
上以某种方式错误地循环。您始终使用相同的 bNode,这可能是错误的原因。因此,如果您的代码看起来像...
那么错误是您正在使用相同的 bNode 实例。您的代码应类似于下面的代码片段。请注意,bNode 创建是在循环内进行的,这是主要区别。
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 ...
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.
你的问题在这里有点模糊,首先你想要的输出实际上是无效的 RDF/XML,所以即使你想生成它也无法生成。您是否尝试过通过 W3C RDF Validator 运行它?它到底来自哪里?
您尝试生成适合特定模式的 RDF/XML 是否有原因?
恕我直言,这是非常糟糕的做法,你真的不应该尝试这样做。
RDF 的要点在于它是一个基于三元组的数据模型,与数据的实际序列化分离。您真的不应该尝试基于所需的序列化创建 RDF,您应该创建表达数据的 RDF 三元组,从您显示的最小代码片段来看,这似乎就是您正在做的事情。
所以我再次重申,为什么需要以特定样式生成 RDF/XML?假设您有某种原因这样做,可能有更好的方法来实现您的实际目标,并且如果您提供更多详细信息,人们将有更好的机会能够适当地帮助您
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