Archive for the ‘Ruby’ Category

DBpedia Examples using Linked Data and Sparql

Monday, August 11th, 2008

Using Wikipedia, the largest online encyclopedia, users can browse and perform full-text searches, but programmatic access to the knowledge-base is limited.

The DBpedia project extracts structured information from Wikipedia opening it up to programmatic access using Semantic Web technologies such as Linked Data and SPARQL. This means that the linking and reasoning abilities of RDF and OWL can be utilized and queries for specific information can be made using SPARQL.

Simplistically the mapping from the Wikipedia HTML based web pages to the DBpedia RDF based resources can be thought of as replacing “http://en.wikipedia.org/wiki/” with “http://dbpedia.org/resource/” but in reality there are some additional subtleties which are described in the article From Wikipedia URI-s to DBpedia URI.

The Wikipedia entry for “Civil Engineering” (http://en.wikipedia.org/wiki/Civil_Engineering) is used as an example to show how specific data can be retrieved from its DBpedia equivalent (http://dbpedia.org/resource/Civil_engineering).

When both the Wikipedia entry (http://en.wikipedia.org/wiki/Civil_Engineering) and its DBpedia equivalent (http://dbpedia.org/resource/Civil_engineering) are opened in a standard web browser they display similar information, however the DBpedia equivalent has been redirected to http://dbpedia.org/page/Civil_engineering.

This redirect can be viewed in Firefox using the Tamper Data Firefox Extension as shown in the image below.

Loading the DBpedia Resource

The initial status of 303 is the HTTP response code “303 See Other“. The server replied with the HTTP response code 303 in order to direct the browser to URI http://dbpedia.org/page/Civil_engineering which is a HTML page the browser can display. The original URI http://dbpedia.org/resource/Civil_engineering is an RDF resource that would not display as well in the HTML browser.

DBpedia implements a HTTP mechanism called content negotiation in order to provide clients such as web browsers with the information they request in a form they can display. The tutorial How to publish Linked Data on the Web describe this and other Linked Data techniques that are used by applications such as DBpedia.

In order to access the RDF resource directly a web client needs to tell the server to send it RDF data. A client can do this by sending the HTTP Request Header Accept: application/rdf+xml as part of its initial request. (The HTML browser had sent an Accept: text/html HTTP header indicating that it was requesting an HTML page.)

The Firefox Addon RESTTest can be used to set Accept: application/rdf+xml in the HTTP Request Header and directly request http://dbpedia.org/resource/Civil_engineering as shown in the image below.

In this case the request to http://dbpedia.org/resource/Civil_engineering succeeded as shown by the “Response Status 200″ and a RDF document was received as shown in the “Response Text”.

In both the RDF fragment shown in the image above and in the HTML page http://dbpedia.org/page/Civil_engineering the multiple language support is visible. The SPARQL queries below show how to extract specific information for a particular language.

SPARQL

DBpedia provides a public SPARQL endpoint at http://dbpedia.org/sparql which enables users to query the RDF datasource with SPARQL queries such as the following.

SELECT ?abstract
WHERE {
{ <http://dbpedia.org/resource/Civil_engineering> <http://dbpedia.org/ontology/abstract> ?abstract }
}

The query returns all the abstracts for Civil Engineering, in each of the available languages.

The next query refines the abstracts returned to just the language specified, in this case ‘en’ (English).

SELECT ?abstract
WHERE {
{ <http://dbpedia.org/resource/Civil_engineering> <http://dbpedia.org/ontology/abstract> ?abstract .
FILTER langMatches( lang(?abstract), ‘en’) }
}

The SNORQL query explorer shown in the image below, provides a simpler interface to the DBpedia SPARQL endpoint. The image below shows both the query and the result returned.

Other SPARQL endpoints such as http://demo.openlinksw.com/sparql/ (shown below) can query DBpedia by specifying the FROM NAMED clause to describe the RDF dataset. E.g.

SELECT ?abstract
FROM NAMED <http://dbpedia.org>
WHERE {
{ <http://dbpedia.org/resource/Civil_engineering> <http://dbpedia.org/ontology/abstract> ?abstract.
FILTER langMatches( lang(?abstract), ‘en’) }
}

Other Related DBpedia Articles

RDF as self-describing Data uses DBpedia and its SPARQL support to show how RDF is essentially ’self-describing’ – there is no need to know about traditional metadata (schemas) before exploring a data set.

Linking to DBpedia with TopBraid outlines the benefit of DBpedia in terms of providing relatively stable URIs for all relevant real-world concepts, thus making it a natural place to connect specific domain models with each other using the OWL built in propery owl:sameAs ( This property indicates that two URI references actually refer to the same thing ). TopBraid Composer provides support to link domain models with DBpedia .

Querying DBpedia provides examples of using SPARQL to query DBpedia.

Adding Semantic Markup to Your Rails Application with DBpedia and ActiveRDF and
Get Semantic with DBPedia and ActiveRDF describe using ActiveRDF to integrate DBpedia resources into web based applications. ActiveRDF is a library for accessing RDF data from Ruby and Ruby On Rails programs and can perform SPARQL queries.

Linking to Photo Sharing Sites

Saturday, January 5th, 2008

I have users with photos published on photo sharing sites such as Flickr, Fotopic, ImageShack, Livejournal, Photobucket, Picasaweb, SmugMug, Webshots and others.

What I want to do is provide these users with the ability to link these published photos to projects managed by our web application. Within our application only the published URL to the image would be stored.

The Flickr API, with its support for REST, is the ideal site to use as a proof of concept. At least one other site, 23 also implements the Flickr API, making it easy to support both 23 and Flickr.

The Ajax based Flickr Related Tag Browser provides a good example of how to use the Flickr API to browse and select photos by tag. Within our application a user wold browse their Flickr account and search by photo album, tag or date to retrieve specific photos which would illustrate the project site itself, tasks to be accomplished, problems associated with a task or as visual confirmation that a task had been completed.

As an example I have two projects that I am about to start.

  • The first is to widen a driveway, add a front gate and landscape the front garden to link in with the new driveway and gate.
  • The second is to complete the garage at the back of the property, which includes adding a couple of rooms that will link up with the existing studio kitchen and main room.

The photos for these two different projects I have tagged gate and garage respectively on my Flickr account.

The default Flickr web pages that open for

  • http://www.flickr.com/photos/richard3kbo/tags/gate/ and
  • http://www.flickr.com/photos/richard3kbo/tags/garage/

by themselves give good overviews of the two different project sites.

Linking specific photos to project tasks helps illustrate and clarify these tasks.

Using photos published on Flickr and similar sites allows our users to continue using the photo sharing sites they are used to and which have more features for image processing and sharing than our site.

Installing Ruby On Rails on Mac OS X

Saturday, August 25th, 2007

The two main sites I am working with are www.3kbo.com and www.abeservices.com.au. 3kbo is hosted at www.railsplayground.com and is centered around Ruby On Rails apps while www.abeservices.com.au has its own server and is java focused.

The plan is to develop semantic web based applications using the Ruby based RDF framework ActiveRDF and deploy them at 3kbo. The 3kbo applications will also be leveraging the Ruby On Rails web framework.

The first step in getting started is to install Ruby On Rails on my new(ish) Mac PowerBook. Initially I will be using just two of the available ActiveRDF adaptors, “SPARQL” and “RDFLite”. RDFLite needs SQLite3, meaning that the default version that comes with Mac OS X needs to be updated. Since RDFLite can also utilize ferret , the Ruby search engine library, this was installed as well.

To install Ruby on Rails I followed the basic instructions outlined in Installing Ruby on Rails and PostgreSQL on OS X.

This approach uses MacPorts and overall worked well, apart from getting the following error at the very beginning:

“Error: search for portname ruby failed: No index(es) found! Have you synced your source indexes?”

The fix was to run the port selfupdate command:

$ sudo port selfupdate

After that ruby and ruby gems were successfully installed with the port command:

$ sudo port install ruby rb-rubygems

Well almost. The first attempt to install rails using gem ended with the error:

Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find rails (> 0) in any repository

Problem solved by following the instructions at http://armyofevilrobots.com/node/418, i.e delete the gem source_cache and update gems.

$ sudo gem update

With gem updated rails installed fine.

$ sudo gem install -y rails

SQLite3 installed without problem

$ sudo port install sqlite3

So did ferret

$ gem install ferret

To test that all was fine I created a basic Rails app following the steps outlined in Rolling with Ruby on Rails Revisited

$ rails example
$ cd example
$ ruby script/server

And view at http://localhost:3000/

Or to check when running with Mongrel

$ mongrel_rails start

And view at http://localhost:3000/

With the basic Rails app working it was time to get started with ActiveRDF.