Domanda

ecco il mio documento RDF che è generato dalla libreria 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>

E io sto cercando di recuperare le persone Nodo 1 e il Nodo 2 con questo codice:

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;

torna purtroppo person_list con i seguenti dati:

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

Quindi, c'è un modo / Methode per ottenere solo il nodo 1 e 2 senza i loro elementi secondari nella lista? (Di corsi degli individui di ID sono generati in modo dinamico, quindi non posso cercare uno specifico ID)

Grazie.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top