Archives

April 2004 (7)
March 2004 (12)
February 2004 (12)
January 2004 (22)
December 2003 (19)
November 2003 (16)
October 2003 (26)
September 2003 (18)
August 2003 (38)
July 2003 (80)
June 2003 (13)
May 2003 (24)
April 2003 (76)
March 2003 (75)
February 2003 (51)
January 2003 (73)

Category

Family (5)
FYI (18)
Games (2)
Geek (88)
Geographic (3)
Hacks (13)
Home (15)
Humor (54)
Ideas (20)
Ideaspace (15)
Local (15)
Metadata (10)
Microsoft (2)
MovableType (5)
Nitwits (66)
PKI (2)
Politics (22)
Quotes (3)
RDF (15)
RSS (4)
Security (3)
Semantic Web (13)
Site Info (13)
Social Networks (1)
Spam (9)
Sysadmin (1)
Tips (2)
Tivo (2)
TMFTOTHD (1)
To Do (1)
Unlisted (1)
Web (3)
Windows (1)

Local

« MetroBlogs »
DC metroblogs
beltway bloggers

Links


Assorted bits

Blogroll Me!
GeoURL
Listed on BlogShares




July 25, 2003

Some RDF examples

Dan Brickley posted about structuring data using RDF. He also posted a link to the RDF validator. This sparked an idea. One of the cool things about RDF is it's ability to use Directed Graphs. Now, I don't have a perfect pitch on explaining why that's such a cool thing. As they say, a picture's worth a thousand words. So here's some real exampes.

Take this snippet of RDF and paste it into the RDF validator. Note you'll probably want to make sure you pull down the "Graph Only" option.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:eg="http://example.org/foovocab#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/">
	<foaf:Person rdf:nodeID="p1">
	    <foaf:name>Alice</foaf:name>
	    <foaf:knows>
		<foaf:Person rdf:nodeID="p2">
		    <foaf:name>Bob</foaf:name>
		    <eg:secretlyStalking rdf:nodeID="p1"/>
		</foaf:Person>
	    </foaf:knows>
	    <eg:acquaintance rdf:nodeID="p2"/>
	    <eg:archNemesis rdf:nodeID="p2"/>
	</foaf:Person>
</rdf:RDF>

Now take this snippet, open a new window to the RDF validator and check it.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:eg="http://example.org/foovocab#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/">
	<foaf:Person rdf:nodeID="p1">
	    <foaf:name>Alice</foaf:name>
	    <foaf:knows rdf:nodeID="p2"/>
	    <eg:acquaintance rdf:nodeID="p2"/>
	    <eg:archNemesis rdf:nodeID="p2"/>
	</foaf:Person>
	<foaf:Person rdf:nodeID="p2">
	    <foaf:name>Bob</foaf:name>
	    <eg:secretlyStalking rdf:nodeID="p1"/>
	</foaf:Person>
</rdf:RDF>

Notice the pictures? They're THE SAME. How is this possible? The second one doesn't use the same ordering of the data as the first. And yet the graphs are exactly alike. This is important. Using RDF allows you to provide data that's got meaning independent of the restrictions imposed by the hierachical nature of XML.

It get's more interesting when you start to have a LOT of people with varying degrees of interconnectedness. Cut-and-paste this snippet into the validator:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:eg="http://example.org/foovocab#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/">
	<foaf:Person rdf:nodeID="alice">
	    <foaf:name>Alice</foaf:name>
	    <foaf:knows rdf:nodeID="bob"/>
	    <foaf:knows rdf:nodeID="ted"/>
	    <eg:acquaintance rdf:nodeID="bob"/>
	    <eg:acquaintance rdf:nodeID="ted"/>
	    <eg:archNemesis rdf:nodeID="bob"/>
	    <eg:archNemesis rdf:nodeID="ted"/>
	</foaf:Person>
	<foaf:Person rdf:nodeID="bob">
	    <foaf:knows rdf:nodeID="alice"/>
	    <foaf:knows rdf:nodeID="ted"/>
	    <foaf:name>Bob</foaf:name>
	    <eg:secretlyStalking rdf:nodeID="alice"/>
	    <eg:acquaintance rdf:nodeID="alice"/>
	    <eg:archNemesis rdf:nodeID="ted"/>
	</foaf:Person>
	<foaf:Person rdf:nodeID="carol">
	    <foaf:name>Carol</foaf:name>
	    <foaf:knows rdf:nodeID="alice"/>
	    <foaf:knows rdf:nodeID="ted"/>
	    <eg:secretlyStalking rdf:nodeID="bob"/>
	    <eg:acquaintance rdf:nodeID="alice"/>
	    <eg:acquaintance rdf:nodeID="ted"/>
	</foaf:Person>
	<foaf:Person rdf:nodeID="ted">
	    <foaf:name>Ted</foaf:name>
	    <eg:acquaintance rdf:nodeID="carol"/>
	    <eg:acquaintance rdf:nodeID="alice"/>
	    <eg:archNemesis rdf:nodeID="bob"/>
	</foaf:Person>
</rdf:RDF>

Here you have a graph showing very complex set of relationships. Yet the RDF/XML file is very compact and not verbose at all. The amazing thing about RDF is I could then query the triples for just the http://xmlns.com/foaf/0.1/knows URI and immediately extract who knows who. No DOM or SAX navigating needed at all.

So when you hear some developers carping about how the supposed verboseness of RDF, think about what it would take to fix the half-baked alternatives they're espousing. Especially when things start to get very interconnected. Using plain old XML would certainly be possible but why? There's already a growing body of tools that support using RDF.

There's more to the story folks, don't believe the crap the simpletons keep spouting. It's just not true.

RDF
Perma  | Comments (1) | TrackBack (1) | 04:38 PM  | xml
Comments

Here's a little ditty that shows how to process
the data above with
rdflib.

Run it like this:

$ python foafwk.py ,ex2.rdf
Carol is secretlyStalking Bob!

# cribbed from
#  http://rdflib.net/stable/example.py

from rdflib.TripleStore import TripleStore
from rdflib.constants import TYPE
from rdflib.Namespace import Namespace
from rdflib.Literal import Literal

FOAF = Namespace("http://xmlns.com/foaf/0.1/")
EX = Namespace("http://example.org/foovocab#")

def main():
s = TripleStore()
s.load(",ex2.rdf")

# find a guy named bob...
for who in s.subjects(FOAF["name"], Literal("Bob")):
bob = who

# who is secretlyStalking bob?
for who in s.subjects(EX["secretlyStalking"], bob):
for n in s.objects(who, FOAF["name"]):
print n, "is secretlyStalking Bob!"

if __name__ == '__main__':
main()


Posted by: Dan Connolly on July 25, 2003 05:58 PM
Post a comment






* if you do not leave a valid e-mail or URL your comment may be deleted *







Navigation

Recent Entries

America and Europe: Vive la différence?
Server changes afoot
Diet behavior mod
Googling for sensitive info
Outlook 2003 and IMAP, a marriage made in Hell
Bike to Work Day, May 7th
Speakeasy rocks
Zippo USB?
When geographic data is nowhere 'near' correct
Local campaign contributions

User comments
Trackbacks

Contact

send me an e-mail E-mail
chat with me using MS messenger MSN Messenger
chat with me via AIM America Online
chat with me on ICQ ICQ
chat with me on Yahoo! Yahoo
Add my vCard to your electronic addressbook vCard
Friend of a Friend FoaF

Syndication

XML  RDF  CDF

Comments

XFML

Extra Stuff

foaf
vCard
pgp info
Linked In
Powered by
Movable Type 2.64