I know this sounds extremely newbieish, but even after going through some of the tutorials on W3 schools on RDF and reading the primer, I cannot seem to fathom how a simple subject-predicate-object rdf relationship is expressed in XML.
Let's say I have a concept like this:
I have a car. My car has a gps receiver. The car's current gps coordinates are X latitude, Y longitude.
Do I represent this as
<RDF>
<Owner Name="me">
<has>car</has>
<car>
<has>gpsreceiver</has>
<has><cordinates X="somevalue", Y="somevalue"></has>
</car>
</Owner>
</RDF>
Is this how it's written? What I have trouble understanding is how subjects, objects and predicates map into elements and attributes.
once I've sorted this out, ultimately I'd like "car" to be its own schema, so I can just refer to its namespace and just say things like "I own car model ABC licence plate DEF that is now at 12.34 coordinates".
Please, please shed some light? At my wits' end and no one around me seems to know rdf or ontologies to enlighten me :-(
I agree with the other responders that you should not worry about the XML syntax, but I would also not suggest thinking about the triples immediately either. First start with thinking clearly about the things you're trying to model, then the triples will be more obvious.
So, you have a thing, your car, which is a kind of car. Being any kind of car in general, and being your car in particular, are two different notions. So you'll need two separate names - RDF calls them resources - to represent the class of all cars and the instance of your car. Likewise, there are things that are GPS's in general, and the GPS in your car in particular. Assuming a suitable namespace, then:
:car127 rdf:type :Car .
:gps99 rdf:type :GPS.
That's a triple expressing that a given car (subject car127
) is a member of (predicate rdf:type
) the class of all cars (object Car
), and similarly one for the GPS.
Your car is owned by Nina, who is a person. So that's two more relationships, one saying that Nina is a person, and one that Nina owns that specific car (by re-using the same resource identifying the car):
:nina rdf:type foaf:Person.
:nina foaf:name "Nina".
:car127 :ownedBy :nina.
(OK, I added an extra triple to relate the resource URI :nina
to the name Nina).
The specific GPS is a component of the specific car:
:car127 :containsComponent :gps99.
Now, we say informally that the GPS "has" a given lat and long position. Clearly these change over time (if not, get a new car :). You could model this by having the x and y predicates directly attached to the GPS resource, and repeatedly updating the values in the model. But if you think about your GPS giving a series of readings at particular times, it seems a bit clearer and more descriptive. Then we have:
:gps99 :reading [
rdf:type :Reading;
:lat 51.14276;
:long -2.71619;
:at "2011-09-02T123400"^^xsd:dateTime
].
The square brackets [...]
is a short-hand way of introducing a new resource whose properties - relationships - we can describe but whose identity we don't know or don't care about. Technically it's called an anonymous node or bNode, but that's not a detail to worry about now. It's enough to note that there's a relationship (':reading') from the GPS device to a resource of type :Reading
(note the capital R - that's a convention to distinguish resources that identify classes from other kinds of resource). This reading resource has four properties: a type, the observed lat and long, and the time of the reading. We could, if we wanted, add more readings for other points in time, which would build up to modelling a track ... but that's another discussion!
I would try not to ever think about what you need the XML to look like, the specification allows for multiple ways to serialize the same information so I would try and think about it in triples.
So for your example:
:Me :owns :MyCar .
:MyCar :hasPart :GpsReceiver .
:MyCar :hasXPosition "x" .
:MyCar :hasYPosition "y" .
This is a fairly basic way of expressing it and there are alternatives such as what Pierre has suggested.
Everything in RDF is represented as triples so try to think about how you'd represent your data in triples, then use the available libraries/tools to generate the serializations like RDF/XML for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With