The objective of this tutorial is to build a simple autocomplete feature based on data extracted from wikipedia (see on-line demo).BackgroundBecause is not always easy to understand the power of SPARQL and of Semantic Web technologies in day-by-day programming, We provided a simple example that solves a very general and frequent problem: autocomplete an input field selecting data from a large dataset. Suppose that you want to write an autocomplete script to help a user writing the name of a river in a form. Here is where the Semantic Web does the magic: you can use Dbpedia to access the full "Wisdom of the crowd" contained in Wikipedia as linked data and get a list of all rivers, in any language! Dbpedia is a great public service but unfortunately it does not ensure any SLA. A reasonable solution is to copy the data you need from dbpedia to your own knowledge base system, so you can safely use it in your application. This is where the LinkedData.Center service plays its role.
The projectAutocomplete is a php open source project hosted in GitHub and you are encouraged to clone and to customize it. It is composed by a javascript/html page, a server script and a knowledge base configuration data file. The html page is a standard implementation of jQueryUi remote autocomplete javascript. The script, by default, connects to https://hub1.linkeddata.center/demo/sparql endpoint. You can also use your own LinkedData.Center instance (free tiers available) just changing credentials in the api code. The knowledge base is populated starting from a Knowledge Exchange Engine Schema (KEES) file. This file is the core of the project. Test in a local environment using Vagrant (suggested)These instructions allow you to install the project on your local workstation using some simple virtualization technologies:
Install on your PHP web server
The provision script contained in the Vagrant file will give an idea of a complete api installation on a ubuntu 14.04 box. The server side scriptjQueryUi remote autocomplete requires a server script file. The script source that searches labels in wikipedia is provided in api/index.php file. Here is the script usage:
Mandatory parameters:
Optional parameters:
Example: the resource:
will return something like:
Try Yourself in the demo site. The client side html codeThe html source with all required javascript is contained in the index.html file. Create your own autocompletion applicationPlease note that you can extend this approach to query any data in billions of linked data sources (public or private) in just three steps:
To improve performances you can add cache at server side script. LicenseAutocomplete project is licensed under the MIT LICENSE . |