Rowlex - 只获取“root”文档的个体

发布于 2024-12-03 05:14:49 字数 1426 浏览 2 评论 0原文

这是我的 rdf 文档,它是由 rowlex 库生成的:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
         xmlns:ns="http://xmlns.com/foaf/0.1/" 
         xmlns:privateinfos="http://domain/privateinfos/"> 

    <ns:Person rdf:about="Node 1">
        <ns:depiction rdf:resource="Default.png" />
        <privateinfos:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Description</privateinfos:description>
        <ns:knows>
            <ns:Person rdf:about="6779ac10-210b-40d2-8111-711db6988bb9" />
        </ns:knows> 
    </ns:Person>

    <ns:Person rdf:about="Node 2">
        <ns:depiction rdf:resource="Default.png" />
        <privateinfos:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Description 2</privateinfos:description>
    </ns:Person>

</rdf:RDF>

我正在尝试使用此代码检索节点 1 和节点 2 个体:

List<Person> person_list = new List<Document>();
OwlThing[] Persons = _rdfDocument.GetIndividuals(Person.Uri, true);

foreach (Person item_found in Persons)
{
    person_list.Add(item_found);
}

return person_list;

不幸的是 person_list 返回以下数据:

[0] : Node 1
[1] : 6779ac10-210b-40d2-8111-711db6988bb9
[2] : Node 2

那么有没有一种方法/方法可以仅获取节点1 和 2 在列表中没有它们的子元素? (当然,个人 ID 是动态生成的,因此我无法搜索特定 ID)

谢谢。

here is my rdf document which is generated by the rowlex library :

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
         xmlns:ns="http://xmlns.com/foaf/0.1/" 
         xmlns:privateinfos="http://domain/privateinfos/"> 

    <ns:Person rdf:about="Node 1">
        <ns:depiction rdf:resource="Default.png" />
        <privateinfos:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Description</privateinfos:description>
        <ns:knows>
            <ns:Person rdf:about="6779ac10-210b-40d2-8111-711db6988bb9" />
        </ns:knows> 
    </ns:Person>

    <ns:Person rdf:about="Node 2">
        <ns:depiction rdf:resource="Default.png" />
        <privateinfos:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Description 2</privateinfos:description>
    </ns:Person>

</rdf:RDF>

And I am trying to retrieve the Node 1 and Node 2 individuals with this code :

List<Person> person_list = new List<Document>();
OwlThing[] Persons = _rdfDocument.GetIndividuals(Person.Uri, true);

foreach (Person item_found in Persons)
{
    person_list.Add(item_found);
}

return person_list;

unfortunatly person_list returns with the following data :

[0] : Node 1
[1] : 6779ac10-210b-40d2-8111-711db6988bb9
[2] : Node 2

So is there a way/methode to get only the node 1 and 2 without their sub elements in the list ? (of courses the individuals ID's are dynamically generated so i can't search for a specific ID)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2024-12-10 05:14:49

我认为这里对 RDF 和 XML 存在一些误解。 RDF 是一组三元组,可以用 XML 和其他序列化格式表示。与 XML 不同,RDF 不是分层的,因此RDF 中不存在“子元素”这样的东西。事实上,Mr. Guid 就在 Mr Node_1 之下,这是由误导性的 XML 节点层次结构“暗示”的幻觉。为了证明这一点,我列出了示例的三元组(请注意,RDF 中三元组的顺序无关!):

"Node 1" typeOf Person
“节点 1”描述“Default.png”
“节点 1”描述“描述”
“节点 1”认识“Guid 先生”
“Guid先生”类型人物
“节点 2”类型人
“节点 2”描述“Default.png”
“节点 2”描述“描述”

尝试以下操作:
再添加一个三元组:
“Mr. Guid”知道“Node 1”,代码如下:

Person mrGuid = _rdfDocument.GetIndividual("6779ac10-210b-40d2-8111-711db6988bb9") as Person;
Person mrNode1 = _rdfDocument.GetIndividual("Node 1") as Person;
mrGuid.knows = mrNode1;
Console.WriteLine(_rdfDocument.ToRdfXml());

现在,Node 1 知道 Mr Guid,Mr Guid 也知道 Node 1,这是一个完全合法的场景。谁是根元素,谁是子元素?
XML 序列化程序可能会选择行中的第一个作为“根”,另一个作为“子元素”,但它是任意的。嵌套只是 XML 序列化产生的幻象。不要上当。

您使用 rdfDocument.GetIndividuals(Person.Uri, true); 语句触发的查询只是过滤掉 Person 类型的所有个体,因此它会正确返回所有三个家伙。

I believe there is some misunderstanding here concerning RDF and XML. RDF is a bunch of triples that can be expressed both in XML and in other serialization formats. Unlike XML, RDF is not hierarchical, therefore there is no such a thing as "subelement" in RDF. The fact that Mr. Guid is just is under Mr Node_1 is an illusion "suggested" by the misleading XML node hierarchy. To demonstrate that, I list the triples of your examples (please, mind that the order of triples in RDF is irrelevant!):

"Node 1" typeOf Person
"Node 1" depiction "Default.png"
"Node 1" description "Description"
"Node 1" knows "Mr. Guid"
"Mr. Guid" typeOf Person
"Node 2" typeOf Person
"Node 2" depiction "Default.png"
"Node 2" description "Description"

Try the following:
Add one more triple:
"Mr. Guid" knows "Node 1" with the following code:

Person mrGuid = _rdfDocument.GetIndividual("6779ac10-210b-40d2-8111-711db6988bb9") as Person;
Person mrNode1 = _rdfDocument.GetIndividual("Node 1") as Person;
mrGuid.knows = mrNode1;
Console.WriteLine(_rdfDocument.ToRdfXml());

Now, both Node 1 knows Mr Guid and Mr Guid knows Node 1, and this is a perfectly legal scenario. Who would be the root and who would be the subelement?
The XML serializer will probably pick the first one in row to be the "root" and the other as the "subelement", but it is arbitrary. The nesting is just an illusion created by the XML serialization. Do not fall for that.

The query you fire with the rdfDocument.GetIndividuals(Person.Uri, true); statement simply filters out all individuals that is of type Person, and hence it returns correctly all the three guys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文