Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ resources/bootstrap/
resources/jquery/
xodx.log
config.ini

.idea/
*.iml
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# vim: set ai ts=4 sw=4 et!:

# Set Zend and bootstrap version
ZENDVERSION=1.12.0
ZENDVERSION=1.12.17
TWBSVERSION=2.3.2

TW_BOOTSTRAP_SRC='http://getbootstrap.com/${TWBSVERSION}/assets/bootstrap.zip'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Because this software is written in PHP you'll need php (>= 5.3.7) with the bind
Take the prepared `config.ini-dist` file, copy it to `config.ini` and configure it according to your system setup.
If you have an OntoWiki runnnig you can copy the database connection section (`store.*`) into the `config.ini` of xodx.
To import the initial base ontology for Erfurt you have to allow virtuoso to read the xodx directory.
You can configure this by adding the directory to `DirsAllowed` in your `virtuoso.ini` (on debian systems you can find it at `/etc/virtuoso-opensource-6.1/virtuoso.ini`).
You can configure this by adding the directory to `DirsAllowed` in your `virtuoso.ini` (on debian systems you can find it at `/etc/virtuoso-opensource-6.1/virtuoso.ini`, if you are using the debian packages; or `/var/lib/virtuoso/db/virtuoso.ini`, if you are using the lod2 package or if you have build virtuoso from the source).

### Erfurt, lib-dssn and Saft
Run `make submodules` to clone Erfurt, lib-dssn-php and Saft.
Expand Down
8 changes: 4 additions & 4 deletions classes/Xodx/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function addActivity ($actorUri, $verbUri, $object)
$subscribeFeeds[$activityUri] = $activityFeedUri;

// II. general statements of object resource
// if $type == 'Uri' the ressource of aair:activityObject statement allready exists
// if $type == 'Uri' the resource of aair:activityObject statement allready exists
// e.g. 'Sharing a Bookmark (URI)' and 'Friending'
if ($type != 'Uri') {
$objectFeedUri = $baseUri . '?c=feed&a=getFeed&uri=' . urlencode($objectUri);
Expand Down Expand Up @@ -458,7 +458,7 @@ public function getActivities ($resourceUri)
return null;
}

// get Type of Ressource and go on
// get Type of resource and go on
$resourceController = $this->_app->getController('Xodx_ResourceController');
$type = $resourceController->getType($resourceUri);

Expand Down Expand Up @@ -548,8 +548,8 @@ public function getActivities ($resourceUri)
if (!empty($objectResult[0]['content'])) {
$activity['objectContent'] = $objectResult[0]['content'];
}
if (!empty($objectResult[0]['image'])) {
$activity['objectImage'] = $objectResult[0]['image'];
if (!empty($objectResult[0]['image'])) {
$activity['objectImage'] = $objectResult[0]['image'];
}
// set data from activity to get valid feed
} else {
Expand Down
11 changes: 9 additions & 2 deletions classes/Xodx/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,16 @@ public function rdfAction ($template)
$model = $bootstrap->getResource('model');
$request = $bootstrap->getResource('request');

$objectId = $request->getValue('id', 'get');

$personUri = $request->getValue('uri', 'get');
$id = $request->getValue('id', 'get');
$controller = $request->getValue('c', 'get');
$personUri = $this->_app->getBaseUri() . '?c=' . $controller . '&id=' . $objectId;

// get URI
if ($id !== null) {
$personUri = $this->_app->getBaseUri() . '?c=' . $controller . '&id=' . $id;
}

$documentUri = new Saft_Url($request);

$mimetypeHelper = $this->_app->getHelper('Saft_Helper_MimetypeHelper');
Expand Down
8 changes: 4 additions & 4 deletions classes/Xodx/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public function imgAction ($template)

/**
*
* get the type of a ressource
* @param $resourceUri a URI of a ressource
* get the type of a resource
* @param $resourceUri a URI of a resource
*/
public function getType ($resourceUri)
{
Expand All @@ -191,9 +191,9 @@ public function getType ($resourceUri)

/**
*
* methods looks up a ressource to get the Uri of the activity feed
* methods looks up a resource to get the Uri of the activity feed
* and returns it if succesfull
* @param $resourceUri - the URI of the ressource to be looked up
* @param $resourceUri - the URI of the resource to be looked up
*/
public function getActivityFeedUri($resourceUri)
{
Expand Down
208 changes: 208 additions & 0 deletions classes/Xodx/StatController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<?php
/**
* This file is part of the {@link https://github.com/DSSN-Practical DSSN-Practical} student project.
*
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/


/**
* This class provides several functions to generate a node statistic for xodx
*
*/
class Xodx_StatController extends Saft_Controller
{

/**
* Function to request a turtle representation of all currently available Observations
* @return string
*/
public function getStatsAction ($template, $id = null, $time = null){
//re-download xodx, add statcontroller
//setting up time and user
$bootstrap = $this->_app->getBootstrap();
$request = $bootstrap->getResource('request');
$time = $request->getValue('time');
$user = $this->_app->getBaseUri().'?c=user&id='.urldecode($request->getValue('id'));
$person = $this->_app->getBaseUri().'?c=person&id='.urldecode($request->getValue('id'));

//initiate observationString
$observationString = "";

// - followers
$dataset = "xo:dataset-xofollowers";
$measureProperty = "xo:followers";

//!!!!!
//IMPORTANT! Assuming: FOLLOWED FEEDS OF PERSONS = PERSONS THAT FOLLOW THE USER!
//!!!!!
$value = $this->getFollowedfeeds($user,$person);
$observationString .= $this->buildObservation(
$this->getObsId($time),
$dataset,
$user,
$measureProperty,
$time,
$value);
// get messages sent
$dataset = "xo:dataset-xoOUT";
$measureProperty = "xo:outgoingMessages";
$value = $this->getSentMessages($person);
$observationString .= $this->buildObservation(
$this->getObsId($time),
$dataset,
$user,
$measureProperty,
$time,
$value);
// get messages received
$dataset = "xo:dataset-xoIN";
$measureProperty = "xo:receivedMessages";
$value = $this->getReceivedMessages($person);
$observationString .= $this->buildObservation(
$this->getObsId($time),
$dataset,
$user,
$measureProperty,
$time,
$value);
// get stored triples
$dataset = "xo:dataset-xoTriples";
$measureProperty = "xo:triples";
$value = $this->getTriples();
$observationString .= $this->buildObservation(
$this->getObsId($time),
$dataset,
$user,
$measureProperty,
$time,
$value);
// get Access Time in microseconds
$dataset = "xo:dataset-xoAccess";
$measureProperty = "xo:Access";
$value = $this->getAccessTime($user);
$observationString .= $this->buildObservation(
$this->getObsId($time),
$dataset,
$user,
$measureProperty,
$time,
$value);
$template->disableLayout();
$template->setRawContent($observationString);

return $template;
}

private function getFollowedfeeds($user,$person){
$bootstrap = $this->_app->getBootstrap();
$model = $bootstrap->getResource('model');
// SPARQL-Query
$query = 'SELECT COUNT(?friendperson) WHERE {';
$query .= ' <'.$user.'> <http://purl.org/net/dssn/subscribedTo> ?resource.';
$query .= ' ?resource <http://purl.org/net/dssn/subscriptionTopic> ?feed.';
$query .= ' ?friendperson <http://purl.org/net/dssn/activityFeed> ?feed.';
$query .= ' <'.$person.'> <http://xmlns.com/foaf/0.1/knows> ?friendperson';
$query .= '} GROUP BY ?friendperson';

$resultset = $model->sparqlQuery($query);
$countResult = $resultset[0]['callret-0'];
return ($countResult?$countResult:0);

}

private function getSentMessages($person){
$bootstrap = $this->_app->getBootstrap();
$model = $bootstrap->getResource('model');
// SPARQL-Query
$query = 'SELECT COUNT(*) WHERE {';
$query .= ' ?x a <http://rdfs.org/sioc/ns#Post>.';
$query .= ' ?x <http://xmlns.com/foaf/0.1/maker> <'.$person.'>';
$query .= '}';

$resultset = $model->sparqlQuery($query);
$countResult = $resultset[0]['callret-0'];

return ($countResult?$countResult:0);

}
private function getReceivedMessages($person){

$bootstrap = $this->_app->getBootstrap();
$model = $bootstrap->getResource('model');
// SPARQL-Query
$query = 'SELECT COUNT(*) WHERE {';
$query .= ' ?x a <http://rdfs.org/sioc/ns#Post>.';
$query .= ' ?x <http://xmlns.com/foaf/0.1/maker> ?maker.';
$query .= ' <'.$person.'> <http://xmlns.com/foaf/0.1/knows> ?maker';
$query .= '}';

$resultset = $model->sparqlQuery($query);
$countResult = $resultset[0]['callret-0'];

return ($countResult?$countResult:0);
}
private function getTriples(){
$bootstrap = $this->_app->getBootstrap();
$model = $bootstrap->getResource('model');
$query = 'SELECT COUNT(*) WHERE {?s ?p ?o}';

$resultset = $model->sparqlQuery($query);
$triples = $resultset[0]['callret-0'];
return $triples;
}


public function readStoreAction($template){
$bootstrap = $this->_app->getBootstrap();
$model = $bootstrap->getResource('model');
$query = 'SELECT * WHERE {?s ?p ?o}';
$resultset = $model->sparqlQuery($query);

echo "<table><tr><th>Subject</th><th>Predicate</th><th>Object</th></tr>";
foreach($resultset as $line){
echo "<tr>";
foreach($line as $value){
echo "<td>{$value}</td>";
}
echo "<tr>";
}
echo "</table>";
}

private function getObsId($x){
return 'xo:observation-'.$x.'-'.md5(rand());
}

private function getAccessTime($user){
$starttime = microtime(true);

$client = new Zend_Http_Client();
$client->setUri($this->_app->getBaseUri());
$client->setParameterGet(array(
'c' => 'feed',
'a' => 'getFeed',
'uri' => $user,
));
$response = $client->request();
$feed = $response->getBody();

$endtime = microtime(true);
return $endtime - $starttime;
}

/**
* function to generate turtle code for the observation part of the datacube
*/
private function buildObservation($id,$dataset,$user,$measureProperty,$time,$value){
$observationString = "";
$observationString .= $id." a qb:Observation;".PHP_EOL;
$observationString .= "qb:dataSet ".$dataset.";".PHP_EOL;
$observationString .= "xo:refAgent <".$user.">;".PHP_EOL;
$observationString .= "xo:refTime ".$time.";".PHP_EOL;
$observationString .= $measureProperty." ".$value.";".PHP_EOL;
$observationString .= ".".PHP_EOL;
return $observationString;
}

}
2 changes: 1 addition & 1 deletion classes/Xodx/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private function _subscribeToFeed ($subscriberUri, $feedUri, $local = false)
$nsDssn = 'http://purl.org/net/dssn/';
$nsRdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';

$subUri = $this->_app->getBaseUri() . '&c=ressource&id=' . md5(rand());
$subUri = $this->_app->getBaseUri() . '&c=resource&id=' . md5(rand());
$cbUri = $this->_app->getBaseUri() . '?c=push&a=callback';

$subscription = array(
Expand Down