Skip to content
Simeon Ackermann edited this page Oct 20, 2015 · 7 revisions

Erfurt Application Framework

Following a short overview how you can start with the Erfurt-API as a standalone app to interact with the data store over SPARQL.

There are two different backends available for Erfurt. One is our Erfurt integrated MySQL store, the other option is virtuoso. In the following both options are described. All section specific to MySQL are marked with MySQL and those specific to a setup with virtuoso are marked with Virtuoso.

We assume, that you have installed one of MySQL or Virtuoso. For instructions how to install and setup Virtuoso please read the documentation at:

On Debian systems it might be enough to run apt-get install virtuoso-opensource php5-odbc php5-xml which will bring with it all necessary dependencies.

Install Erfurt API

Create a new folder (e.g. MyErfurt) somewhere on your file system, where your web server can find it.

mkdir MyErfurt

Clone the Erfurt source code or download a zip release from github. Move the downloaded Erfurt folder into the new Folder (in our example MyErfurt).

Get a copy of the Zend-Framework. You can download it and move the folder ZendFramework-xx/library/Zend (xx is the Zend version number) into the MyErfurt folder. Alternatively you can copy it from an existing OntoWiki installation or create a symbolic link to it.

Folder structure

Now you should have following items in MyErfurt folder:

  • MyErfurt/Erfurt - Symbolic link or raw folder
  • MyErfurt/Zend - Symbolic link or raw folder

Give Erfurt DBS access MySQL

Now, go into MyErfurt/Erfurt/Erfurt folder

cd MyErfurt/Erfurt/Erfurt

and copy one of the config.ini-dist-mysql files to config.ini.

cp config.ini-dist-mysql config.ini

After that, update config.ini with your access data. You should change only this two items

store.zenddb.username 
store.zenddb.password 

Connect Erfurt to Virtuoso Virtuoso

Add your Erfurt-folder to the following line in /etc/virtuoso-opensource-xx/virtuoso.ini (xx is the Zend version number):

DirsAllowed = ., /usr/share/virtuoso-opensource-xx/vad, /path/to/MyErfurt/Erfurt/Erfurt

Now, go into MyErfurt/Erfurt/Erfurt folder

cd MyErfurt/Erfurt/Erfurt

and copy the config.ini-dist-virtuoso files to config.ini.

cp config.ini-dist-virtuoso config.ini

After that, check config.ini if the access data correct. Usually the pre-settings should work.

store.virtuoso.dsn      = VOS
store.virtuoso.username = dba
store.virtuoso.password = dba

Playing with fancy models

Now create a file in the MyErfurt folder for your first steps, named index.php. Open it and write:

$main_dir = rtrim(dirname(__FILE__), '/\\');

# Set include paths
$includePath  = get_include_path() . PATH_SEPARATOR;

$includePath .= $main_dir . '/Erfurt/' . PATH_SEPARATOR;
$includePath .= $main_dir . '/Erfurt/Erfurt/' . PATH_SEPARATOR;
$includePath .= $main_dir . '/Zend/'. PATH_SEPARATOR;

set_include_path($includePath);

Now we include and configure the Zend Autoloader which includes required classes.

# Include Zend Autoloader
require_once 'Zend/Loader/Autoloader.php';

# Configure Zend Autoloader
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Erfurt_');

As the environment is prepared we can initialize the API by instantiating the Erfurt_App.

# Creating an instance of Erfurt API
$app = Erfurt_App::getInstance();

You need to authenticate on Erfurt with a valid user. The easiest is use the user and password of you database connection (the one you have configured in default.ini) If you have an OntoWiki installation running with the same database you can also use a valid user access from your installed OntoWiki. The example reads the user name and password from default.ini:

# Authentification on Erfurt (needed for model access)
$dbUser = $app->getStore()->getDbUser();
$dbPass = $app->getStore()->getDbPassword();
$app->authenticate($dbUser, $dbPass);

So... lets get data and show them!

# Get a new model
try {
    # Create it if it doesn't exist
    $model = $app->getStore()->getNewModel('http://localhost/MyErfurt');
} catch (Erfurt_Store_Exception $e) {
    # Get it if it already exists
    $model = $app->getStore()->getModel('http://localhost/MyErfurt');
}

# Get and show all items of the model 
echo "<pre>";
var_dump($model->sparqlQuery('SELECT ?s ?p ?o WHERE {?s ?p ?o}')); 
echo "</pre>";

Too many code snippets? Here is the complete code.

<?php

$main_dir = rtrim(dirname(__FILE__), '/\\');

# Set include paths
$includePath  = get_include_path() . PATH_SEPARATOR;

$includePath .= $main_dir . '/Erfurt/' . PATH_SEPARATOR;
$includePath .= $main_dir . '/Erfurt/Erfurt/' . PATH_SEPARATOR;
$includePath .= $main_dir . '/Zend/'. PATH_SEPARATOR;

set_include_path($includePath);

# Include Zend Autoloader
require_once 'Zend/Loader/Autoloader.php';

# Configure Zend Autoloader
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Erfurt_');

# Creating an instance of Erfurt API
$app = Erfurt_App::getInstance();

# Authentification on Erfurt (needed for model access)
$dbUser = $app->getStore()->getDbUser();
$dbPass = $app->getStore()->getDbPassword();
$app->authenticate($dbUser, $dbPass);

# Get a new model
try {
    # Create it if it doesn't exist
    $model = $app->getStore()->getNewModel('http://localhost/MyErfurt');
} catch (Erfurt_Store_Exception $e) {
    # Get it if it already exists
    $model = $app->getStore()->getModel('http://localhost/MyErfurt');
https://raw.github.com/olberger/Erfurt/master/example-app.php}

# Get and show all items of the model 
echo "<pre>";
var_dump ($model->sparqlQuery('SELECT ?s ?p ?o WHERE {?s ?p ?o}')); 
echo "</pre>";

After executing it in your browser by calling http://localhost/MyErfurt/ you should see an array structure like this one:

array (size=1)
    0 => 
        array (size=3)
            's' => string 'http://localhost/MyErfurt' (length=25)
            'p' => string 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' (length=47)
            'o' => string 'http://www.w3.org/2002/07/owl#Ontology' (length=38)

What we have done

Your MyErfurt folder contains the following items:

  • MyErfurt/Erfurt - Symbolic link or raw folder
  • MyErfurt/Zend - Symbolic link or raw folder
  • MyErfurt/index.php - instantiate and query etc.

And you should have created and maybe changed the following file

  • MyErfurt/Erfurt/Erfurt/config.ini - DBS Access data

What's next

Next, you'd want to try consuming Linked Data.

See an Example application, consuming FOAF profiles, for instance.