2

I am trying to understand RDF/XML basics. I have a problem understading data referencing.

For a simple example, let's consider the relationship between Person and Document.

In a relational data model, this would be a simple one to many relationship (Person can have many documents, but a Document can only belong to one Person). So this could be solved by having person_id in the documents table.

But how do I achieve something like this in RDF/XML?

I define my <namespace:Person rdf:about="http://www.foo.com"> with all the attributes and I also have <namespace:Document rdf:about="http://www.bar.com">, but what is the correct way of saying that a document belongs to a person whose id = x?

unor
  • 92,415
  • 26
  • 211
  • 360
Coderr19
  • 23
  • 4
  • 1
    Not immediately an answer, but can I recommend that you don't try to understand how RDF works by trying to read/write RDF/XML? RDF/XML is one possible syntax form for RDF, and it's _very_ hard to read. Instead, [read up on how the RDF model works](https://www.w3.org/TR/rdf11-primer/). – Jeen Broekstra Apr 08 '18 at 00:05
  • @JeenBroekstra Thank you for the suggestion, but I am actually tasked to provide a solution to a problem. I am expected to come up with RDF/XML file and RDF Schema. – Coderr19 Apr 08 '18 at 00:14
  • up to you of course, but it's still easier to learn the abstract model first, and perhaps use a different syntax (e.g. Turtle) that is easier to understand. There are many many free/open-source tools available that can convert your RDF to RDF/XML syntax format once you're done modeling. – Jeen Broekstra Apr 08 '18 at 00:25
  • Maybe you'll find this answer on "[What's a rdf triple?](https://stackoverflow.com/a/49066324/1485527)" helpful. It tries to explain the concept of "rdf triple" at the example of a simple relation/table. – jschnasse Apr 09 '18 at 15:07

1 Answers1

4

RDF is a model that uses triples (a.k.a. RDF statements) to express data. Each statement has a subject, a predicate, and an object. Typically, the predicate expresses the relationship between the subject and the object. A collection of such statements can be thought of as a graph (with the subjects and objects as vertices, and the predicates as edges).

So in your example of Documents and Persons, let's first of all establish what relationship Documents and Persons have. For the sake of example, let's assume that you wish to express that a Document has an author, who is a Person.

If we apply this to a specific Document ex:d1, and a specific person ex:p1, we would simply write the following triples to express the relation:

ex:d1 a ex:Document;
      ex:hasAuthor ex:p1 .
ex:p1 a ex:Person .

The above is Turtle syntax by the way, an easier to read/write syntax for RDF. See the RDF Primer for details.

In RDF/XML syntax, the same data would look something like this:

<ex:Document rdf:about="http://example.org/d1">
   <ex:hasAuthor rdf:resource="http://example.org/p1"/>
</ex:Document>
<ex:Person rdf:about="http://example.org/p1"/>

But, like I mentioned in my comment: it's more effective to try and understand RDF modeling in the abstract (thinking about triples and graphs), than by trying to understand how to write RDF/XML.

Back to the example: the above shows how you model a relationship between a specific document and a specific person. If you wish to express the more general information that "documents and persons are classes that can be related through an author-relation", you can use the RDF Schema vocabulary. You would express this as follows:

ex:Document a rdfs:Class .
ex:Person a rdfs:Class .
ex:hasAuthor a rdf:Property ;
             rdfs:domain ex:Document ;
             rdfs:range ex:Person .

Note that an RDF Schema not the same thing as relational schema! A relational schema's purpose is to prescribe structure and allow data validation. An RDF vocabulary (or ontology) is used to describe the world. All the above says is that documents and persons exist in our world, and if two things have an 'author'-relation between them, those two things are documents and persons.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • This is a great explanation! Thank you! :) – Coderr19 Apr 08 '18 at 00:35
  • @Coderr19 I'm wondering why you didn't read this in the RDF primer then? That's the main entry point, reading the W3C recommendations and from my point of view most things therein are explained sufficiently even with examples. Anyways, +1 for Jeen – UninformedUser Apr 08 '18 at 08:06
  • @AKSW I don't know whether OP read the primer or not, but it can often help to have the same thing explained to you in different words (at least it often helps me). So no wasted effort IMHO. – Jeen Broekstra Apr 08 '18 at 10:55