Friday, 29 October 2010

SPARQL RDF Query Language and RDF Containers (i.e. rdf:Seq, rdf:Bag and rdf:Alt)

SQPARQL and RDF
SPARQL is the query language for RDF. Most of us learn SQL langauge for database first and then we learn about SPARQL and RDF. RDF is a datamodel which supports a simple structure of Subject, Predicate and Object.

After SPARQL basic is learned, then here comes the trouble of querying RDF containers. There are three kinds of containers in RDF, namely, Seq, Bag and Alt. So, how do we query the following RDF graph about bags. It would be something like this from looking at the RDF/XML.

PREFIX rdf .
PREFIX cd .
SELECT ?artist
WHERE 
{
 cd:Artist ?bag.
?bag rdf:li ?artists.
} 

It won't give us any results because the actual graph and the representation form are different. Lets see the RDFXML and RDF graph for some examples.

RDF Bag




John
      Paul
      George
      Ringo
    
  









RDF Sequence





  
    
      George
      John
      Paul
      Ringo 







RDF Alt (Alternate)




  
    
      CD
      Record
      Tape
    
  









From the above RDF graphs, we can see that tough these are annotated by <rdf:li>, in the real representation they are represented as rdf:_1, rdf#_2, rdf#_3, .... And the type of the container, i.e. semantic of the list is defined by using rdf:type property to the corresponging container type (bag, seq, alt). That's the reason the above SPARQL query doesn't work. Here is the query that works.

  PREFIX dc: <http://purl.org/dc/elements/1.1/> .
  PREFIX asn: <http://purl.org/ASN/schema/core/> .
  PREFIX gemq: <http://purl.org/gem/qualifiers/> .
  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
SELECT ?statement ?type
WHERE
{
  ?doc a asn:StandardDocument ;  gemq:hasChild ?seq.
  ?seq ?t ?statement.
  ?statement a ?type.

}

In the above query, a unbounded variable "?t" is used to get all the elements of the container.  I ran into this pitfall once and it took me an hour to figure that out. So, I decided to share this so that you won't ran into it and spend hours on that.


References: Sample RDF data from http://www.w3schools.com/rdf/rdf_containers.asp

Thursday, 14 October 2010

Think For Yourself

This of one of the best advice advice for our lives. Buddha is the first one who taught us to think by yourself rather than following faiths, beliefs, books, famous persons, and the list is endless. The enlightened teacher once said, "Do not believe what your teachers would say. Do not believe what your tradition says, Do not take anything because it comes to you with the authority of somebody else. make it a personal experience. Think for yourself. Be convinced. And once you are convinced, act accordingly."

In this age of information where social networks, blogs and wikis plays far more important role in communicating knowledge than traditional methods like books, newspaper, encyclopedia, etc. When knowledge is socially generated, it is chaos and difficult to control the correctness of the content, let alone quality. This is where we need to "Think for ourself again.". Every information from unreliable sources needs to be analysed and compare with other sources to make sure that it is correct.
May be now it's quite clear that we should not believe everything without proper reasoning. Now lets see whether people today are thinking for themselves or not.  From my experience, usually do not think by themselves. Think of how much hoax emails are forwarded to you by your friends every week. That just shows that people usually take stuff like hoax emails for granted. Some people are still sending "If you don't forward this you will die in 10 minutes" kind of emails. Some send their passwords in response to phishing emails. There are countless examples of these.

Internet is just a medium. It is just much faster and powerful. Does a better medium means we become smarter? I don't think so. We are still human being as we are in the stone age and the rules of reasoning and common sense still applies. Internet won't make us any smarter unless we think for ourself. So, don't take anything on the Internet for granted. Don't trust whatever Google returns you as a result :). It is often influenced by advertisement money and SEO techniques.

So, lets "think for ourself". It will make you smarter because information is now available anywhere, anytime. We just need to analyze them against our own knowledge and reasoning. If most people are thinking for themselves, the world will definitely be a much better place.

Note: This is just my very first blog post. Any suggestions are welcomed. If you wonder what makes me wrote this, it is because I am getting sick and tired of people telling me nonsense, useless and misleading stuff. If I asked them why, their answer is "I read it on X, or Y told me". Do I argue with them? No. I tried and it doesn't work even if I give them a logical reason. Why? Because most of them won't think logically :)