Showing posts with label sparql. Show all posts
Showing posts with label sparql. Show all posts

Saturday, December 5, 2015

SPARQL Guide for the Visual Basic 6 (VB6) Developer

Author:
Topics: , , , ,

SPARQL Guide for the Visual Basic 6 (VB6) Developer

Introduction

This is the Visual Basic 6 variation of 's SPARQL guides for PHP, Perl, Python, JavaScript developers and my guide forClassic ASP developers. I wanted to share this because quite a number of developers (including me) are still using Visual Basic 6 and It could also be used for Linked Data Application development. Visual Basic is on the top 20 most popular programming languages according to TIOBE Index as at december 2015

What?

A simple guide usable by any Visual Basic 6 developer seeking to exploit SPARQL without hassles.

Why?

SPARQL is a powerful query language, results serialization format, and an HTTP based data access protocol from the W3C. It provides a mechanism for accessing and integrating data across Deductive Database Systems (colloquially referred to as triple or quad stores in Semantic Web and Linked Data circles) -- database systems (or data spaces) that manage proposition oriented records in 3-tuple (triples) or 4-tuple (quads) form.

How?

SPARQL queries are actually HTTP payloads (typically). Thus, using a RESTful client-server interaction pattern, you can dispatch calls to a SPARQL compliant data server and receive a payload for local processing e.g. local object binding re. Visual Basic 6 (vb6).

Steps:
  • Determine which SPARQL endpoint you want to access e.g. DBpedia or a local Virtuoso instance (typically: http://localhost:8890/sparql).
  • If using Virtuoso, and you want to populate its quad store using SPARQL, assign "SPARQL_SPONGE" privileges to user "SPARQL" (this is basic control, more sophisticated WebID based ACLs are available for controlling SPARQL access).
  • Make sure MSXML parser is installed on the server or you can download from here.
  • Download VB-JSON: A Visual Basic 6 (VB6) JSON Parser Class Library.
  • In Visual Basic, create a new Standard EXE project. Create and add a new module, "module1.bas".
  • Add a project reference to Microsoft XML version 2.0, Microsoft scripting runtime, Microsoft ActiveX Data Objects library.
  • Unzip the VB-JSON file. Extract the following files: "json.bas", "cJSONScript.cls" and "cStringBuilder.cls". Add them to the Visual Basic project
  • Paste the following code in "module1.bas" file. See the inline comments for a description of how the code functions.
  • Save and run the Visual Basic project.
Code:
 Private m_SafeChar(0 To 255) As Boolean
 Sub main()
  Dim buf As New cStringBuilder

    Dim p As Object
  
  Dim result As String
  Dim url As New cStringBuilder
  Dim dsn As String
  Dim parameters As String
  Dim sparql As New cStringBuilder
  
  On Error Resume Next
  
  ' Setting Data Source Name (DSN)
  dsn = "http://dbpedia.org/sparql"
  
  ' HTTP URL is constructed accordingly with JSON query results format in mind.
  parameters = "default-graph-uri=&should-sponge=&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on"

  
  ' SPARQL Query
  ' List all the landlocked countries in Africa
  sparql.Append "PREFIX rdfs:  "
  sparql.Append "PREFIX type:  "
  sparql.Append "PREFIX prop:  "
  sparql.Append "SELECT ?country_name ?population ?ind1 "
  sparql.Append "WHERE { "
  sparql.Append "    ?country a type:LandlockedCountries, yago:AfricanCountries ; "
  sparql.Append "             rdfs:label ?country_name ; "
  sparql.Append "             prop:populationEstimate ?population . "
  sparql.Append "             FILTER (?population > 15000000) . "
  sparql.Append "             filter (lang(?country_name) = 'en'). "
  sparql.Append "             bind( str(?country_name) as ?ind1 ). "
  sparql.Append "} "
  
  ' construct the SPARQL URL
  url.Append dsn
  url.Append "?"
  url.Append "query="
  url.Append URLEncode(sparql.toString)
  url.Append "&"
  url.Append parameters
  
  ' Send SPARQL URL as REST
  result = WebRequest(url.toString)
  
  DoEvents: DoEvents
  
  ' Parse SPARQL JSON results
  Set p = JSON.parse(result)
  DoEvents: DoEvents
  
  If Not (p Is Nothing) Then
   
     If JSON.GetParserErrors <> "" Then
     ' Errors 
     MsgBox JSON.GetParserErrors, vbInformation, "Parsing Error(s) occured"
     Else
     ' No Errors
     Dim cnt As Integer
     Dim maxrecs As Integer
     Dim sparqldata As String
     
     maxrecs = IIf(CInt(p.Item("results").Item("bindings").Count) > 4, 5, CInt(p.Item("results").Item("bindings").Count))
     cnt = 1
     buf.Append "Retrieved Data:" & vbNewLine
     buf.Append "" & vbNewLine
     Do While True
    buf.Append p.Item("results").Item("bindings").Item(cnt).Item("country_name").Item("value") & vbNewLine
    If cnt = maxrecs Then Exit Do
    cnt = cnt + 1
    
    DoEvents
     Loop
     
     End If
  Else
     MsgBox "An error occurred parsing file "
     
  End If

 MsgBox buf.toString
 End Sub

 Public Function WebRequest(url As String) As String
  Dim http As MSXML2.XMLHTTP
  Set http = CreateObject("MSXML2.ServerXMLHTTP")

  http.Open "GET", url, False
  http.send

  WebRequest = http.responseText
  Set http = Nothing
 End Function

 ' Return a URL safe encoding of txt.
 Private Function URLEncode(ByVal txt As String) As String
 Dim i As Integer
 Dim ch As String
 Dim ch_asc As Integer
 Dim result As String

  SetSafeChars

  result = ""
  For i = 1 To Len(txt)
   ' Translate the next character.
   ch = Mid$(txt, i, 1)
   ch_asc = Asc(ch)
   If ch_asc = vbKeySpace Then
    ' Use a plus.
    result = result & "+"
   ElseIf m_SafeChar(ch_asc) Then
    ' Use the character.
    result = result & ch
   Else
    ' Convert the character to hex.
    result = result & "%" & Right$("0" & _
     Hex$(ch_asc), 2)
   End If
  Next i

  URLEncode = result
 End Function

 ' Set m_SafeChar(i) = True for characters that
 ' do not need protection.
 Private Sub SetSafeChars()
 Static done_before As Boolean
 Dim i As Integer

  If done_before Then Exit Sub
  done_before = True

  For i = 0 To 47
   m_SafeChar(i) = False
  Next i
  For i = 48 To 57
   m_SafeChar(i) = True
  Next i
  For i = 58 To 64
   m_SafeChar(i) = False
  Next i
  For i = 65 To 90
   m_SafeChar(i) = True
  Next i
  For i = 91 To 96
   m_SafeChar(i) = False
  Next i
  For i = 97 To 122
   m_SafeChar(i) = True
  Next i
  For i = 123 To 255
   m_SafeChar(i) = False
  Next i
 End Sub

  
Output:
  Retrieved Data 

  Burkina Faso
  Ethiopia
  Malawi
  
Conclusion:

JSON was chosen over XML (re. output format) since this is about a "no-brainer installation and utilization" guide for a Javascript developer that already knows how to use Javascript for HTTP based data access within HTML. SPARQL just provides an added bonus to URL dexterity (delivered via URI abstraction) with regards to constructing Data Source Names or Addresses.

Thursday, December 3, 2015

SPARQL Guide for the Classic ASP Developer

Author:
Topics: , , , ,

SPARQL Guide for the Classic ASP Developer

Introduction

This is the Classic ASP variation of 's SPARQL guides for PHP, Perl, Python, JavaScript developers. I wanted to share this because quite a number of developers (including me) are still using Classic ASP and It could also be used for Linked Data Application development.

What?

A simple guide usable by any Classic ASP developer seeking to exploit SPARQL without hassles.

Why?

SPARQL is a powerful query language, results serialization format, and an HTTP based data access protocol from the W3C. It provides a mechanism for accessing and integrating data across Deductive Database Systems (colloquially referred to as triple or quad stores in Semantic Web and Linked Data circles) -- database systems (or data spaces) that manage proposition oriented records in 3-tuple (triples) or 4-tuple (quads) form.

How?

SPARQL queries are actually HTTP payloads (typically). Thus, using a RESTful client-server interaction pattern, you can dispatch calls to a SPARQL compliant data server and receive a payload for local processing e.g. local object binding re. ASP.

Steps:
  • Determine which SPARQL endpoint you want to access e.g. DBpedia or a local Virtuoso instance (typically: http://localhost:8890/sparql).
  • If using Virtuoso, and you want to populate its quad store using SPARQL, assign "SPARQL_SPONGE" privileges to user "SPARQL" (this is basic control, more sophisticated WebID based ACLs are available for controlling SPARQL access).
  • Make sure MSXML parser is installed on the server or you can download from here.
  • Download AXE (ASP Xtreme Evolution) JSON parser json2.asp.
  • Create a new ASP page, and paste the following code in the page and save the file to the Web server.
Script:
   <!--#include file="json2.asp"-->
   <%

   dim mysrc
   dim inputsource
   dim parameters
   dim dsn

   ' Setting Data Source Name (DSN)
   dsn="http://dbpedia.org/sparql"

   ' HTTP URL is constructed accordingly with JSON query results format in mind.
   parameters="default-graph-uri=&should-sponge=&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on"

   ' SPARQL Query
   ' List all the landlocked countries in Africa
   mysrc="PREFIX rdfs:  "
   mysrc = mysrc & "PREFIX type:  "
   mysrc = mysrc & "PREFIX prop:  "
   mysrc = mysrc & "SELECT ?country_name ?population ?ind1 "
   mysrc = mysrc & "WHERE { "
   mysrc = mysrc & "    ?country a type:LandlockedCountries, yago:AfricanCountries ; "
   mysrc = mysrc & "             rdfs:label ?country_name ; "
   mysrc = mysrc & "             prop:populationEstimate ?population . "
   mysrc = mysrc & "             FILTER (?population > 15000000) . "
   mysrc = mysrc & "             filter (lang(?country_name) = 'en'). "
   mysrc = mysrc & "             bind( str(?country_name) as ?ind1 ). "
   mysrc = mysrc & "} "
   mysrc = dsn & "?" & "query=" & server.urlencode(mysrc) & "&" & parameters



   Set xmlHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
   xmlHTTP.open "GET", mysrc, False
   xmlHTTP.setRequestHeader "Content-Type", "text/json"
   xmlHTTP.setRequestHeader "CharSet", "UTF-8"
   xmlHTTP.Send
   inputsource = xmlHTTP.responseText
   set xmlHTTP = Nothing


   set test = JSON.parse(inputsource)

   Response.write "Retrieved Data 

" dim key : for each key in test.results.bindings.keys() Response.write( test.results.bindings.get(key).country_name.value & "
") next Set test = Nothing %>
Output:
  Retrieved Data 

  Burkina Faso
  Ethiopia
  Malawi
  
Conclusion:

JSON was chosen over XML (re. output format) since this is about a "no-brainer installation and utilization" guide for a Javascript developer that already knows how to use Javascript for HTTP based data access within HTML. SPARQL just provides an added bonus to URL dexterity (delivered via URI abstraction) with regards to constructing Data Source Names or Addresses.

Monday, March 24, 2014

Big Data at the Nigerian Movies

Using Big Data and Natural Language Processing techniques to query the Global Graph for Nigerian Movies and Actors.

Using Virtuoso SPARQL editor, I sent the following queries to the LinkedMDB SPARQL Endpoint using Federated SPARQL.

Nigerian Movies on LinkedMDB

The following query lists all the Nigerian movies in the RDF store of LinkedMDB or in SPARQL terms, "show me movies whose 'movie:country' is 'country:NG' which may have a 'dc:title' or a 'dc:date'" :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>

 select ?s ?Title ?Date

 where {
 SERVICE <http://data.linkedmdb.org/sparql> {
 ?s movie:country   country:NG .
 optional { ?s dc:title ?Title. }
 optional { ?s dc:date ?Date. }
  }

 } 
 
[View query in Virtuoso SPARQL Editor]

The answer looks like this.

 ---------------------------------------------------------------------------------------------------
 | S                                               | Title                          | Date         |
 ===================================================================================================
 | <http://data.linkedmdb.org/resource/film/10659> | "Rise and Fall of Idi Amin"    | "1980"       |
 | <http://data.linkedmdb.org/resource/film/16051> | "Osuofia in London"            |              |
 | <http://data.linkedmdb.org/resource/film/16118> | "Ezra"                         | "2007-01-23" |
 | <http://data.linkedmdb.org/resource/film/16130> | "Aki na Ukwa"                  |              |
 | <http://data.linkedmdb.org/resource/film/16131> | "2 Rats"                       | "2003"       |
 | <http://data.linkedmdb.org/resource/film/16463> | "Above Death: In God We Trust" | "2003"       |
 | <http://data.linkedmdb.org/resource/film/17663> | "Abuja Connection"             |              |
 | <http://data.linkedmdb.org/resource/film/24122> | "Missing Angel"                |              |
 ---------------------------------------------------------------------------------------------------

 
[Run the query using URIburner Endpoint].

Wow! they have only 8 Nigerian movies in their dataset.

Who acted in the movie "2 Rats"

Let us find out who acted in the movie "2 Rats" by using the following query. In SPARQL terms "show me the 'movie:actor' of '.../film/16131' and also tell me his '?Name'" :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>

 select ?Name

 where {
 SERVICE <http://data.linkedmdb.org/sparql> {
 <http://data.linkedmdb.org/resource/film/16131>  movie:actor ?actor .
 ?actor movie:actor_name ?Name .

  }

 } 
 
[View query in Virtuoso SPARQL Editor].

The answer .

 --------
 | Name |
 ========
 --------
 
[Run the query using URIburner Endpoint].

Wow! LinkedMDB does not have that information. Let me see what else they have on the movie using the following query or in SPARQL terms "show me all you have on the subject of '.../film/16131'" :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>
 PREFIX dbowl: <http://dbpedia.org/ontology/>

 select *

 where {
 SERVICE <http://data.linkedmdb.org/sparql> {
 <http://data.linkedmdb.org/resource/film/16131> ?PropertyName ?Value
  

  }

 } 


 
[View query in Virtuoso SPARQL Editor]

The answer.

 ----------------------------------------------------------------------------------------------------------------------------
 | property                                          | object                                                               |
 ============================================================================================================================
 | <http://xmlns.com/foaf/0.1/based_near>            | <http://sws.geonames.org/2328926/>                                   |
 | <http://xmlns.com/foaf/0.1/page>                  | <http://www.freebase.com/view/guid/9202a8c04000641f8000000005674af3> |
 | movie:initial_release_date                        | "2003"                                                               |
 | dc:date                                           | "2003"                                                               |
 | movie:country                                     | country:NG                                                           |
 | movie:language                                    | <http://www.lingvoj.org/lingvo/en>                                   |
 | movie:filmid                                      | "16131"^^<http://www.w3.org/2001/XMLSchema#int>                      |
 | dc:title                                          | "2 Rats"                                                             |
 | rdfs:label                                        | "2 Rats"                                                             |
 | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | movie:film                                                           |
 ----------------------------------------------------------------------------------------------------------------------------

 
[Run the query using URIburner Endpoint]

This just shows the release date, country, lanaguage, title of the movie. This is not much. Let us check from the very nucleus of the Linked Open Data web, DBpedia (http://dbpedia.org), if they have some more data than LinkedMDB.

"2 Rats" at DBpedia

Let us see if we can catch "2 Rats" in DBpedia by using the following query or in SPARQL terms "show us the ?moviename and ?actor of any dbpedia:Film that has '2 Rats' in its name and dbprop:country is 'nigeria' " :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>

 select ?s as ?Movie ?moviename as ?Name ?actor as ?Actor

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbprop:country ?country.

 ?s dbpedia:starring ?dbname .
 ?s rdfs:label ?moviename.
 ?dbname dbprop:name ?actor.
 filter regex(?moviename,"^2 Rats") .
 filter regex(?country,"^nigeria","i") .


  }

 } 
 
[View query in Virtuoso SPARQL Editor]

The answer .

 -------------------------------------------------------------------------------
 | s                                    | moviename   | actor                  |
 ===============================================================================
 | <http://dbpedia.org/resource/2_Rats> | "2 Rats"@en | "Osita Iheme"@en       |
 | <http://dbpedia.org/resource/2_Rats> | "2 Rats"@en | "Iheme, Osita"@en      |
 | <http://dbpedia.org/resource/2_Rats> | "2 Rats"@en | "Chinedu Ikedieze"@en  |
 | <http://dbpedia.org/resource/2_Rats> | "2 Rats"@en | "Ikedieze, Chinedu"@en |
 -------------------------------------------------------------------------------
 
[Run the query using URIburner Endpoint]

Now we can see that DBpedia has the actors name.

What else do they have on the movie

Let us check for the movie description, director, distributor with the following query. In SPARQL terms "show me the ?director and ?distributor of any dbpedia:Film that has '2 Rats' in its name and dbprop:country is 'nigeria'" :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>

 select distinct ?s as ?Movie ?director ?distributor

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbprop:country ?country.

 ?s dbpedia:starring ?dbname .
 ?s rdfs:label ?moviename.
 ?s rdfs:comment ?description .
 ?s dbprop:director ?director.
 ?s dbprop:distributor ?distributor.
 ?dbname dbprop:name ?actor.
 filter regex(?moviename,"^2 Rats") .
 filter regex(?country,"^nigeria","i") .


  }

 } 
 
[View query in Virtuoso SPARQL Editor]

and the result shows

 -----------------------------------------------------------------------------------------------
 | s                                    | director         | distributor                       |
 ===============================================================================================
 | <http://dbpedia.org/resource/2_Rats> | "Andy Chukwu"@en | "OJ Productions International"@en |
 -----------------------------------------------------------------------------------------------
 
[Run the query using URIburner Endpoint]

so we can now see that DBpedia has much more information on this movie. We can get more information like the movie description with the following query.

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>

 select distinct ?description as ?Summary

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbprop:country ?country.

 ?s dbpedia:starring ?dbname .
 ?s rdfs:label ?moviename.
 ?s rdfs:comment ?description .
 ?s dbprop:director ?director.
 ?s dbprop:distributor ?distributor.
 ?dbname dbprop:name ?actor.
 filter regex(?moviename,"^2 Rats") .
 filter regex(?country,"^nigeria","i") .


  }

 } 
 
[View query in Virtuoso SPARQL Editor]

and it showed....


 | "2 Rats is a 2003 Nigeria film. Nollywood's highest paid actors, Osita Iheme (A-boy) and Chinedu Ikedieze (Bobo) are two young boys whose father has been murdered by their uncle. In a selfish move, Amaechi Muonagor wants them to work as house boys in their father's own house. A-boy and Bobo have other plans. The film features performances by Aki na Pawpaw and can be dubbed as Nollywood's Home Alone."@en |
 
[Run the query using URIburner Endpoint]

Chinedu Ikedieze's filmography

Which other movie did Chinedu Ikedieze star in? Let us ask DBpedia the following query or in SPARQL terms "Show us any 'dbpedia:Film' 'dbpedia:starring' 'dbr:Chinedu_Ikedieze', giving us the '?director' and '?distributor' if available " :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>
 PREFIX dbr: <http://dbpedia.org/resource/>

 select distinct ?s as ?Movie ?director ?distributor

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbpedia:starring dbr:Chinedu_Ikedieze .
 optional {?s dbprop:director ?director. }
 optional {?s dbprop:distributor ?distributor. }

  }

 } 

 
[View query in Virtuoso SPARQL Editor]

and the result showed ...

 ---------------------------------------------------------------------------------------
 | s                  | director                   | distributor                       |
 =======================================================================================
 | dbr:2_Rats         | "Andy Chukwu"@en           | "OJ Productions International"@en |
 | dbr:Aki_na_Ukwa    | "Amayo Uzo Philips"@en     | "Kas-Vid International"@en        |
 | dbr:Games_Men_Play | dbr:Lancelot_Oduwa_Imasuen |                                   |
 ---------------------------------------------------------------------------------------
 
[Run the query using URIburner Endpoint]

Hmm! only 3 films.

Chinedu Ikedieze and Osita Iheme

Which films in DBpedia have starred both Chinedu and Osita together? Let us ask with the following query :

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>
 PREFIX dbr: <http://dbpedia.org/resource/>

 select distinct ?s as ?Movie ?director ?distributor

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbpedia:starring dbr:Chinedu_Ikedieze .
 ?s dbpedia:starring dbr:Osita_Iheme .
 optional {?s dbprop:director ?director. }
 optional {?s dbprop:distributor ?distributor. }

  }

 } 
 
[View query in Virtuoso SPARQL Editor]

The answer.

 --------------------------------------------------------------------------------
 | s               | director               | distributor                       |
 ================================================================================
 | dbr:2_Rats      | "Andy Chukwu"@en       | "OJ Productions International"@en |
 | dbr:Aki_na_Ukwa | "Amayo Uzo Philips"@en | "Kas-Vid International"@en        |
 --------------------------------------------------------------------------------
 
[Run the query using URIburner Endpoint]

Just only 2 movies.

Nollywood in DBpedia

Let us ask DBpedia which Nigerian movies does it have, using the following query or in SPARQL terms "show us all the dbpedia:Film you have that dbprop:country is 'nigeria' and give it to me in english language".

 ## SPARQL Query
 PREFIX owl: <http://www.w3.org/2002/07/owl#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
 PREFIX dc: <http://purl.org/dc/terms/>
 PREFIX country: <http://data.linkedmdb.org/resource/country/>
 PREFIX dbpedia: <http://dbpedia.org/ontology/>
 PREFIX dbprop: <http://dbpedia.org/property/>
 PREFIX dbr: <http://dbpedia.org/resource/>

 select distinct ?s as ?Movie ?moviename as ?Name ?country as ?Country

 where {
 SERVICE <http://dbpedia.org/sparql> {
 ?s a dbpedia:Film .
 ?s dbprop:country ?country.
 optional {?s rdfs:label ?moviename. }

 filter regex(?country,"^nigeria","i") .
 filter (lang(?moviename) ='en') .
  }

 } 

 
[View query in Virtuoso SPARQL Editor]

The answer.

 -----------------------------------------------------------------------------------------------------------------------
 | s                                                             | country      | moviename                            |
 =======================================================================================================================
 | <http://dbpedia.org/resource/Area_Boys_(film)>                | "Nigeria"@en | "Area Boys (film)"@en                |
 | dbr:Lilies_of_the_Ghetto                                      | "Nigeria"@en | "Lilies of the Ghetto"@en            |
 | dbr:Living_in_Bondage                                         | "Nigeria"@en | "Living in Bondage"@en               |
 | dbr:Mirror_Boy                                                | "Nigeria"@en | "Mirror Boy"@en                      |
 | dbr:Oni_Ise_Owo                                               | "Nigeria"@en | "Oni Ise Owo"@en                     |
 | <http://dbpedia.org/resource/Rag_Tag_(film)>                  | "Nigeria"@en | "Rag Tag (film)"@en                  |
 | dbr:Rising_Moon                                               | "Nigeria"@en | "Rising Moon"@en                     |
 | dbr:Tango_with_Me                                             | "Nigeria"@en | "Tango with Me"@en                   |
 | dbr:The_Mayors                                                | "Nigeria"@en | "The Mayors"@en                      |
 | dbr:2_Rats                                                    | "Nigeria"@en | "2 Rats"@en                          |
 | <http://dbpedia.org/resource/30_Days_(2006_film)>             | "Nigeria"@en | "30 Days (2006 film)"@en             |
 | dbr:Games_Men_Play                                            | "Nigeria"@en | "Games Men Play"@en                  |
 | dbr:The_Figurine                                              | "Nigeria"@en | "The Figurine"@en                    |
 | dbr:Jenifa                                                    | "Nigeria"@en | "Jenifa"@en                          |
 | <http://dbpedia.org/resource/Above_Death:_In_God_We_Trust>    | "Nigeria"@en | "Above Death: In God We Trust"@en    |
 | dbr:Abuja_Connection                                          | "Nigeria"@en | "Abuja Connection"@en                |
 | dbr:Aki_na_Ukwa                                               | "Nigeria"@en | "Aki na Ukwa"@en                     |
 | <http://dbpedia.org/resource/Anchor_Baby_(film)>              | "Nigeria"@en | "Anchor Baby (film)"@en              |
 | <http://dbpedia.org/resource/Black_Gold_(2011_Nigerian_film)> | "Nigeria"@en | "Black Gold (2011 Nigerian film)"@en |
 | <http://dbpedia.org/resource/Ezra_(film)>                     | "Nigeria"@en | "Ezra (film)"@en                     |
 | dbr:Missing_Angel                                             | "Nigeria"@en | "Missing Angel"@en                   |
 | dbr:Osuofia_in_London                                         | "Nigeria"@en | "Osuofia in London"@en               |
 -----------------------------------------------------------------------------------------------------------------------
 
[Run the query using URIburner Endpoint]

Wow! just only 21 movies.

Conclusion

The web of linked data or Semantic Web is a global information space consisting of inter-linked data. SPARQL enables applications to query this global graph or database for information about resources or entities.
.
I have shown how easy to query these graphs for information on Nollywood. We have also seen that not enough information on Nollywood exist in the global graph so there is need to publish more.

Why? Applications can consume the results of these kind of queries to create a rich experience for users in interacting with these resources e.g. movie recommendation app, an actor app, etc.

  Emeka Okoye

Keywords: linkedopendatang, linkedopendata, opendatang, linkeddata, lod, nigeria, sparql, films, movies, nollywood

References

http://www.linkedmdb.org/ - LinkedMDB.

http://dbpedia.org - DBpedia.

http://en.wikipedia.org/wiki/SPARQL - About SPARQL.

http://www.w3.org/TR/rdf-sparql-query/ - SPARQL Query Language for RDF.

http://semanticweb.org/wiki/SPARQL_endpoint - SPARQL Endpoint.

http://www.w3.org/TR/sparql11-federated-query/ - Federated SPARQL.

http://linkeddata.uriburner.com/sparql/ - URIBurner SPARQL Endpoint.

http://virtuoso.openlinksw.com/ - Openlink Virtuoso.