-
Notifications
You must be signed in to change notification settings - Fork 1
Scripting
<?php
// Composer autoload
// assuming we are in the SameAsLite webroot. Adjust the path, if necessary.
require_once 'vendor/autoload.php';
// Init the store
// if using a MySQL store:
/*
$options = [
'username' => 'testuser',
'password' => 'testpass',
'dbName' => 'teststore',
'host' => 'localhost',
'port' => '3306',
'charset' => 'utf8',
];
// Note: the store 'teststore' will be created if it does not exist
$store = new \SameAsLite\Store\MySQLStore('teststore', $options);
*/
// if using a SQLLite store:
$options = [
'location' => './db/sameaslite-store.db', // adjust this to your SQLite db location
];
// Note: the store 'teststore' will be created if it does not exist
$store = new \SameAsLite\Store\SQLiteStore('teststore', $options);
// connect to the store
$store->connect();
// check if we are connected
if (!$store->isConnected()) {
die("Something went wrong with connecting to the DB.
Check permissions, db location, store config, etc.");
}
// do some queries - see the available methods in SQLiteStore.php
print PHP_EOL . "Querying some stuff out of the store: " . $store->getStoreName() . PHP_EOL;
print "-----------".PHP_EOL;
var_dump($store->querySymbol('Frankfurt'));
// or if you've added resource URIs instead of literals to your store:
var_dump($store->querySymbol('http://dbpedia.org/resource/Frankfurt'));
// disconnect from db
$store->disconnect();
?>
The output could look like this (if using SameAs-Lite with literal values):
Querying some stuff out of the store: teststore
-----------
array(7) {
[0] =>
string(3) "FFM"
[1] =>
string(8) "Franfurt"
[2] =>
string(9) "Frankfurt"
[3] =>
string(15) "Frankfurt a. M."
[4] =>
string(17) "Frankfurt am Main"
}
$store->assertPair('crisps', 'potato chips'); Create a relationship
$store->querySymbol('crisps'); Looks up all equivilent symbols. Returns ['crisps', 'potato chips']
$store->getCanon('potato chips'); Gets the canon for the symbol. Canons are created when a pair is asserted and neither of the symbols are in the store, and the first symbol is used as the canon. Returns 'crisps'
$store->removeSymbol('potato chips'); Removes that symbol from the store.
These stores can be used by themselves and accessed directly. However sameAs Lite also comes with a WebApp that can be used to provide a RESTful API and HTML interface to interact with the store. The WebApp uses Slim for routing.
To use the WebApp create a new \SameAsLite\WebApp object, passing in an array of options.
"Options described here" Stores can then be added to the app using the addDataset function:
$app->addDataset($store); Finally, run the app using run().
$app->run(); A full example can be found in examples/manual.php
All Stores bundled with sameAs Lite are in the \SameAsLite\Store namespace and all take a name for the store and an array of options. For MySQL these options are:
[ 'username' => , 'password' => , 'dbName' => <string, default=sameAsLite>, 'host' => , 'port' => <int, optional>, 'charset' => <string, optional> ] TODO: Needs some more help here, so that it works better out of the box (such as username/password).
For other Store options please see the documentation.
- SameAs-Lite
- Concepts
- Server Requirements
- Installation & Configuration
- [Data Stores](Data Stores)
- Usage
- Contributing to SameAs-Lite
- [Setting up a development environment](Setting up a development environment)
- [Coding Standards](Coding Standards)
- [Day-to-Day Development](Day-to-Day Development)
- [Open Source Governance](Open Source Governance)
- Support
- [Getting In Touch](Getting In Touch)
- [Legal Information](Legal Information)