Visions of Aestia

10 Dec 2004

RDF/OWL == XML/XSLT, part 2

Filed under: Programming, PlanetRDF — JBowtie @ 3:13 pm

Sometimes, when I’m working with XML I need to change vocabularies. That’s why we invented XSLT, so that I can take XML in one flavor, modify it a bit, and get out some other flavor. Probably the most common transformation is {your favourite XML variant} to XHTML.

When we’re doing transforms, what we’re really doing is exploring the relationships between chunks of XML, mostly with XPath. So we discover that “relatives/uncle” in my example is the same as “relation[type=’uncle’]” in your example, and we write some transforms to convert back and forth.

XSLT lets me take the things you write in XML and turn it into XML that I understand. So instead of rewriting my program to recognize “foaf:name”, I can write an XSLT filter that turns it into “person/name”. I can do lots of other things with it, but that’s the core use case.




OWL lets me do the same thing on an RDF level. In other words, take some XML you understand and map it to some XML I understand.



So this is a description block that should be added to the XML that describes the name element in the FOAF schema. And instead of manually mapping it to an element that we understand, we are telling the OWL processor to do the mapping for us. It’s the same thing, but at a higher level.

With XSLT, we stop talking about the data contained in an XML document and start talking about the elements and attributes that make it up. Often we look at the data in an XPath to figure out what to do, but mostly we move it around between elements.

OWL also concentrates on the elements and attributes that make up a document. Instead of using XPaths to pick out nodes, we put nodes into categories.








is conceptually the same as:




It looks a little more complicated in OWL because everything needs an ID, even your elements and attributes. In a lot of cases you’d already have some sort of XML-based schema somewhere defining your terms.

But if we’re composing XML from blocks scattered around in multiple documents, OWL shines, because XSLT is miserable at it.
Imagine the following:


25


Pointing our transform at either of these documents is not going to produce results, because the color attribute is not actually defined on the wine element. OWL, however, builds on the distributed nature of RDF and can easily output the WhiteWine element.

I know I’ve left a lot out, but hopefully this will help someone else start grokking the Semantic Web.

RDF/OWL == XML/XSLT, part 1

Filed under: Programming, PlanetRDF — JBowtie @ 2:43 pm

Once upon a time, you used to have to explain XML to a group of IT people who had never heard of it. You’d give a little speech starting “XML is just like HTML except….”, followed by the five or six key points about XML. It was of course a drastic oversimplification and lots of details were glossed over, but everyone understood the basic concepts.

This is my attempt at a similar stab at getting everyone to understand RDF/OWL.

RDF and OWL are just like XML and XSLT. Let me illustrate.

A chunk of XML describing a person might look like this:


Clifford

123 Main St


If you wanted to link to this chunk of XML, you would use something like:






Notice how the ID is used to identify the chunk of XML you care about, and how a URL is used to refer to it from somewhere else. In this example, we might use some XSLT to create a web page with links to the XML describing my relatives. Most of us have seen stuff like this, this is how HTML links work.

RDF works exactly the same way. We identify some chunk of RDF with an ID, and use a URL to refer to it from somewhere else. We use rdf:resource in place of the href, and rdf:id so that RDF recognizes the id.






Cool. I can still turn this into a web page without thinking too hard. Any RDF-aware program can follow the links and get the XML describing my uncle Cliff.

I’m not just confined to linking to my uncle’s XML, though. I can add to it pretty easily by using a rdf:Description element.








Cliff
United States

As far as any RDF application is concerned, this is exactly the same as if I edited the original document to look like this:


Clifford

123 Main St

Cliff
United States

What the RDF parser is doing (conceptually) is following the link to get the original XML, then adding anything contained in the description block to get the final XML it ends up showing you. I could do this manually in XSLT by writing a transform, at least for simple cases.

There is only one other thing you need to know about RDF.

Most RDF browsers don’t actually care if a document you link to exists; they just won’t be able to show you much information. If example.org/family.xml is deleted, the browser will only show my uncle’s nickname and country. But that’s fine, it can still combine any other description blocks it finds that link to him. From an RDF perspective, the URL is just a unique identifier, like a database key.

The bit about adding description blocks together is really key. When I don’t have access or permission to modify an XML document, I can create a description block so that it appears (to an RDF browser) that I’ve made the changes anyway.

On to OWL in my next post.

Powered by WordPress