Showing posts with label linkeddata. Show all posts
Showing posts with label linkeddata. Show all posts

Friday, December 26, 2014

How to Create an API Listing Nigerian States or Local Government Areas

How to Create an API for listing Nigerian States and Local Government Area using Linked Data from the Web of Data

.

Subjects: , , , ,

Situation Analysis:

Mfoniso Ossom (https://www.facebook.com/mfoniso?fref=nf) posed the question on Silicon Africa Facebook group (https://www.facebook.com/groups/siliconafrica/), "Is there a public API that provides a listing of Nigerian states, Cities, LGA e.t.c?". Investigation has shown there was none as the time of this post.

Challenge:

How do I create an API out of a document that comprised of data representing States or Local Government Areas of ? We know that Wikipedia documents hosts these data so we can use DBPedia data as well as any other additional data source on the web.

Solution:

  1. Use any server side programming language like PHP, Ruby, Python, Perl, ASP, etc to exploit SPARQL via REST based web service.
  2. Determine which SPARQL endpoint, a REST web service URI, you want to access e.g DBpedia (http://dbpedia.org/sparql) or a local virtuoso instance (typically http://localhost:8890/sparql). SPARQL endpoints provides a REST API to exploit RDF documents. The URL we'll send will start with the SPARQL endpoint and then pass it some query string parameters, "query" and "output".
  3. Construct the SPARQL query to list the data
    
      ## SPARQL Query
      
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      
      SELECT ?s1 as ?stateURI str(?s4) as ?stateName str(?s5) as ?stateDesc
      WHERE 
      {
      ?s1 a <http://dbpedia.org/ontology/Place> .
      ?s1 <http://dbpedia.org/property/type> ?s3 .
      ?s1 rdfs:label ?s4 .
      ?s1 rdfs:comment ?s5 .
      FILTER ( ?s3 in ( <http://dbpedia.org/resource/States_of_Nigeria> ) ) 
      FILTER langMatches( lang(?s4), "en" )
      FILTER langMatches( lang(?s5), "en" ) 
      
      
      
  4. URL Encode the SPARQL query and add it to the "query" parameter in the HTTP URL (e.g http://dbpedia.org/sparql?query=[encoded sparql here]).
  5. Add the query output format to the "output" parameter (e.g http://dbpedia.org/sparql?query=[encoded sparql here]&output=json).
  6. This URI is usable anywhere on the Web.
  7. Make the HTTP request to the URL and return the response body as a string.
  8. Using the right content header, you can write to standard output.

Download:

  • Source codes for the Local Government Areas API https://github.com/emekaokoye/NG-LGA-API - here.
  • Source codes for the States API https://github.com/emekaokoye/NG-States-API - here.

Live Demo:

  • Local Government Areas API http://linkedopendatang.com/entity/localgov/getlg.php?f=xml - here.
  • States API http://linkedopendatang.com/entity/state/getstate.php?f=json - here.
  • Note: Options for query parameter 'f' are json,csv,xml,ttl,rdf.

References

http://en.wikipedia.org/wiki/DBpedia -

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

http://www.w3.org/TR/rdf-sparql-query/ -

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

http://en.wikipedia.org/wiki/Server-side_scripting -

Keywords: linkedopendatang, open data, linked data, nigeria, sparql, states, local government areas, api

Tuesday, March 18, 2014

Edo State Food Centers Search App

Introduction
As we are have converted some of Edo State Open Data datasets to Linked Data, you are probably thinking what applications we can develop from the data. We decided to use the Food Centers list to create a cool app.

About The App
The app, "Food Centers", let's you search for eatries, restaurants, bukas (local restaurants), etc in Edo State by street or business names. You can find the application here.

How Does It Work
It's simple and straightforward.

  • Start the application
  • Enter a street name (without the 'street') or business name in the 'Find' box.
  • Click the 'Search' button
  • A SPARQL query based on your search is generated and sent to a SPARQL Endpoint using PHP CURL lib.
  • The search result is retrieved in JSON format and displayed with JQuery Mobile
  • Each business name is anchored with a URI so that It can be exploited via Linked Data follow-your-nose

Further Work
We will geocode each of the addresses and display them on Google map.

Under The Hood
The app was developed with PHP, JQuery mobile, SPARQL, HTML5. The data was converted to RDF format.

Data
RDF/Turtle, RDF/XML.

SPARQL query


   prefix foaf: <http://xmlns.com/foaf/0.1/> 
   prefix edo: <http://www.vikanttimobile.com/opendatang/data/edo-food-centers.ttl#> 
   select distinct ?biz ?Name? Address 
   from <http://www.vikanttimobile.com/opendatang/data/edo-food-centers.ttl> 
   where { 
   ?biz a foaf:Organization. 
   ?biz edo:IsLocated ?Address . 
   ?biz foaf:name ?Name.
   FILTER ( regex(?Name,'" + nameValue + "','i')  || regex(?Address,'" + nameValue + "','i')    ) 
       }
  

  Emeka Okoye

Keywords: linkedopendatang, linkedopendata, opendatanigeria, opendatang, opendata, linkeddata, buka, nigeria, restaurant, hotel, naija30, food, edo

Edo State Food Centers Search App.

Edo State Open Data

Edo State Food Centers in RDF/Turtle

Thursday, March 6, 2014

Dataset: State of Nigerian Universities 2012

Description:  State of Nigerian Universities 2012 .

         

Country: Nigeria

RDF/XML.

Keywords: linkedopendatang, linkedopendata, opendatanigeria, opendatang, opendata, linkeddata, graduate, school, dataset, nigeria, universities, education, naija30, africa30, undergraduate

Information: About the Linked Data document.

Predicates/Properties [via URIBurner Endpoint], [via SPARQLer Endpoint]

Linked Data Follow Your Nose (hosted on rww.io)

Sample Visualization: Pie Chart on the Population of Nigerian Undergraduates by their Courses

Sample SPARQL Queries:

  Emeka Okoye

State of Nigerian Universities 2012.

Tuesday, March 4, 2014

Dataset: Edo State Food Centers

Description:  Edo State Food Centers .

     

Country: Nigeria

RDF/XML.

Keywords: linkedopendatang, linkedopendata, opendatanigeria, opendatang, opendata, linkeddata, dataset, nigeria, edo, food, naija30, africa30, restaurant

Information: About the Linked Data document.

Predicates/Properties [via URIBurner Endpoint], [via SPARQLer Endpoint]

Linked Data Follow Your Nose (hosted on rww.io)

Sample Visualization:

Sample SPARQL Queries:

  Emeka Okoye

List of food centers in Edo State Nigeria.

Dataset: Nigerian Government Budgets for Education

Description:  Nigeria Government Budgets For Education .

Country: Nigeria

RDF/XML.

Keywords: linkedopendatang, linkedopendata, opendatanigeria, opendatang, opendata, linkeddata, dataset, nigeria, budget, examination, naija30, africa30, education

Information: About the Linked Data document.

Predicates/Properties [via URIBurner Endpoint], [via SPARQLer Endpoint]

Linked Data Follow Your Nose (hosted on rww.io)

Sample Visualization:

Sample SPARQL Queries:

 The top Education Budgets in recent time based on percentage of allocation to Education [via URIBurner Endpoint], [via SPARQLer Endpoint] .

prefix odng: <http://www.vikanttimobile.com/opendatang/data/odng-education-budget.ttl#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select str(?year) as ?Year, str(?alloc) as ?Education, str(?budget) as ?TotalBudget, str(?percent) as ?Percent from <http://www.vikanttimobile.com/opendatang/data/odng-education-budget.ttl> where { ?s odng:year ?year . ?s odng:educationAllocation ?alloc. ?s odng:totalBudget ?budget. optional { ?s odng:percentage ?percent. } } order by desc(xsd:double(?percent))

Edit the above query

  Emeka Okoye

Nigeria Government Budgets For Education.

Dataset: West African Examination Council (WAEC) Examination Results

Description:  Results of the West African Examination Council Examination in Nigeria .

Country: Nigeria

RDF/XML, CSV.

Keywords: linkedopendatang, linkedopendata, opendatanigeria, opendatang, opendata, linkeddata, dataset, nigeria, waec, examination, naija30, africa30, education

Information: About the Linked Data document.

Predicates/Properties [via URIBurner Endpoint], [via SPARQLer Endpoint]

Linked Data Follow Your Nose (hosted on rww.io)

Sample Visualization:

Sample SPARQL Queries:

 The top 5 WAEC Examinations with the best performance in 5 subjects including English and Maths [via URIBurner Endpoint], [via SPARQLer Endpoint] .

prefix odng: <http://www.vikanttimobile.com/opendatang/data/odng-education-waec-results.ttl#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select  ?examName as ?Examination, str(?totalCandidates) as ?TotalCandidates, str(?scored5creditsengmaths) as ?Scored5CreditsEngMaths, str(?pctScored5creditsengmaths) as ?PercentScored5creditsEngMaths from <http://www.vikanttimobile.com/opendatang/data/odng-education-waec-results.ttl> where { ?s rdfs:label ?examName. ?s odng:totalCandidates  ?totalCandidates . ?s odng:have5CreditsWithEnglishMaths  ?scored5creditsengmaths . ?s odng:pct5CreditsEnglishMaths ?pctScored5creditsengmaths . optional {?s odng:have6Credits ?scored6credits .} optional {?s odng:have5Credits ?scored5credits .} optional {?s odng:have4Credits ?scored4credits .} optional {?s odng:have3Credits ?scored3credits .} optional {?s odng:have2Credits ?scored2credits .}

} order by desc(xsd:integer(?pctScored5creditsengmaths)) limit 5

Edit the above query

 The top 5 WAEC Examinations with the worst performance in 5 subjects including English and Maths [via URIBurner Endpoint], [via SPARQLer Endpoint] .

prefix odng: <http://www.vikanttimobile.com/opendatang/data/odng-education-waec-results.ttl#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select  ?examName as ?Examination, str(?totalCandidates) as ?TotalCandidates, str(?scored5creditsengmaths) as ?Scored5CreditsEngMaths, str(?pctScored5creditsengmaths) as ?PercentScored5creditsEngMaths from <http://www.vikanttimobile.com/opendatang/data/odng-education-waec-results.ttl> where { ?s rdfs:label ?examName. ?s odng:totalCandidates  ?totalCandidates . ?s odng:have5CreditsWithEnglishMaths  ?scored5creditsengmaths . ?s odng:pct5CreditsEnglishMaths ?pctScored5creditsengmaths . optional {?s odng:have6Credits ?scored6credits .} optional {?s odng:have5Credits ?scored5credits .} optional {?s odng:have4Credits ?scored4credits .} optional {?s odng:have3Credits ?scored3credits .} optional {?s odng:have2Credits ?scored2credits .}

} order by asc(xsd:integer(?pctScored5creditsengmaths)) limit 5

Edit the above query

  Emeka Okoye

Results of the West African Examination Council Examination in Nigeria.

Dataset: Joint Admission Matriculation Board (JAMB) Examination Results

Description:  Results of the Joint Admission Matriculation Board Examinations in Nigeria .

Country: Nigeria

RDF/XML, CSV.

Keywords: opendatanigeria, opendatang, opendata, linkeddata, dataset, nigeria, jamb, examination, naija30, africa30, education

Information: About the Linked Data document.

Predicates/Properties [via URIBurner Endpoint], [via SPARQLer Endpoint]

Linked Data Follow Your Nose (hosted on rww.io)

Sample Visualization:

Sample SPARQL Queries:

 The best 5 performances in JAMB Exams based on the number of candidates that scored more than 50% [via URIBurner Endpoint], [via SPARQLer Endpoint] .

prefix odng: <http://www.vikanttimobile.com/opendatang/data/odng-education-jexams-results.ttl#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?description, ?year, str(?totalCandidate) as ?totalCandidates , str(?scoredAbove200) as ?scoredMoreThan200 , xsd:double(?scoredAbove200) / xsd:double(?totalCandidate) * 100 as ?percent from <http://www.vikanttimobile.com/opendatang/data/odng-education-jexams-results.ttl> where { ?s odng:examOrganization ?exambody . ?s rdfs:label ?description . ?s odng:year ?year . ?s odng:totalAbove200 ?scoredAbove200 . optional {?s odng:totalCandidate ?totalCandidate .} optional {?s odng:above300 ?scoredAbove300 .} optional {?s odng:between270to299 ?scoredAbove270 .} optional {?s odng:between200to249 ?scoredAbove200 .} optional {?s odng:below170 ?scoredBelow170 .} optional {?s odng:between250to270 ?scoredAbove250 .} optional {?s odng:totalBelow200 ?scoredBelow200 .} } order by desc(xsd:integer(?percent ))

Edit the above query

 The top JAMB Examinations that had candidates that scored more than 300 points [via URIBurner Endpoint], [via SPARQLer Endpoint].

prefix odng: <http://www.vikanttimobile.com/opendatang/data/odng-education-jexams-results.ttl#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?description, ?year, str(?totalCandidate) as ?totalCandidates , str(?scoredAbove300) as ?scoredAbove300 from <http://www.vikanttimobile.com/opendatang/data/odng-education-jexams-results.ttl> where { ?s odng:examOrganization ?exambody . ?s rdfs:label ?description . ?s odng:year ?year . ?s odng:above300 ?scoredAbove300 . optional {?s odng:totalCandidate ?totalCandidate .} optional {?s odng:above300 ?scoredAbove300 .} optional {?s odng:between270to299 ?scoredAbove270 .} optional {?s odng:between200to249 ?scoredAbove200 .} optional {?s odng:below170 ?scoredBelow170 .} optional {?s odng:between250to270 ?scoredAbove250 .} optional {?s odng:totalBelow200 ?scoredBelow200 .} } order by desc(xsd:integer(?scoredAbove300 ))

Edit the above query

  Emeka Okoye

Results of the Joint Admission Matriculation Board Examinations in Nigeria.