We've had a couple of years of deafening noise surrounding the famous "Web 2.0". What with shoving AJAX everywhere (who hasn't suffered doing raw XMLHttpRequest calls while dealing with the differences between our beloved Firefox and the dreaded Internet Explorer?), how blogs have democratized publishing, and how user-generated content is the future. Meanwhile, the W3C folks and Tim Berners-Lee keep hammering us with what comes next: the Semantic Web. Some visionaries are already calling it straight up Web 3.0.
Last night I sat down to read the W3C specifications to understand what all this hype is really about. The premise sounds like something out of a sci-fi movie: making machines not just parse HTML to paint it with colors in a browser for a human to read, but actually understand the real meaning of the data and its relationships.
Let me break it down for you: instead of having isolated web pages with hyperlinks, the idea is to turn the entire internet into one massive, global, distributed database.
The foundation of the graph: RDF and the URI madness
The main standard around which all of this pivots is RDF (Resource Description Framework). Forget for a moment about your tables, your rows, and your columns. In RDF, everything is based on a graph structure made up of triples: Subject, Predicate, and Object.
The technical key here is that both the subject and the predicate must be globally unique URIs (Uniform Resource Identifiers). That way, we avoid ambiguity. You don't just say "name", you say "the concept of name according to vocabulary X".
Obviously, since we are right in the middle of 2006 and the XML fever is dominating everything in the industry, RDF is usually serialized into fairly verbose XML files. To give you an idea, if we want to use the well-known FOAF (Friend of a Friend) vocabulary to describe a developer, the code looks somewhat like this:
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:about="http://midominio.com/yo">
<foaf:name>srdata</foaf:name>
<foaf:mbox rdf:resource="mailto:contacto@midominio.com"/>
</foaf:Person>
</rdf:RDF>
OWL: Throwing logic into the blender
The problem with RDF is that it falls short when defining complex rules. If you want the machine to understand that "A programmer is a subclass of Person", that "Two identical emails mean it's the same physical person", or that the "Person" class is disjoint from the "Car" class, OWL (Web Ontology Language) comes into play.
OWL adds a layer of descriptive logic and constraints (the famous ontologies) on top of your RDF. This allows for inference engines (specialized software) that can deduce new data that wasn't explicitly written in the XML. It's pure set theory and first-order logic applied to internet architecture.
Querying this chaos with SPARQL
Of course, if we are going to have the web filled with massive interconnected RDF graphs, we need something to extract meaningful data. If relational databases have SQL, the Semantic Web has SPARQL. The W3C has just published it as a Candidate Recommendation, and technically, it looks very interesting.
Unlike traditional SQL where we do JOINs between tables based on primary keys, SPARQL works by pattern matching. We look for subgraphs that fit the shape we ask for.
Imagine we have a repository of decentralized social data and we want to extract the names and emails of all registered users. The query would be as clean as this:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?nombre ?email
WHERE {
?persona rdf:type foaf:Person .
?persona foaf:name ?nombre .
?persona foaf:mbox ?email .
}
It's elegant, let's not kid ourselves. The question marks (?) mark the variables we want to bind. The SPARQL engine will look for any subject (?persona) that meets those three conditions simultaneously in the graph and will return a tabular set of results. If you want to mess around with this today, you can spin up a test server by installing libraries like Jena in Java or ARC for PHP (taking advantage of the fact that PHP 5 handles OOP decently now).
Are we really heading towards Web 3.0?
Here comes my serving of raw reality. The theory is spectacular and academically flawless. Building autonomous software agents that travel the web crossing data without human intervention sounds like the absolute panacea of technical automation.
But being practical, pragmatic, and knowing the sector... are we really going to convince millions of web developers to tag every piece of information with super-strict ontological vocabularies in a mile-long XML? Currently, half of the webmasters don't even properly close their <li> or <p> tags in their HTML, let alone run their pages through the W3C validator. It's incredibly hard for me to believe that overnight we're going to embrace such a strict, semantic, and academic technology on a global scale.
For now, I'll keep a close eye on SPARQL because I see massive potential for closed enterprise data integration projects, where you can actually enforce a schema. But for the day-to-day of the average web developer, I'm convinced that "Web 2.0", AJAX, and MySQL databases are going to put food on our tables for quite a few more years before we see this famous Web 3.0 running natively in our browsers.