RDF : Resource Description Framework

The basis of the Semantic Web

Jean-François Perrot

  1. Tools

  2. RDF
    1. Introduction, from the Jena Tutorial
    2. Tools
    3. More on RDF's XML Syntax, from the RDF Primer
    4. Extracting RDF contents from standard XML documents
    5. A special syntax for rdf:type

  3. SPARQL
    1. A query language for RDF.
    2. Execution
    3. SPARQL by example : SELECT
    4. SPARQL by example : CONSTRUCT

  4. RDFa & DBPedia
    1. RDFa : mixing XHTML & RDF
    2. Querying DBPedia
    3. Doing it with PHP

  1. Tools


  2. RDF


  3. SPARQL


  4. RDFa & DBPedia

    1. RDFa : mixing XHTML & RDF

    2. Querying DBPedia

      via its SPARQL endpoint : http://dbpedia.org/sparql

      [How to proceed]

      Asking for Mary Shelley's birthdate :

      select ?bd where {
        <http://dbpedia.org/resource/Mary_Shelley> <http://dbpedia.org/ontology/birthDate> ?bd
      }



      for her birthplace

      select ?bp where {
        <http://dbpedia.org/resource/Mary_Shelley> <http://dbpedia.org/ontology/birthPlace> ?bp
      }



      for the country where she was born

      PREFIX dbpedia: <http://dbpedia.org/resource/>
      PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
      select ?bc where {
        
      dbpedia:Mary_Shelley dbpedia-owl:birthPlace ?bp .
        
      ?bp dbpedia-owl:country ?bc
      }



    3. Doing it with PHP

      Composing a HTTP Get query from SPARQL

      function makeHTTPQuery($term){
          $format = 'xml';
          $query =
          "PREFIX dbp: <http://dbpedia.org/resource/> ont : <http://dbpedia.org/ontology/>
           SELECT ?bd
           WHERE {
               dbp:$Mary_Shelly ont:birthDate> ?bd
           }";
         
          $endpoint =
      'http://dbpedia.org/sparql';
         
      $searchUrl = $endpoint.'?'.'query='.urlencode($query).'&format='.$format;
          return $searchUrl;
      }//makeHTTPQuery



      Sending a HTTP Get query with cURL, response as an XML string :

      function sendQuery($searchUrl){
          // get curl handle
          $ch = curl_init();
          // set request url
          curl_setopt($ch, CURLOPT_URL, $searchUrl);
          // set option "return response", don't print/echo
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          // get the response
          $response = curl_exec($ch);
          curl_close($ch);
          return $response;
      }//sendQuery



      Extract info from XML string

      function extractDate ($xmlString){
          $splDoc = new SimpleXMLElement($xmlString);
          $splDoc->registerXPathNamespace('s', 'http://www.w3.org/2005/sparql-results#');
          $pathb = "/s:sparql/s:results/s:result/s:binding[@name='bd']/s:literal/text()";
          $bds = $splDoc->xpath($pathb); // array
          return $bds[0];
      }//extractDate



      Let us add a function to display the date in a format more civil than xsd:date : decoDate.php
      in order to make it clear that obtaining the date of birth is only one step in a process which may be quite elaborate.

      Complete script : birthDate.php