It occurred to me today that RDF documents are a lot like documents we call web pages. I realized that while I was looking at some jQuery examples, and it struck me that tag and attribute names used in XPath expressions are similar concepts as instance and property IDs and that creating and appending new nodes is essentially the same as creating new instances. So, if we apply some “if she weighs as much as a duck, she is a witch” logic to it, we can conclude that jQuery-like syntax should also work very well for querying and manipulating data stored as RDF.
Let’s have a look a what this might look like.
A simple select:
authors = $('author[@name = "Clay Shirky"]');
Setting a property value:
$('author[@name = "Clay Shirky"]').set('homepage', 'http://www.shirky.com');
Appending a new value to an object property:
$('author[@name = "Clay Shirky"]').append('books', $.create('book', {'title': 'Here comes everybody', 'year': 2008}));
Deleting an instance:
$('author[@name = "Clay Shirky"]').delete();
The code would then go and and update your triple store or something like that. I really like how it combines querying and data modification in a single syntax. Also, it’s quite a bit more compact than SPARQL and SPARUL statements.
All I have so far are these very simple cases, but it does look like I might be on to something. It might make an interesting weekend project.
UPDATE (20. jan): it turns out that a similar project already exists. It’s called rdfQuery.
Related posts:
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=603cfc57-f0d9-42d7-beb8-8fa81934b688)
