コード例 #1
0
ファイル: SimpleQueryTest.php プロジェクト: FTeichmann/Erfurt
 public function testSetWithMethodsAsk()
 {
     $queryString = '
         ASK
         WHERE {
             ?comment <http://rdfs.org/sioc/ns#about> ?resource.
             ?comment a <http://rdfs.org/sioc/types#Comment>.
             ?comment <http://rdfs.org/sioc/ns#has_creator> ?author.
             ?comment <http://rdfs.org/sioc/ns#content> ?content.
             ?comment <http://purl.org/dc/terms/created> ?date.
         }
         ORDER BY DESC(?date)
         LIMIT 6';
     $queryObject = new Erfurt_Sparql_SimpleQuery();
     $queryObject->setAsk();
     $queryObject->setWherePart('WHERE {
             ?comment <http://rdfs.org/sioc/ns#about> ?resource.
             ?comment a <http://rdfs.org/sioc/types#Comment>.
             ?comment <http://rdfs.org/sioc/ns#has_creator> ?author.
             ?comment <http://rdfs.org/sioc/ns#content> ?content.
             ?comment <http://purl.org/dc/terms/created> ?date.
         }');
     $queryObject->setOrderClause('DESC(?date)');
     $queryObject->setLimit(6);
     $this->assertQueryEquals($queryString, (string) $queryObject);
     $this->assertEquals(true, $queryObject->isAsk());
     $this->assertEquals(null, $queryObject->getSelectClause());
 }
コード例 #2
0
ファイル: RdfJson.php プロジェクト: FTeichmann/Erfurt
 public function serializeGraphToString($graphUri, $pretty = false, $useAc = true)
 {
     $triples = array();
     $store = Erfurt_App::getInstance()->getStore();
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $sparql = new Erfurt_Sparql_SimpleQuery();
     $sparql->setProloguePart('SELECT ?s ?p ?o');
     $sparql->addFrom($graphUri);
     $sparql->setWherePart('WHERE { ?s ?p ?o }');
     $sparql->setOrderClause('?s ?p ?o');
     $sparql->setLimit(1000);
     $offset = 0;
     while (true) {
         $sparql->setOffset($offset);
         $result = $store->sparqlQuery($sparql, array('result_format' => 'extended', 'use_owl_imports' => false, 'use_additional_imports' => false, 'use_ac' => $useAc));
         $counter = 0;
         foreach ($result['results']['bindings'] as $stm) {
             $s = $stm['s']['value'];
             $p = $stm['p']['value'];
             $o = $stm['o'];
             if (!isset($triples["{$s}"])) {
                 $triples["{$s}"] = array();
             }
             if (!isset($triples["{$s}"]["{$p}"])) {
                 $triples["{$s}"]["{$p}"] = array();
             }
             if ($o['type'] === 'typed-literal') {
                 $triples["{$s}"]["{$p}"][] = array('type' => 'literal', 'value' => $o['value'], 'datatype' => $o['datatype']);
             } else {
                 if ($o['type'] === 'typed-literal') {
                     $oArray = array('type' => 'literal', 'value' => $o['value']);
                     if (isset($o['xml:lang'])) {
                         $oArray['lang'] = $o['xml:lang'];
                     }
                     $triples["{$s}"]["{$p}"][] = $oArray;
                 } else {
                     $triples["{$s}"]["{$p}"][] = array('type' => $o['type'], 'value' => $o['value']);
                 }
             }
             $counter++;
         }
         if ($counter < 1000) {
             break;
         }
         $offset += 1000;
     }
     return json_encode($triples);
 }
コード例 #3
0
 public function onPropertiesActionTemplate($event)
 {
     $store = Erfurt_App::getInstance()->getStore();
     $config = Erfurt_App::getInstance()->getConfig();
     $model = $event->model;
     $graph = $event->graph;
     $resource = $event->resource;
     $predicates = $model->getPredicates();
     $description = $resource->getDescription();
     if ($this->_privateConfig->template->restrictive) {
         foreach ($description as $resource) {
             if (isset($resource[EF_RDF_TYPE])) {
                 $type = $resource[EF_RDF_TYPE][0]['value'];
             } else {
                 return false;
             }
         }
         $query = new Erfurt_Sparql_SimpleQuery();
         $query->setProloguePart('PREFIX erm: <http://vocab.ub.uni-leipzig.de/bibrm/> SELECT DISTINCT ?uri');
         $query->addFrom((string) $event->graph);
         $query->setWherePart('{?template a <' . $this->_template . '> .
                                 ?template erm:providesProperty ?uri .
                                 ?template erm:bindsClass <' . $type . '> .
                             } ');
         $query->setLimit('20');
         $result = $store->sparqlQuery($query);
     }
     if (!empty($result)) {
         // flatten Array and flip keys with values to use array_intersect_key
         $result = array_map(function ($x) {
             return array_flip($x);
         }, $result);
         // FIXME Find a method to add standard properties which will be
         // displayed by default
         $result[] = array(EF_RDF_TYPE => "bla");
         $result[] = array(EF_RDFS_LABEL => "bla");
         $newResult = array();
         foreach ($result as $newKey => $newValue) {
             $newResult = array_merge($newResult, $newValue);
         }
         $matched = array_intersect_key($predicates[(string) $graph], $newResult);
         $matched = array((string) $graph => $matched);
         $event->predicates = $matched;
     } else {
         return false;
     }
     return true;
 }
コード例 #4
0
ファイル: Store.php プロジェクト: FTeichmann/Erfurt
 /**
  * Get the configuration for a graph.
  * @param string $graphUri to specity the graph
  * @return array
  */
 public function getGraphConfiguration($graphUri)
 {
     if (null === $this->_graphConfigurations) {
         $sysOntModelUri = $this->getOption('modelUri');
         // Fetch the graph configurations
         $queryObject = new Erfurt_Sparql_SimpleQuery();
         $queryObject->setProloguePart('SELECT ?s ?p ?o');
         $queryObject->setFrom(array($sysOntModelUri));
         $queryObject->setWherePart('WHERE { ?s ?p ?o . ?s a <http://ns.ontowiki.net/SysOnt/Model> }');
         $queryoptions = array('use_ac' => false, 'result_format' => Erfurt_Store::RESULTFORMAT_EXTENDED, 'use_additional_imports' => false);
         $stmtArray = array();
         if ($result = $this->sparqlQuery($queryObject, $queryoptions)) {
             $result = $result['results'];
             foreach ($result['bindings'] as $row) {
                 if (!isset($stmtArray[$row['s']['value']])) {
                     $stmtArray[$row['s']['value']] = array();
                 }
                 if (!isset($stmtArray[$row['s']['value']][$row['p']['value']])) {
                     $stmtArray[$row['s']['value']][$row['p']['value']] = array();
                 }
                 if ($row['o']['type'] === 'typed-literal') {
                     $row['o']['type'] = 'literal';
                 }
                 if (isset($row['o']['xml:lang'])) {
                     $row['o']['lang'] = $row['o']['xml:lang'];
                     unset($row['o']['xml:lang']);
                 }
                 $stmtArray[$row['s']['value']][$row['p']['value']][] = $row['o'];
             }
         }
         $this->_graphConfigurations = $stmtArray;
     }
     if (isset($this->_graphConfigurations[$graphUri])) {
         return $this->_graphConfigurations[$graphUri];
     }
     return array();
 }
コード例 #5
0
ファイル: Turtle.php プロジェクト: FTeichmann/Erfurt
 public function serializeResourceToString($resource, $graphUri, $pretty = false, $useAc = true, array $additional = array())
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?resourceUri ?p ?o');
     $query->addFrom($graphUri);
     /*
      * Why not as subject?
      * Because serializeQueryResultToString() expects ?resourceUri to be bound.
      */
     $query->setWherePart('WHERE { ?resourceUri ?p ?o . FILTER (sameTerm(?resourceUri, <' . $resource . '>))}');
     $query->setOrderClause('?resourceUri ?p ?o');
     return $this->serializeQueryResultToString($query, $graphUri, $pretty, $useAc);
 }
コード例 #6
0
 /**
  * Deletes one or more resources denoted by param 'r'
  * TODO: This should be done by a evolution pattern in the future
  */
 public function deleteAction()
 {
     $this->view->clearModuleCache();
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     $store = $this->_erfurt->getStore();
     $model = $this->_owApp->selectedModel;
     $modelIri = (string) $model;
     $redirect = $this->_request->getParam('redirect', $this->_config->urlBase);
     if (isset($this->_request->r)) {
         $resources = $this->_request->getParam('r', array());
     } else {
         throw new OntoWiki_Exception('Missing parameter r!');
     }
     if (!is_array($resources)) {
         $resources = array($resources);
     }
     // get versioning
     $versioning = $this->_erfurt->getVersioning();
     $count = 0;
     if ($this->_erfurt->getAc()->isModelAllowed('edit', $modelIri)) {
         foreach ($resources as $resource) {
             // if we have only a nice uri, fill to full uri
             if (Zend_Uri::check($resource) == false) {
                 // check for namespace
                 if (strstr($resource, ':')) {
                     $resource = OntoWiki_Utils::expandNamespace($resource);
                 } else {
                     $resource = $model->getBaseIri() . $resource;
                 }
             }
             // action spec for versioning
             $actionSpec = array();
             $actionSpec['type'] = 130;
             $actionSpec['modeluri'] = $modelIri;
             $actionSpec['resourceuri'] = $resource;
             // starting action
             $versioning->startAction($actionSpec);
             $stmtArray = array();
             // query for all triples to delete them
             $sparqlQuery = new Erfurt_Sparql_SimpleQuery();
             $sparqlQuery->setProloguePart('SELECT ?p, ?o');
             $sparqlQuery->addFrom($modelIri);
             $sparqlQuery->setWherePart('{ <' . $resource . '> ?p ?o . }');
             $result = $store->sparqlQuery($sparqlQuery, array('result_format' => 'extended'));
             // transform them to statement array to be compatible with store methods
             foreach ($result['results']['bindings'] as $stmt) {
                 $stmtArray[$resource][$stmt['p']['value']][] = $stmt['o'];
             }
             $store->deleteMultipleStatements($modelIri, $stmtArray);
             // stopping action
             $versioning->endAction();
             $count++;
         }
         $message = $count . ' resource' . ($count != 1 ? 's' : '') . ($count ? ' successfully' : '') . ' deleted.';
         $this->_owApp->appendMessage(new OntoWiki_Message($message, OntoWiki_Message::SUCCESS));
     } else {
         $message = 'not allowed.';
         $this->_owApp->appendMessage(new OntoWiki_Message($message, OntoWiki_Message::WARNING));
     }
     $event = new Erfurt_Event('onDeleteResources');
     $event->resourceArray = $resources;
     $event->modelUri = $modelIri;
     $event->trigger();
     $this->_redirect($redirect, array('code' => 302));
 }
コード例 #7
0
ファイル: FoafSsl.php プロジェクト: FTeichmann/Erfurt
 /**
  * Checks the local database, whether user exists
  */
 protected function _checkWebId($webId)
 {
     $retVal = array('userUri' => false, 'denyLogin' => false);
     // Query the store.
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?s ?p ?o');
     $query->addFrom($this->_acModelUri);
     $where = 'WHERE { 
                         ?s ?p ?o . 
                         ?s <' . EF_RDF_TYPE . '> <' . $this->_uris['user_class'] . "> .\n                            FILTER (sameTerm(?s, <{$webId}>))\n                        }";
     $query->setWherePart($where);
     $result = $this->_store->sparqlQuery($query, array('use_ac' => false));
     foreach ((array) $result as $row) {
         // Set user URI
         if ($retVal['userUri'] === false) {
             $retVal['userUri'] = $row['s'];
         }
         // Check predicates, whether needed.
         switch ($row['p']) {
             case $this->_uris['action_deny']:
                 // if login is disallowed
                 if ($row['o'] === $this->_uris['action_login']) {
                     $retVal['denyLogin'] = true;
                 }
                 break;
             case EF_RDFS_LABEL:
                 $retVal['userLabel'] = $row['o'];
                 break;
             case $this->_uris['user_username']:
                 $retVal['username'] = $row['o'];
                 break;
             case $this->_uris['user_mail']:
                 $retVal['email'] = $row['o'];
             default:
                 // Ignore all other statements.
         }
     }
     return $retVal;
 }
コード例 #8
0
 /**
  * Returns all existing sync configurations.
  *
  * @return array|bool
  */
 private function _listSyncConfigs()
 {
     if (null === $this->_syncConfigListCache) {
         $store = Erfurt_App::getInstance()->getStore();
         require_once 'Erfurt/Sparql/SimpleQuery.php';
         $query = new Erfurt_Sparql_SimpleQuery();
         $query->setProloguePart('SELECT ?s ?p ?o');
         $query->addFrom($this->_syncModelUri);
         $where = 'WHERE {
             ?s ?p ?o .
             ?s <' . EF_RDF_TYPE . '> <' . $this->_properties['syncConfigClass'] . '> . }';
         $query->setWherePart($where);
         $result = $store->sparqlQuery($query, array('use_ac' => false));
         if (count($result) === 0) {
             return false;
         }
         $retVal = array();
         foreach ($result as $row) {
             if (!isset($retVal[$row['s']])) {
                 $retVal[$row['s']] = array('uri' => $row['s']);
             }
             switch ($row['p']) {
                 case $this->_properties['targetModel']:
                     $retVal[$row['s']]['targetModel'] = $row['o'];
                     break;
                 case $this->_properties['syncResource']:
                     $retVal[$row['s']]['syncResource'] = $row['o'];
                     break;
                 case $this->_properties['wrapperName']:
                     $retVal[$row['s']]['wrapperName'] = $row['o'];
                     break;
                 case $this->_properties['lastSyncPayload']:
                     $retVal[$row['s']]['lastSyncPayload'] = unserialize($row['o']);
                     break;
                 case $this->_properties['lastSyncDateTime']:
                     $retVal[$row['s']]['lastSyncDateTime'] = $row['o'];
                     break;
                 case $this->_properties['syncQuery']:
                     $retVal[$row['s']]['syncQuery'] = $row['o'];
                     break;
                 case $this->_properties['checkHasChanged']:
                     $retVal[$row['s']]['checkHasChanged'] = (bool) $row['o'];
                     break;
             }
         }
         $cacheVal = array();
         foreach ($retVal as $s => $valueArray) {
             $hash = $this->_getHash($valueArray['syncResource'], $valueArray['wrapperName'], $valueArray['targetModel']);
             $cacheVal[$hash] = $valueArray;
         }
         $this->_syncConfigListCache = $cacheVal;
     }
     return $this->_syncConfigListCache;
 }
コード例 #9
0
 /**
  * Searches for properties in the local database.
  *
  * @param array  $termsArray
  * @param string $modelUri
  * @param int    $limit
  *
  * @return array
  */
 private function _searchLocalPropertiesOnly(array $termsArray, $modelUri, $limit)
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT DISTINCT ?uri ?o');
     if (null !== $modelUri) {
         $query->addFrom($modelUri);
     }
     $where = '{ { ?uri ?p ?o . ?uri <' . EF_RDF_TYPE . '> ?o2 .
         FILTER (
             sameTerm(?o2, <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#DatatypeProperty>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#ObjectProperty>)
         )
         FILTER ((';
     $uriRegexFilter = array();
     foreach ($termsArray as $t) {
         $uriRegexFilter[] = 'regex(str(?uri), "' . $t . '", "i")';
     }
     $where .= implode(' && ', $uriRegexFilter) . ') || (isLiteral(?o) && ';
     $oRegexFilter = array();
     foreach ($termsArray as $t) {
         $oRegexFilter[] = 'regex(?o, "' . $t . '", "i")';
     }
     $where .= implode(' && ', $oRegexFilter) . ')) } UNION {';
     $where .= '?s ?uri ?o .
               FILTER (';
     $where .= implode(' && ', $uriRegexFilter) . ') } }';
     $query->setWherePart($where);
     $query->setOrderClause('?uri');
     $query->setLimit($limit);
     $store = Erfurt_App::getInstance()->getStore();
     $queryResult = $store->sparqlQuery($query, array('result_format' => 'extended'));
     $tempResult = array();
     foreach ($queryResult['results']['bindings'] as $row) {
         if ($row['o']['type'] === 'literal') {
             $weight = $this->_getWeight($termsArray, $row['uri']['value'], $row['o']['value']);
         } else {
             $weight = $this->_getWeight($termsArray, $row['uri']['value']);
         }
         if (isset($tempResult[$row['uri']['value']])) {
             if ($weight > $tempResult[$row['uri']['value']]) {
                 $tempResult[$row['uri']['value']] = $weight;
             }
         } else {
             $tempResult[$row['uri']['value']] = $weight;
         }
     }
     arsort($tempResult);
     require_once 'OntoWiki/Model/TitleHelper.php';
     require_once 'OntoWiki/Utils.php';
     if (null !== $modelUri) {
         $model = $store->getModel($modelUri, false);
         $titleHelper = new OntoWiki_Model_TitleHelper($model);
     } else {
         $titleHelper = new OntoWiki_Model_TitleHelper();
     }
     $titleHelper->addResources(array_keys($tempResult));
     $translate = $this->_owApp->translate;
     $result = array();
     foreach ($tempResult as $uri => $w) {
         $title = $titleHelper->getTitle($uri);
         if (null !== $title) {
             $result[$uri] = str_replace('|', '&Iota;', $title) . '|' . $uri . '|' . $translate->_('Local Search');
         } else {
             $result[$uri] = OntoWiki_Utils::compactUri($uri) . $uri . '|' . $translate->_('Local Search');
         }
     }
     return $result;
 }
コード例 #10
0
ファイル: Query.php プロジェクト: eschwert/cubeviz.ontowiki
 /**
  * Get all observations which fits to given DSD, DS and selected compontents.
  * @param $dataSetUrl URL of a data set
  * @param $selectedComponentDimensions
  */
 public function getObservations($dataSetUrl, $selectedComponentDimensions = array())
 {
     // generate unique hash using given result and model uri
     $objectId = md5($this->_model->getModelIri() . $dataSetUrl . json_encode($selectedComponentDimensions));
     // check there is already a cached object for this hash
     $result = $this->_objectCache->load($objectId);
     if (false === $result) {
         $this->_queryCache->startTransaction($objectId);
         /**
          * Fill SimpleQuery object with live!
          */
         $queryObject = new Erfurt_Sparql_SimpleQuery();
         // SELECT
         $queryObject->setProloguePart('SELECT ?s ?p ?o');
         // FROM
         $queryObject->setFrom(array($this->_model->getModelIri()));
         // WHERE
         $where = 'WHERE { ' . "\n" . '
             ?s ?p ?o .' . "\n" . '
             ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <' . DataCube_UriOf::Observation . '> .' . "\n" . '
             ?s <' . DataCube_UriOf::DataSetRelation . '> <' . $dataSetUrl . '> .' . "\n";
         // Set selected properties (e.g. ?s <http://data.lod2.eu/scoreboard/properties/year> ?d0 .)
         $i = 0;
         foreach ($selectedComponentDimensions as $dimension) {
             if (0 < count($dimension['__cv_elements'])) {
                 $where .= ' ?s <' . $dimension[DataCube_UriOf::Dimension] . '> ?d' . $i++ . ' .' . "\n";
             }
         }
         // Set FILTER
         // e.g.: FILTER (?d1 = "2003" OR ?d1 = "2001" OR ?d1 = "2002")
         // e.g. 2: FILTER ( ?d0 = <http://data.lod2.eu/scoreboard/indicators/bb_fcov_RURAL_POP__pop> OR
         //                  ?d0 = <http://data.lod2.eu/scoreboard/indicators/bb_lines_TOTAL_FBB_nbr_lines> )
         $i = 0;
         foreach ($selectedComponentDimensions as $dimension) {
             $dimensionElements = $dimension['__cv_elements'];
             if (0 < count($dimensionElements)) {
                 $filter = array();
                 foreach ($dimensionElements as $elementUri => $element) {
                     // If __cv_uri is set and an URL
                     if (true == Erfurt_Uri::check($element['__cv_uri'])) {
                         $value = '<' . $element['__cv_uri'] . '>';
                         $filter[] = ' ?d' . $i . ' = ' . $value . ' ';
                     } else {
                         $value = '"' . $element['__cv_niceLabel'] . '"';
                         $filter[] = ' xsd:string(?d' . $i . ') = xsd:string(' . $value . ') ';
                     }
                 }
                 $i++;
                 $where .= ' FILTER (' . implode('OR', $filter) . ') ' . "\n";
             }
         }
         $where .= '}';
         $queryObject->setWherePart($where);
         $result = $this->_model->sparqlQuery((string) $queryObject);
         // generate associative array out of given observation result
         $result = $this->generateAssocSPOArrayFromSparqlResult($result, 's', 'p', 'o');
         // limit the number of observations
         $result = array_slice($result, 0, 250);
         // enrich data with CubeViz sugar
         $result = $this->enrichResult($result, false);
         // close the object cache transaction
         $this->_queryCache->endTransaction($objectId);
         // save the result value in the object cache
         $this->_objectCache->save($result, $objectId);
     }
     return $result;
 }
コード例 #11
0
 protected function _buildQuery()
 {
     $query = new Erfurt_Sparql_SimpleQuery();
     $prologue = 'SELECT DISTINCT ?classUri ?sub ?subsub ?subsubsub';
     $query->setProloguePart($prologue);
     $whereSpecs = array();
     $whereSpec = '';
     foreach ($this->_options['object_types'] as $type) {
         $whereSpecs[] = '{?classUri a <' . $type . '>}';
     }
     // optional inference
     if (!$this->_options['entry'] && $this->_inference) {
         // instance retrieval is only applicable for classes
         if ($this->_options['sub_relation'] == EF_RDFS_SUBCLASSOF) {
             $whereSpecs[] = '{?instance a ?classUri.}';
         }
         // entities with a subtype must be a type
         $whereSpecs[] = '{?subtype <' . $this->_options['sub_relation'] . '> ?classUri.}';
     }
     $whereSpec = implode(' UNION ', $whereSpecs);
     $whereSpec .= ' FILTER (isURI(?classUri))';
     // dont't show rdfs/owl entities and subtypes in the first level
     if (!$this->_options['entry']) {
         $whereSpec .= ' FILTER (regex(str(?super), "^' . EF_OWL_NS . '") || !bound(?super))';
     }
     $whereSpec .= ' OPTIONAL {?sub <' . $this->_options['sub_relation'] . '> ?classUri. 
                         OPTIONAL {?subsub <' . $this->_options['sub_relation'] . '> ?sub.
                               OPTIONAL {?subsubsub <' . $this->_options['sub_relation'] . '> ?subsub}
                         }
                     }';
     $whereSpec .= ' OPTIONAL {?classUri <' . $this->_options['sub_relation'] . '> ?super. FILTER(isUri(?super))}';
     // namespaces to be ignored, rdfs/owl-defined objects
     foreach ($this->_options['ignore_ns'] as $ignore) {
         $whereSpec .= ' FILTER (!regex(str(?classUri), "^' . $ignore . '"))';
     }
     // entry point into the class tree
     if ($this->_options['entry']) {
         $whereSpec .= ' FILTER (str(?super) = str(<' . $this->_options['entry'] . '>))';
     }
     $query->setWherePart('WHERE {' . $whereSpec . '}');
     return $query;
 }
コード例 #12
0
ファイル: Recovery.php プロジェクト: FTeichmann/Erfurt
 /**
  *
  */
 public function validateHash($hash)
 {
     $config = Erfurt_App::getInstance()->getConfig();
     $store = Erfurt_App::getInstance()->getStore();
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->addFrom($config->ac->modelUri);
     $query->setProloguePart('SELECT ?user');
     $query->setWherePart('{ ?user <' . $config->ac->user->recoveryHash . '> "' . $hash . '" . }');
     $resultUser = $store->sparqlQuery($query, array('use_ac' => false));
     if (!empty($resultUser)) {
         return $resultUser[0]['user'];
     } else {
         require_once 'Erfurt/Auth/Identity/Exception.php';
         throw new Erfurt_Auth_Identity_Exception('Invalid recovery session identifier.');
     }
 }
コード例 #13
0
 protected function getStoredConfigurationUris()
 {
     $dir = $this->_owApp->extensionManager->getExtensionPath('csvimport') . '/configs/';
     if (!is_dir($dir)) {
         return;
     }
     $configurations = array();
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file == "." || $file == '..') {
                 continue;
             }
             $handle = fopen($dir . $file, 'r');
             $contents = fread($handle, filesize($dir . $file));
             fclose($handle);
             $configurations[] = array('label' => str_replace('.cfg', '', str_replace('_', ' ', $file)), 'config' => $contents);
         }
         closedir($dh);
         return $configurations;
     }
     return array();
     return;
     $sysontUri = $this->_owApp->erfurt->getConfig()->sysont->modelUri;
     $sysOnt = $this->_owApp->erfurt->getStore()->getModel($sysontUri, false);
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart(' SELECT  ?configUri ?configLabel ?configuration');
     $query->setWherePart('  
                 WHERE { ?configUri a <' . $sysontUri . 'CSVImportConfig> .
                         ?configUri <http://www.w3.org/2000/01/rdf-schema#label> ?configLabel .
                         ?configUri <' . $sysontUri . 'CSVImportConfig/configuration> ?configuration} ');
     if ($result = $sysOnt->sparqlQuery($query)) {
         // var_dump($result); die;
         $configurations = array();
         foreach ($result as $entry) {
             //var_dump($entry['configuration']); die;
             $configurations[$entry['configUri']] = array('label' => $entry['configLabel'], 'config' => base64_decode($entry['configuration']));
         }
         //var_dump($configurations);
         return $configurations;
     }
     return array();
 }
コード例 #14
0
ファイル: RdfWriter.php プロジェクト: FTeichmann/Erfurt
 protected function _sparqlForListResources()
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?s ?first ?rest');
     $query->addFrom($this->_graphUri);
     $query->setWherePart('WHERE { ?s <' . EF_RDF_FIRST . '> ?first . ?s <' . EF_RDF_REST . '> ?rest }');
     $result = $this->_store->sparqlQuery($query, array('result_format' => 'extended', 'use_owl_imports' => false, 'use_additional_imports' => false));
     $listArray = array();
     if ($result) {
         foreach ($result['results']['bindings'] as $row) {
             $listArray[$row['s']['value']] = array('first' => $row['first']['value'], 'rest' => $row['rest']['value']);
         }
     }
     $this->_listArray = $listArray;
 }
コード例 #15
0
ファイル: Rdf.php プロジェクト: FTeichmann/Erfurt
 /**
  * Fetches the for all users from the RDF user store.
  * 
  * Stores the user data in an internal array for alter reference.
  *
  * @return void
  */
 public function fetchDataForAllUsers()
 {
     $uris = $this->_getUris();
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $userSparql = new Erfurt_Sparql_SimpleQuery();
     $userSparql->setProloguePart('SELECT ?subject ?predicate ?object');
     $wherePart = 'WHERE { ?subject ?predicate ?object . ?subject <' . EF_RDF_TYPE . '> <' . $uris['user_class'] . '> }';
     $userSparql->setWherePart($wherePart);
     if ($result = $this->_sparql($userSparql)) {
         foreach ($result as $statement) {
             switch ($statement['predicate']) {
                 case $uris['action_deny']:
                     if ($statement['object'] == $uris['action_login']) {
                         $this->_users[$statement['subject']]['loginForbidden'] = true;
                     }
                     break;
                 case $uris['user_username']:
                     // save username
                     $this->_users[$statement['subject']]['userName'] = $statement['object'];
                     break;
                 case $uris['user_password']:
                     // save password
                     $this->_users[$statement['subject']]['userPassword'] = $statement['object'];
                     break;
                 case $uris['user_mail']:
                     // save e-mail
                     $this->_users[$statement['subject']]['userEmail'] = $statement['object'];
                     break;
                 default:
                     // ignore other statements
             }
         }
         $this->_userDataFetched = true;
     }
 }
コード例 #16
0
ファイル: RdfXml.php プロジェクト: FTeichmann/Erfurt
 protected function _serializeResource($resource, $useAc = true, $level = 0)
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?s ?p ?o');
     $query->addFrom($this->_graphUri);
     $query->setWherePart('WHERE { ?s ?p ?o . FILTER (sameTerm(?s, <' . $resource . '>))}');
     $query->setOrderClause('?s ?p ?o');
     $query->setLimit(1000);
     $offset = 0;
     $bnObjects = array();
     while (true) {
         $query->setOffset($offset);
         $result = $this->_store->sparqlQuery($query, array('result_format' => 'extended', 'use_owl_imports' => false, 'use_additional_imports' => false, 'use_ac' => $useAc));
         foreach ($result['results']['bindings'] as $row) {
             $s = $row['s']['value'];
             $p = $row['p']['value'];
             $o = $row['o']['value'];
             $sType = $row['s']['type'];
             $oType = $row['o']['type'];
             $lang = isset($row['o']['xml:lang']) ? $row['o']['xml:lang'] : null;
             $dType = isset($row['o']['datatype']) ? $row['o']['datatype'] : null;
             if ($oType === 'bnode') {
                 $bnObjects[] = substr($o, 2);
             }
             $this->_handleStatement($s, $p, $o, $sType, $oType, $lang, $dType);
         }
         if (count($result['results']['bindings']) < 1000) {
             break;
         }
         $offset += 1000;
     }
     $this->_forceWrite();
     // SCBD -> Write Bnodes, too
     if ($level <= 10) {
         foreach ($bnObjects as $bn) {
             $this->_serializeResource($bn, $useAc, $level + 1);
         }
     }
     // We only return SCBD of the TOP resource...
     if ($level > 0) {
         return;
     }
     // SCBD: Do the same for all Resources, that have the resource as object
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?s ?p ?o');
     $query->addFrom($this->_graphUri);
     $query->setWherePart('WHERE { ?s ?p ?o . ?s ?p2 ?o2 . FILTER (sameTerm(?o2, <' . $resource . '>)) }');
     $query->setOrderClause('?s ?p ?o');
     $query->setLimit(1000);
     $offset = 0;
     $bnObjects = array();
     while (true) {
         $query->setOffset($offset);
         $result = $this->_store->sparqlQuery($query, array('result_format' => 'extended', 'use_owl_imports' => false, 'use_additional_imports' => false, 'use_ac' => $useAc));
         foreach ($result['results']['bindings'] as $row) {
             $s = $row['s']['value'];
             $p = $row['p']['value'];
             $o = $row['o']['value'];
             $sType = $row['s']['type'];
             $oType = $row['o']['type'];
             $lang = isset($row['o']['xml:lang']) ? $row['o']['xml:lang'] : null;
             $dType = isset($row['o']['datatype']) ? $row['o']['datatype'] : null;
             if ($oType === 'bnode') {
                 $bnObjects[] = substr($o, 2);
             }
             $this->_handleStatement($s, $p, $o, $sType, $oType, $lang, $dType);
         }
         if (count($result['results']['bindings']) < 1000) {
             break;
         }
         $offset += 1000;
     }
     $this->_forceWrite();
     // SCBD -> Write Bnodes, too
     if ($level <= 10) {
         foreach ($bnObjects as $bn) {
             $this->_serializeResource($bn, $useAc, $level + 1);
         }
     }
 }