Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top