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.

Saturday, May 9, 2015

Muhammadu Buhari's Election Campaign Promises in Nanotation

My notes, in portable #nanotation form (comprehensible to both humans and machines), on promises made by President-elect Muhammadu Buhari to Nigerians during his political campaigns constructed from a blog post by Simon Ateba.
{
 
<>
a schema:WebPage, foaf:Document;
rdfs:label "Buhari's Election Promises"@en ;
rdfs:comment """
Buhari's promises to Nigerians during his political campaigns.
             """@en; 
schema:creator  ;
dcterms:created "2015-05-09T03:15:00-05:00"^^xsd:dateTime ;
dcterms:modified  "2015-05-09T03:15:00-05:00"^^xsd:dateTime ;
schema:about <#ElectionPromise> ;
dcterms:hasPart <#Promise1>, <#Promise2>, <#Promise3>, <#Promise4>,<#Promise5>,<#Promise6>,<#Promise7>,<#Promise8>,<#Promise9>,<#Promise10>,<#Promise11> ;
dcterms:source  ;
xhv:license   .


<#Buhari>
a foaf:Person ;
foaf:name "Muhammadu Buhari" ;
owl:sameAs dbpedia:Muhammadu_Buhari ;
schema:about , ,  . 


<#Promise1>
a schema:CommunicateAction ;
rdfs:label "Promise #1" ;
skos:altLabel "Electricty" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Buhari promised to deliver 20,000 megawatts of electricity in four years to surpass Nigeria’s consumption level of around 15,000mw. """ @en ;
schema:mentions dbpedia:Power_Holding_Company_of_Nigeria, dbpedia:Nigeria, dbpedia:Electricity ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise2>
a schema:CommunicateAction ;
rdfs:label "Promise #2" ;
skos:altLabel "Exchange Rate" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Sometime around March 23 in Owerri, Imo State, Buhari promised to make naira equal to dollar. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Nigerian_naira, dbpedia:Dollar ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise3>
a schema:CommunicateAction ;
rdfs:label "Promise #3" ;
skos:altLabel "Employment" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Around January 25, Buhari promised to create one million jobs for Igbo youths by revamping huge coal deposits in Enugu State for generation of electricity and export """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Employment,dbpedia:Nigerian_Coal_Corporation, dbpedia:Electricity ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise4>
a schema:CommunicateAction ;
rdfs:label "Promise #4" ;
skos:altLabel "Housing" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Sometime around December 18, Buhari told the nation that he will create around 4 million new home owners by 2019 """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Affordable_housing, dbpedia:Housing ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .



<#Promise5>
a schema:CommunicateAction ;
rdfs:label "Promise #5" ;
skos:altLabel "Industry" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ During his campaign in Lokoja sometime around January 17, Buhari pledged to revive Ajaokuta Steel Company. He said he would resuscitate the company which had been out of production for the past five years. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Ajaokuta ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise6>
a schema:CommunicateAction ;
rdfs:label "Promise #6" ;
skos:altLabel "Transportation" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Ekiti_State ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ He also promised to build an airport in Ekiti State, which someone called a deceit. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Airport, dbpedia:Ekiti_State ;
dcterms:source  ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise7>
a schema:CommunicateAction ;
rdfs:label "Promise #7" ;
skos:altLabel "Poverty" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ He also promised to make direct cash transfer of NGN 5,000 to the 25 million poorest and most vulnerable citizens, if they immunize children and enroll them in school. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Poverty_in_Nigeria ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .


<#Promise8>
a schema:CommunicateAction ;
rdfs:label "Promise #8" ;
skos:altLabel "Education" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ I will provide 1 meal a day for children in public primary schools. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Education_in_Nigeria ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .



<#Promise9>
a schema:CommunicateAction ;
rdfs:label "Promise #9" ;
skos:altLabel "Oil and Gas" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Revive and reactivate our minimally performing Refineries to optimum capacity; Make the industry and Nigeria one of the world leading/cutting edge centres for clean oil and gas technology; also producing leading world Oil and Gas technologist, scientists, and owing mega structure installations. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Petroleum_industry_in_Nigeria, dbpedia:Oil_refinery ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .



<#Promise10>
a schema:CommunicateAction ;
rdfs:label "Promise #10" ;
skos:altLabel "Women" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ Implementation of the 2005 National Gender Policy, which serves as a road map for the promotion of women’s empowerment and gender equality in Nigeria. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Woman, dbpedia:Women_in_Nigeria ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .



<#Promise11>
a schema:CommunicateAction ;
rdfs:label "Promise #11" ;
skos:altLabel "Security" ;
schema:agent <#Buhari> ;
schema:recipient dbpedia:Nigerians ;
schema:participant dbpedia:All_Progressives_Congress ;
schema:object """ He also promised to deal with Boko Haram with a few months. """ @en ;
schema:mentions dbpedia:Nigeria, dbpedia:Boko_Haram ;
dcterms:isPartOf  ;
schema:creator  ;
schema:about <> .




<#ElectionPromise>
a skos:Concept ;
rdfs:label "Election Promise"@en;
owl:sameAs dbpedia:Election_promise .   



a schema:WebPage, schema:BlogPosting;
rdfs:label "Just So We Don’t Forget; A Recap Of Buhari’s Promises – Simon Ateba" ;
schema:about <#Buhari> ;
schema:url  .



a foaf:Person ;
foaf:name "Emeka Okoye" ;
owl:sameAs ,  ;
schema:about ,   . 


}



Friday, March 20, 2015

Linked Open Election Framework for Publishing Election Data and Results in Structured Formats

Author:
Topics: , , , , ,
Situation analysis

In most part of the world, there is hardly any freely available database of political election results in existence. This is because the data required to compile it is located in different websites or documents. The information is presented in many different formats and many different ways, and the only way the information can be compiled for re-use is by manual methods.

The Linked Open Election Framework is supporting the publication of election results as (the language used to write web pages) embed (called "Metadata") in the source code. Though invisible to normal users, publishing the information in this way gives it structure and meaning, and allowing machines to understand its meaning.

What is the Linked Open Election Framework?

The main point of is to aid accountability and transparency and this framework supports the publication and public access to Election results on websites as – data that is published under an open licence that allows unrestricted reuse, and that is marked up to identify the structure and meaning, making possible its automated collection for re-publishing and mashing up with other data.

How does it work?

Rather than publishing using not-so open formats or standards like PDF, HTML, Plain Text, etc, we embed machine-readable metadata in the HTML source code of web pages. These metadata is derived from information defined from the Election data. Entities or "things" that make up the Election data are defined as items and described in an HTML page. Each item is made up of one or more key-value pairs: a property and a value. The Microdata syntax is completely made up of HTML attributes. These attributes can be used on any valid HTML element. This gives the information structure and meaning, with a licence to allow collection, collation and reuse by anyone at no cost.

This structured information or "Structured Data" is a broad term that encompasses various standards and encoding mechanisms but, at the end of the day, refers to information provided to data consumers specifically for machine consumption. This machine-readable code is closely-allied to, but separate from, the presentation layer that us humans consume when we read a web page, providing a way for dumb machines to better understand the entities and connections between entities present in a piece of content.

Although this additional code does not directly impact the user's experience of the page, it makes a big difference to machines (including Bots, Smart Agents, Search Engines, etc), helping them to "understand" that (for example) this webpage:

  • Is a News Article
  • Has the headline "Election Results for Ekiti Governorship Election 2014"
  • Has information on a "Poll" event held on June 21, 2014

To make this metadata available we have used a vocabulary (or ) called Linked Open Election. This vocabulary provides a simple way of expressing Election data and information in Linked Data formats. Additionally, we used vocabulary proposed by Google, Bing, Yahoo and others

This metadata comprises of real-world entities refered by Uniform Resource Identifiers (URIs).

Benefits

: An immediate benefit of this work will be that search engines will be better able to display links to these News articles, helping users to find relevant stories and to determine from a search engine's listings the relevance of the article to the story that they are searching for and ultimately help to open up references to the data contained in those stories.

Linked Open Data: It will create an open database of election data and results.

Why is it important?

The use of Linked Open Data provides a clear signal to every organizations and governments the imminence of the "web of data" or Web 3.0. Every Web Site has to evolve into a Linked Data Space: a location on the Web that provides granular access to discrete data items in line with the core principles of the Linked Data meme.

Remember, the essence of the Linked Data meme is simply this: you reference data items and access their metadata, in variety of formats via a single HTTP based URI. This approach to Web data publishing is compatible with any HTTP aware user agent (e.g. your Web Browser or tools & applications that provide abstracted access to HTTP).

Do you need a special software to do this?

No, just the same way to mark up HTML. This also works in Content Management and Blogging system.

Tutorials & How to

  • How to Embed Election Data in HTML using HTML5, Microdata and Linked Data - Read
  • How to Publish Election Data in Nanotation (aka micro-Turtle) - Read
  • Sample Nanotation on Election Data and Results - View
  • Sample Election Data in RDF (turtle) document - View
  • Sample Election Data in HTML5, Microdata format - View
  • Sample Election Poll Data in RDF (turtle) document - View
  • List of Nigerian Political Parties in RDF (turtle) document - View
  • Linked Open Election Ontology - View
  • Prefix - loe
  • About Linked Open Election Framework - Read

Tuesday, March 10, 2015

Sample Nanotation on Election Data and Results

Sample Nanotation on Election Data

.

Nanotation,also known as micro , that describes an election that was held on the 21st of june 2014 in Nigeria is as follows:


	{

		@prefix schema:   .
		@prefix election:  .
		
		<>
		a schema:NewsArticle, election:Poll ;
		
		schema:name "Election Results";
		schema:headline "Election Results";

		schema:author [
				  a schema:Person ;
				  schema:name "Emeka Okoye" ;
				  schema:url  ;
		
		]	;
		schema:creator [
				  a schema:Person ;
				  schema:name "Emeka Okoye" ;
				  schema:url  ;
		
		]	;
		
		schema:about [
				  a schema:Thing ;
				  schema:name "Election" ;
				  schema:url  ;
		
		]	, 
		
		[
				  a schema:Thing ;
				  schema:name "Elections in Nigeria" ;
				  schema:url  ;
		
		]	; 
		
		schema:articleBody "your story or article goes here" ;
		schema:sourceOrganization 	[
				  a schema:Organization ;
				  schema:name "OpenDataNG" ;
				  schema:url  ;
		
		]	; 

		schema:provider [
				  a schema:Organization ;
				  schema:name "OpenDataNG" ;
				  schema:url  ;
		
		]	;  
		
		election:hasElectionDate "2014-06-21"^^xsd:date ;
		election:hasConstituency  ;
		election:hasRegisteredVoters "733766"^^xsd:integer ;
		election:hasAccreditedVoters "369257"^^xsd:integer ;
		election:hasTotalBallots "360455"^^xsd:integer ;
		election:hasInvalidBallots "10089"^^xsd:integer ;
		election:hasValidBallots "350366"^^xsd:integer ;
		election:hasViolence "false"^^xsd:boolean ;
		election:isCandidate <#candidate1>, <#candidate2>, <#candidate3> ;
		election:hasElectoralFraud "false"^^xsd:boolean .
		
		<#candidate1> a election:Candidate ;
		schema:name "Ayodele Peter Fayose" ;
		election:isOfPoliticalParty  ;
		election:hasVotes "203090"^^xsd:integer ;
		election:isElected "true"^^xsd:boolean .

		<#candidate2> a election:Candidate ;
		schema:name "John Olukayode Fayemi" ;
		election:isOfPoliticalParty  ;
		election:hasVotes "120433"^^xsd:integer ;
		election:isElected "false"^^xsd:boolean .
		
		
		<#candidate3> a election:Candidate ;
		schema:name "Bamidele Michael Opeyemi" ;
		election:isOfPoliticalParty  ;
		election:hasVotes "18135"^^xsd:integer ;
		election:isElected "false"^^xsd:boolean .
		
	
	}

Friday, March 6, 2015

Linked Open Election Framework Implementation Guide for Nanotation

How to Publish Election Data in Nanotation

.

Subjects: , , ,

Introduction:

This guide will show you how to implement the Linked Open Election Data using Nanotation and the Linked Election Framework.

Nanotations, which are micro Turtle, are deployable from any social media/networking space or service that offers the ability to post plain text (Twitter Tweets, Facebook Posts, Google+ Posts, LinkedIn Posts, Blog Posts, Comments, Mailing List Posts etc.. ).

This guide assumes a basic knowledge of Nanotation. If you're new to the subject or just need some brushing up, we recommend that you read the Kingsley Idehen's post on Nanotation.

Solution:

  1. First thing to do is to define the article or post that will host the election data:

    	{
    
    		@prefix schema:   .
    		
    		<>
    		a schema:NewsArticle ;
    		
    	}
     
    Please note that you can also use other Schema.org classes like schema:Article,schema:TechArticle, schema:BlogPost, schema:ScholarlyArticle as the document type.

  2. Define the name and headline of the post.

     
    	{
    
    		@prefix schema:   .
    		
    		<>
    		a schema:NewsArticle ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results".
    	
    	}
     

  3. Embed the author's name and profile URI (eg. Google+, WebID-Profile, DBpedia, Freebase, etc) :

    	{
    
    		@prefix schema:   .
    		
    		<>
    		a schema:NewsArticle ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	.
    	
    	}
    
     

  4. Annotate the data, tags or subject associated with the article. You can define as many as possible using entities in Wikipedia, Freebase and Linked Open Data (LOD), delimited with commas :

     	{
    
    		@prefix schema:   .
    		
    		<>
    		a schema:NewsArticle ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		
    		schema:about [
    				  a schema:Thing ;
    				  schema:name "Election" ;
    				  schema:url  ;
    		
    		]	, 
    		
    		[
    				  a schema:Thing ;
    				  schema:name "Elections in Nigeria" ;
    				  schema:url  ;
    		
    		]	. 
    	
    	}
    
     
    We're going to finish by annotating all of the data we've asserted concerning the article's associated entities.

  5. Embed your news story or article within the attribute "articleBody" .

     	{
    
    		@prefix schema:   .
    		
    		<>
    		a schema:NewsArticle ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		
    		schema:about [
    				  a schema:Thing ;
    				  schema:name "Election" ;
    				  schema:url  ;
    		
    		]	, 
    		
    		[
    				  a schema:Thing ;
    				  schema:name "Elections in Nigeria" ;
    				  schema:url  ;
    		
    		]	; 
    		
    		schema:articleBody "your story or article goes here" .
    	
    	}
    
     

  6. Embed the election results. See subsequent steps on how to embed election polling data.

  7. Define and setup your poll and add the election schema.

     
     	{
    
    		@prefix schema:   .
    		@prefix election:  .
    		
    		<>
    		a schema:NewsArticle, election:Poll ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		
    		schema:about [
    				  a schema:Thing ;
    				  schema:name "Election" ;
    				  schema:url  ;
    		
    		]	, 
    		
    		[
    				  a schema:Thing ;
    				  schema:name "Elections in Nigeria" ;
    				  schema:url  ;
    		
    		]	; 
    		
    		schema:articleBody "your story or article goes here" .
    	
    	}
      
     

  8. Add and update the attributes of the poll and candidates

     	{
    
    		@prefix schema:   .
    		@prefix election:  .
    		
    		<>
    		a schema:NewsArticle, election:Poll ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		
    		schema:about [
    				  a schema:Thing ;
    				  schema:name "Election" ;
    				  schema:url  ;
    		
    		]	, 
    		
    		[
    				  a schema:Thing ;
    				  schema:name "Elections in Nigeria" ;
    				  schema:url  ;
    		
    		]	; 
    		
    		schema:articleBody "your story or article goes here" ;
    		
    		election:hasElectionDate "2014-06-21"^^xsd:date ;
    		election:hasConstituency  ;
    		election:hasRegisteredVoters "733766"^^xsd:integer ;
    		election:hasAccreditedVoters "369257"^^xsd:integer ;
    		election:hasTotalBallots "360455"^^xsd:integer ;
    		election:hasInvalidBallots "10089"^^xsd:integer ;
    		election:hasValidBallots "350366"^^xsd:integer ;
    		election:hasViolence "false"^^xsd:boolean ;
    		election:isCandidate <#candidate1>, <#candidate2>, <#candidate3> ;
    		election:hasElectoralFraud "false"^^xsd:boolean .
    		
    		<#candidate1> a election:Candidate ;
    		schema:name "Ayodele Peter Fayose" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "203090"^^xsd:integer ;
    		election:isElected "true"^^xsd:boolean .
    
    		<#candidate2> a election:Candidate ;
    		schema:name "John Olukayode Fayemi" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "120433"^^xsd:integer ;
    		election:isElected "false"^^xsd:boolean .
    		
    		
    		<#candidate3> a election:Candidate ;
    		schema:name "Bamidele Michael Opeyemi" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "18135"^^xsd:integer ;
    		election:isElected "false"^^xsd:boolean .
    	
    	
    	}
    
    
    	
     

  9. Finally, you can add the provider organization data. The url attribute should be the website URL of the news or blogger organization while the name of the organization is added to the name attribute:

    
     	{
    
    		@prefix schema:   .
    		@prefix election:  .
    		
    		<>
    		a schema:NewsArticle, election:Poll ;
    		
    		schema:name "Election Results";
    		schema:headline "Election Results";
    
    		schema:author [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		schema:creator [
    				  a schema:Person ;
    				  schema:name "Creator's name" ;
    				  schema:url  ;
    		
    		]	;
    		
    		schema:about [
    				  a schema:Thing ;
    				  schema:name "Election" ;
    				  schema:url  ;
    		
    		]	, 
    		
    		[
    				  a schema:Thing ;
    				  schema:name "Elections in Nigeria" ;
    				  schema:url  ;
    		
    		]	; 
    		
    		schema:articleBody "your story or article goes here" ;
    		schema:sourceOrganization 	[
    				  a schema:Organization ;
    				  schema:name "Your organization name" ;
    				  schema:url  ;
    		
    		]	; 
    
    		schema:provider [
    				  a schema:Organization ;
    				  schema:name "Your organization name" ;
    				  schema:url  ;
    		
    		]	;  
    		
    		election:hasElectionDate "2014-06-21"^^xsd:date ;
    		election:hasConstituency  ;
    		election:hasRegisteredVoters "733766"^^xsd:integer ;
    		election:hasAccreditedVoters "369257"^^xsd:integer ;
    		election:hasTotalBallots "360455"^^xsd:integer ;
    		election:hasInvalidBallots "10089"^^xsd:integer ;
    		election:hasValidBallots "350366"^^xsd:integer ;
    		election:hasViolence "false"^^xsd:boolean ;
    		election:isCandidate <#candidate1>, <#candidate2>, <#candidate3> ;
    		election:hasElectoralFraud "false"^^xsd:boolean .
    		
    		<#candidate1> a election:Candidate ;
    		schema:name "Ayodele Peter Fayose" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "203090"^^xsd:integer ;
    		election:isElected "true"^^xsd:boolean .
    
    		<#candidate2> a election:Candidate ;
    		schema:name "John Olukayode Fayemi" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "120433"^^xsd:integer ;
    		election:isElected "false"^^xsd:boolean .
    		
    		
    		<#candidate3> a election:Candidate ;
    		schema:name "Bamidele Michael Opeyemi" ;
    		election:isOfPoliticalParty  ;
    		election:hasVotes "18135"^^xsd:integer ;
    		election:isElected "false"^^xsd:boolean .
    		
    	
    	}
    
    
    	
    	
     

That is it.

Information:

References

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

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

- http://www.w3.org/TR/turtle/

- http://kidehen.blogspot.com/2015/01/review-publishing-for-everyone.html

- http://kidehen.blogspot.com/2014/07/nanotation.html

Keywords: linked data, election, semantic web, turtle

Sunday, March 1, 2015

Linked Open Election Framework Implementation Guide for HTML5 + Microdata

How to Embed Election Data in HTML using HTML5, Microdata and Linked Data

.

Subjects: , , , , ,

Introduction:

This guide will show you how to implement the Linked Open Election Data using HTML5, Microdata and the Linked Election Framework. You can also use RDFa instead of Microdata. It is left to implementing organizations to determine which implementation best suits their particular business needs.

This guide assumes a basic knowledge of HTML5 and Microdata. If you're new to the subject or just need some brushing up, we recommend that you review the Wikipedia article on HTML 5 Microdata.

Solution:

  1. First thing to do is to define the article or post that will host the election data:

      <html itemscope itemtype="http://schema.org/NewsArticle" itemid="http://your-domain/news-story.html">
      ---
      </html>
     
    for content management system (CMS) like wordpress, tumblr, blogspot, drupal, etc you can use the <div> tag:
      <div itemscope itemtype="http://schema.org/NewsArticle"  itemid="http://your-domain/news-story.html">
      ---
      </div>
     
    Please note that you can also use other Schema.org classes like http://schema.org/Article,http://schema.org/TechArticle, http://schema.org/BlogPost, http://schema.org/ScholarlyArticle as the itemtype.

  2. Define the name and headline of the post. You can use any of the HTML elements (<span>,<div>,<a>,<h>, etc) for these:

      <h1 itemprop="name headline">Election Results</h1>
     

  3. Embed the author's name and profile URI (eg. Google+, WebID-Profile, DBpedia, Freebase, etc) :

      <div itemprop="author creator" itemscope itemtype="http://schema.org/Person">
       <strong>Author:</strong>  <a href="https://plus.google.com/+EmekaOkoye/" rel="publisher" itemprop="url">
       <span itemprop="name">Emeka Okoye</span></a><br />
      </div>
    
     

  4. Annotate the data, tags or subject associated with the article. You can define as many as possible using entities in Wikipedia, Freebase and Linked Open Data (LOD), delimited with commas :

      <strong>Topics:</strong> 
      <span itemprop="about" itemscope itemtype="http://schema.org/Thing" itemid="http://dbpedia.org/resource/Election">
      <a href="http://en.wikipedia.org/wiki/Election" itemprop="url"><span itemprop="name">Election</span></a>
      </span>,
    
     
    We're going to finish by annotating all of the data we've asserted concerning the article's associated entities.

  5. Embed your news story or article within the attribute "articleBody" tag. You can specify the attribute itemprop="articleBody" multiple times in a web page if the story is located in different sections of the page.

      <div itemprop="articleBody">
       your story goes here
      </div>
     

  6. Embed the election results within a <div> tag. See subsequent steps on how to embed election polling data.

  7. Define and setup your poll :

      <div itemscope itemtype="http://linkedopendatang.com/schemas/election#Poll">
      </div>
     

  8. Modify the previous <div> to Add and update the attributes of the poll :

      <div itemscope itemtype="http://linkedopendatang.com/schemas/election#Poll">
       <!-- define constituency. Use any instance of schema:place, dbpedia:place -->
       <p><strong>Constituency:</strong> <a itemprop="hasConstituency" href="http://dbpedia.org/resource/Ekiti_State">Ekiti State</a></p>
       
       <!-- define poll date. date format is yyyy-mm-dd  -->
       <p><strong>Election Date:</strong> <meta content="2014-06-21" itemprop="hasElectionDate"/>June 21, 2014</p>
       
       <!-- define poll's registered voters  -->
       <p><strong>Registered Voters:</strong> <span itemprop="hasRegisteredVoters">733766</span></p>
       
       <!-- define poll's accredited voters  -->
       <p><strong>Accredited Voters:</strong> <span itemprop="hasAccreditedVoters">369257</span></p>
       
       <!-- define total ballot papers used  -->
       <p><strong>Total Ballot Papers Used: </strong><span itemprop="hasTotalBallots">360455</span></p>
       
       <!-- define total invalid votes  -->
       <p><strong>Invalid Votes: </strong><span itemprop="hasInvalidBallots">10089</span></p>
       
       <!-- define total valid votes  -->
       <p><strong>Valid Votes: </strong><span itemprop="hasValidBallots">350366</span></p>
       
       <!-- define reported violence. format is boolean  -->
       <p><strong>Any Reported Violence: </strong><span itemprop="hasViolence">False</span></p>
       
       <!-- define reported fraud. format is boolean  -->
       <p><strong>Any Reported Fraud: </strong><span itemprop="hasElectoralFraud">False</span></p>
       
       <!-- A poll must have 2 or more candidates. Each candidate must be defined in a <div> or <span> tag -->
       <!-- candidate 1 -->
       <div itemprop="isCandidate" itemscope itemtype="http://linkedopendatang.com/schemas/election#Candidate">
       <dl>
        <!-- define candidate's name  -->
        <dt>Candidate's Name </dt>
        <dd><div itemprop="hasName" itemscope itemtype="http://schema.org/Person" itemid="#fayose"><span itemprop="name">Ayodele Peter Fayose</span>
        <meta itemprop="sameAs" content="http://dbpedia.org/resource/Ayo_Fayose"/>
        </div>
        </dd> 
    
        <!-- define candidate's party  -->
        <dt>Candidate's Party </dt>
        <dd><a itemprop="isOfPoliticalParty" href="http://linkedopendatang.com/entity/ngpoliticalparty.ttl#pdp">PDP</a></dd>
    
        <!-- define candidate's votes  -->
        <dt>Candidate's Votes </dt>
        <dd><span itemprop="hasVotes">203090</span></dd>
    
        <!-- define candidate's success status.  -->
        <dt>Elected? </dt>
        <dd><span itemprop="isElected">True</span></dd>
      
       </dl>
       </div>
       
       <!-- follow the previous approach on candidate 1 for other candidates
       <!-- candidate 2 -->
       <div itemprop="isCandidate" itemscope itemtype="http://linkedopendatang.com/schemas/election#Candidate">
        data goes here
       </div>
       
       <!-- candidate n -->
       <div itemprop="isCandidate" itemscope itemtype="http://linkedopendatang.com/schemas/election#Candidate">
        data goes here
       </div>
      </div>
     

  9. Finally, you can add the provider organization data. The url attribute should be the website URL of the news or blogger organization while the name of the organization is added to the name attribute:

       <span
        itemprop="sourceOrganization provider"
        itemscope
        itemtype="http://schema.org/Organization"
        itemid="http://linkedopendatang.blogspot.com">
        <meta itemprop="name" content="Linked Open Data Nigeria" />
        <meta itemprop="url" content="http://linkedopendatang.blogspot.com" />
        </span>
    
     

That is it.
  1. You can query the data (microdata) with sparql

  2. There are tools or distillers like RDF Distiller or pyMicrodata that can convert microdata stored in web pages into RDF triples, making it possible to query this data with SPARQL

  3. For instance, to get all data in a webpage, enter the following query at a sparql endpoint:

     select *
     from <http://www.w3.org/2012/pyMicrodata/extract?uri=[URL of Web Page]&format=turtle>
     

  4. You can view a sample here

Information:

  • View a live demo here.
  • View extracted data from live demo here
  • The source and samples are on github.

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: linked data, election, HTML5, html, semantic web, microdata