public function getContents()
 {
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $changes = array();
     if ($this->results) {
         foreach ($this->results as $change) {
             if ($this->getContext() == "main.window.dashmodelinfo") {
                 //id, resource, tstamp, action_type
                 $change['useruri'] = $this->user;
                 $this->model = null;
             }
             if (Erfurt_Uri::check($change['resource'])) {
                 $change['aresource'] = new OntoWiki_Resource((string) $change['useruri'], $this->systemModel);
                 $change['author'] = $change['aresource']->getTitle() ? $change['aresource']->getTitle() : OntoWiki_Utils::getUriLocalPart($change['aresource']);
                 $url->setParam('r', (string) $change['aresource'], true);
                 $change['ahref'] = (string) $url;
                 //$change['date'] = OntoWiki_Utils::dateDifference($change['tstamp'], null, 3);
                 $url->setParam('r', (string) $change['resource'], true);
                 $change['rhref'] = (string) $url;
                 $change['resource'] = new OntoWiki_Resource((string) $change['resource'], $this->model);
                 $change['rname'] = $change['resource']->getTitle() ? $change['resource']->getTitle() : OntoWiki_Utils::contractNamespace($change['resource']->getIri());
                 $changes[] = $change;
             }
         }
     }
     if (empty($changes)) {
         $this->view->infomessage = 'There are no changes yet.';
     } else {
         $this->view->changes = $changes;
     }
     return $this->render('templates/lastchanges');
 }
예제 #2
0
 public function testCheck()
 {
     $validUris = array('http://example.com/Test', 'urn:isbn:978-3-86680-192-9', 'ftp://ftp.is.co.za/rfc/rfc1808.txt', 'gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles', 'http://www.math.uio.no/faq/compression-faq/part1.html', 'mailto:mduerst@ifi.unizh.ch', 'news:comp.infosystems.www.servers.unix', 'telnet://melvyl.ucop.edu/', 'http://*****:*****@example.com/test/cat?foo=ba%7C', 'http://bio2rdf.org/bio2rdf_dataset:bio2rdf-sgd-20121015');
     foreach ($validUris as $uri) {
         $this->assertEquals(true, Erfurt_Uri::check($uri));
     }
     $invalidUris = array('Literal value', 'http://example.com /Test', "http://example.com/T\nest", 'http://example.[com]/{test}/cat?foo=ba%7C');
     foreach ($invalidUris as $uri) {
         $this->assertEquals(false, Erfurt_Uri::check($uri));
     }
 }
예제 #3
0
 /**
  * Handle objects by checking different cases and than decide how to react.
  * @param $s string URI of subject
  * @param $p string URI of predicate
  * @param $o mixed Can be string, array or an object of the object
  * @param $graph Call by reference of $graph instance
  * @return void
  */
 public static function handleNonCVObjects($s, $p, $o, &$graph)
 {
     // is object an URI
     if (true === is_string($o) && true === Erfurt_Uri::check($o)) {
         $graph->addResource($s, $p, $o);
         // is object NOT an array
     } else {
         if (false === is_array($o)) {
             $graph->add($s, $p, $o);
             // assuming, object is an array
         } else {
             foreach ($o as $entry) {
                 if (true === Erfurt_Uri::check($entry)) {
                     $graph->addResource($s, $p, $entry);
                 } else {
                     $graph->add($s, $p, $entry);
                 }
             }
         }
     }
 }
예제 #4
0
파일: Pool.php 프로젝트: FTeichmann/Erfurt
 /**
  * create a Resource
  *
  * @param string resourceIri
  * @param string graphIri or null
  * @return Erfurt_Rdf_Resource resource
  */
 private function _createResource($resourceIri, $graphIri = 'store')
 {
     $resource = null;
     if (Erfurt_Uri::check($resourceIri)) {
         if ($graphIri == 'store') {
             $resource = new Erfurt_Rdf_Resource($resourceIri);
         } else {
             if (Erfurt_Uri::check($graphIri)) {
                 $model = $this->_app->getStore()->getModel($graphIri, false);
                 $resource = $model->getResource($resourceIri);
             } else {
                 if (defined('_OWDEBUG')) {
                     $logger = $this->_app->getLog();
                     $logger->info('ResourcePool: Given GraphIri not valid.');
                 }
             }
         }
     } else {
         if (defined('_OWDEBUG')) {
             $logger = $this->_app->getLog();
             $logger->info('ResourcePool: Given ResourceIri not valid.');
         }
     }
     return $resource;
 }
예제 #5
0
 /**
  * Add a new title property on top of the list (most important) of title properties
  *
  * @param $propertyUri a string with the URI of the property to add
  */
 public function prependTitleProperty($propertyUri)
 {
     // check if we have a valid URI
     if (Erfurt_Uri::check($propertyUri)) {
         // remove the property from the list if it already exist
         foreach ($this->_titleProperties as $key => $value) {
             if ($value == $propertyUri) {
                 unset($this->_titleProperties[$key]);
             }
         }
         // rewrite the array
         $this->_titleProperties = array_values($this->_titleProperties);
         // prepend the new URI
         array_unshift($this->_titleProperties, $propertyUri);
         // reset the TitleHelper to fetch resources with new title properties
         $this->reset();
     }
 }
예제 #6
0
 public function onDisplayLiteralPropertyValue($event)
 {
     if (array_key_exists($event->property, $this->_properties) && Erfurt_Uri::check($event->value)) {
         return '<a href="' . $event->value . '">' . OntoWiki_Utils::shorten($event->value, 60) . '</a>';
     }
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 private function _getMenu($uri, $model, $titleHelper = null)
 {
     $query = '
         PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
         SELECT ?item ?prop
         WHERE {
            <' . $uri . '> ?prop ?item.
            ?prop a rdfs:ContainerMembershipProperty.
         }
     ';
     try {
         $result = $model->sparqlQuery($query);
     } catch (Exception $e) {
         throw new OntoWiki_Exception('Problem while getting menu entries.', $e);
     }
     // array of urls and labels which represent the navigation menu
     $items = array();
     // round one: fill items array with urls as well as fill the titleHelper
     foreach ($result as $row) {
         // works only for URIs ...
         if (Erfurt_Uri::check($row['item'])) {
             // prepare variables
             $url = $row['item'];
             $property = $row['prop'];
             // fill the titleHelper
             if ($titleHelper !== null) {
                 $titleHelper->addResource($url);
             }
             // split property and use numeric last part for items order.
             // example property: http://www.w3.org/2000/01/rdf-schema#_1
             $pieces = explode('_', $property);
             if (isset($pieces[1]) && is_numeric($pieces[1])) {
                 // file the items array
                 $items[$pieces[1]] = array('url' => $url, 'label' => $pieces[1]);
                 $subMenu = $this->_getMenu($url, $model, $titleHelper);
                 if (count($subMenu['items']) > 0) {
                     $items[$pieces[1]]['hasSubMenu'] = true;
                     $items[$pieces[1]]['subMenu'] = $subMenu;
                 } else {
                     $items[$pieces[1]]['hasSubMenu'] = false;
                 }
             }
         }
     }
     // round three: sort items according to the index
     if (count($items) > 1) {
         ksort($items);
     }
     // metadata of the navigation as a whole
     $meta = array();
     $resource = $model->getResource($uri);
     $resourceModel = $resource->getMemoryModel();
     if ($resourceModel->hasSP($uri, $this->_prependedContent)) {
         $meta['prependedContent'] = $resourceModel->getValue($uri, $this->_prependedContent);
     }
     if ($resourceModel->hasSP($uri, $this->_appendedContent)) {
         $meta['appendedContent'] = $resourceModel->getValue($uri, $this->_appendedContent);
     }
     //if ($uri == 'http://aksw.org/Events/2013/LeipzigerSemanticWebTag/Menu') {
     //var_dump($resourceModel);
     //}
     return array('items' => $items, 'meta' => $meta);
 }
예제 #9
0
 protected function _loadModel()
 {
     $siteConfig = $this->_getSiteConfig();
     // m is automatically used and selected
     if (!isset($this->_request->m) && !$this->_owApp->selectedModel) {
         // TODO: what if no site model configured?
         if (!Erfurt_Uri::check($siteConfig['model'])) {
             $site = $this->_privateConfig->defaultSite;
             $root = $this->getComponentHelper()->getComponentRoot();
             $configFilePath = sprintf('%s%s/%s/%s', $root, $this->_relativeTemplatePath, $site, SiteHelper::SITE_CONFIG_FILENAME);
             throw new OntoWiki_Exception('No model selected! Please, configure a site model by setting the option ' . '"model=..." in "' . $configFilePath . '" or specify parameter m in the URL.');
         } else {
             // setup the model
             $this->_modelUri = $siteConfig['model'];
             $store = OntoWiki::getInstance()->erfurt->getStore();
             $this->_model = $store->getModel($this->_modelUri);
             OntoWiki::getInstance()->selectedModel = $this->_model;
         }
     } else {
         $this->_model = $this->_owApp->selectedModel;
         $this->_modelUri = (string) $this->_owApp->selectedModel;
     }
 }
예제 #10
0
 /**
  * Adds a prefix for the namespace URI in a given graph.
  *
  * @param Erfurt_Rdf_Model|string $graph
  * @param string $namespace
  * @param string $prefix
  * @throws Erfurt_Namespaces_Exception
  */
 public function addNamespacePrefix($graph, $namespace, $prefix)
 {
     // safety
     $prefix = (string) $prefix;
     $namespace = (string) $namespace;
     //lowercase prefix always (for best compatibility)
     $prefix = strtolower($prefix);
     $graphPrefixes = $this->getNamespacesForGraph($graph);
     // check if namespace is a valid URI
     require_once 'Erfurt/Uri.php';
     if (!Erfurt_Uri::check($namespace)) {
         require_once 'Erfurt/Namespaces/Exception.php';
         throw new Erfurt_Namespaces_Exception("Given namespace '{$namespace}' is not a valid URI.");
     }
     // check if prefix is a valid XML name
     require_once 'Erfurt/Utils.php';
     if (!Erfurt_Utils::isXmlPrefix($prefix)) {
         require_once 'Erfurt/Namespaces/Exception.php';
         throw new Erfurt_Namespaces_Exception("Given prefix '{$prefix}' is not a valid XML name.");
     }
     // check if prefix matches a URI scheme (http://www.iana.org/assignments/uri-schemes.html)
     if (array_key_exists($prefix, $this->_reservedNames)) {
         require_once 'Erfurt/Namespaces/Exception.php';
         throw new Erfurt_Namespaces_Exception("Reserved name '{$prefix}' cannot be used as a namespace prefix.");
     }
     // check for existence of prefixes
     if (array_key_exists($prefix, $graphPrefixes)) {
         require_once 'Erfurt/Namespaces/Exception.php';
         throw new Erfurt_Namespaces_Exception("Prefix '{$prefix}' already exists.");
     }
     // check for multiple prefixes
     if (!$this->_allowMultiplePrefixes and array_key_exists($namespace, array_flip($graphPrefixes))) {
         require_once 'Erfurt/Namespaces/Exception.php';
         throw new Erfurt_Namespaces_Exception("Multiple prefixes for namespace '{$namespace}' not allowed.");
     }
     // add new prefix
     $graphPrefixes[$prefix] = $namespace;
     // save new set of prefixes
     $this->setNamespacesForGraph($graph, $graphPrefixes);
 }
 /**
  *
  * Enter description here ...
  *
  * @param   $uri         string to convert to nice uri
  * @param   $titleHelper TitleHelper instance to use to get titles for URIs
  */
 private function generateUriFromSparql($uri, $titleHelper)
 {
     $schema = $this->loadNamingSchema($uri);
     $properties = array();
     foreach ($schema as $element) {
         if (is_string($this->_config->property->{$element})) {
             $properties[$this->_config->property->{$element}] = array('element' => $element, 'rank' => '1');
         } elseif (is_array($this->_config->property->{$element}->toArray())) {
             $countDeep = 0;
             foreach ($this->_config->property->{$element}->toArray() as $elementDeep) {
                 $properties[(string) $elementDeep] = array('element' => $element, 'rank' => $countDeep++);
             }
         }
     }
     $query = new Erfurt_Sparql_Query2();
     $sRef = new Erfurt_Sparql_Query2_IriRef($uri);
     $pVar = new Erfurt_Sparql_Query2_Var('p');
     $oVar = new Erfurt_Sparql_Query2_Var('o');
     $query->addProjectionVar($pVar);
     $query->addProjectionVar($oVar);
     $query->addTriple($sRef, $pVar, $oVar);
     $query->addFrom((string) $this->_model);
     $query->setLimit(100);
     $query->setDistinct(true);
     $container = new Erfurt_Sparql_Query2_ConditionalOrExpression();
     foreach ($properties as $filterProp => $element) {
         $sameTerm = new Erfurt_Sparql_Query2_sameTerm($pVar, new Erfurt_Sparql_Query2_IriRef($filterProp));
         //$filter = new Erfurt_Sparql_Query2_Filter($sameTerm);
         $container->addElement($sameTerm);
     }
     $query->addFilter($container);
     $result = $this->_owApp->erfurt->getStore()->sparqlQuery($query, array('withImports' => true));
     $replacements = array();
     foreach ($result as $row) {
         if (array_key_exists($row['p'], $properties)) {
             $titleHelper->addResource($row['p']);
             if (Erfurt_Uri::check($row['o'])) {
                 $titleHelper->addResource($row['o']);
             }
             if (array_key_exists($properties[$row['p']]['element'], $replacements)) {
                 $newRank = (int) $properties[$row['p']]['rank'];
                 $minRank = $replacements[$properties[$row['p']]['element']]['rank'];
                 if ($newRank < $minRank) {
                     $replacements[$properties[$row['p']]['element']] = array('rank' => $newRank, 'value' => $row['o'], 'key' => $row['p']);
                 }
             } else {
                 $replacements[$properties[$row['p']]['element']] = array('rank' => $properties[$row['p']]['rank'], 'value' => $row['o'], 'key' => $row['p']);
             }
         }
     }
     $localName = '';
     foreach ($schema as $element) {
         if (array_key_exists($element, $replacements)) {
             if (Erfurt_Uri::check($replacements[$element]['value'])) {
                 $val = $titleHelper->getTitle($replacements[$element]['value']);
             } else {
                 $val = $replacements[$element]['value'];
             }
             $val = $this->convertChars($val);
             $key = $this->convertChars($titleHelper->getTitle($replacements[$element]['key']));
             $localName .= $key . '/' . $val . '/';
         }
     }
     // no meaningful localname created falback to old uri (TODO or md5 a new one?)
     if ($localName === '') {
         return $uri;
         //$localName = 'resource/' . md5($uri . time());
     }
     $base = '';
     if ($this->_model !== null && $this->_model->getBaseIri() !== '') {
         $base = $this->_model->getBaseIri();
         if ($base[strlen($base) - 1] !== '#' && $base[strlen($base) - 1] !== '/') {
             $base .= '/';
         }
     } else {
         $count = 0;
         foreach (explode('/', $uri) as $element) {
             if ($count > 2) {
                 break;
             } else {
                 $count++;
                 $base .= $element . '/';
             }
         }
     }
     return $base . $localName;
 }
예제 #12
0
 function getObject($property, $value)
 {
     if (is_string($value)) {
         $value = addslashes($value);
     }
     if (isset($this->_map[$property]) && $this->_map[$property]['type'] == 'uri' || Erfurt_Uri::check($value)) {
         $object = '<' . $value . '>';
     } else {
         if (is_bool($value)) {
             $object = '"' . ($value ? 'true' : 'false') . '"^^xsd:boolean';
         } else {
             if (is_string($value) && $value == 'true' || $value == 'false') {
                 $object = '"' . ($value == 'true' ? 'true' : 'false') . '"^^xsd:boolean';
                 //why?
             } else {
                 if (isset($this->_map[$property]['datatype']) && $this->_map[$property]['datatype'] == 'boolean') {
                     $object = '"' . ((bool) $value ? 'true' : 'false') . '"^^xsd:boolean';
                 } else {
                     $object = '"' . $value . '"';
                 }
             }
         }
     }
     return $object;
 }
예제 #13
0
 /**
  * This is the sorting function used to sort the result set.
  * It compares the titles of the resources in $a and $b as returned by the TitleHelper
  *
  * @param $a the first row to compare
  * @param $b the second row to compare
  * @return int as needed by usort
  */
 private function _cmpTitles($a, $b, $orderBy = 'resourceUri')
 {
     $titleA = '';
     $titleB = '';
     if (!Erfurt_Uri::check($a[$orderBy])) {
         $titleA = $a[$orderBy];
     } else {
         $titleA = $this->_titleHelper->getTitle($a[$orderBy]);
     }
     if (!Erfurt_Uri::check($b[$orderBy])) {
         $titleB = $b[$orderBy];
     } else {
         $titleB = $this->_titleHelper->getTitle($b[$orderBy]);
     }
     return strcasecmp($titleA, $titleB);
 }
 /**
  *
  */
 public function getslicesAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     // parameter
     $modelIri = $this->_request->getParam('modelIri', '');
     $dsdUrl = $this->_request->getParam('dsdUrl', '');
     $dsUrl = $this->_request->getParam('dsUrl', '');
     // check if model there
     if (false === $this->_erfurt->getStore()->isModelAvailable($modelIri)) {
         $code = 404;
         $this->_sendJSONResponse(array('code' => $code, 'content' => '', 'message' => 'Model not available'), $code);
         return;
     }
     // check if dsdUrl is valid
     if (false === Erfurt_Uri::check($dsdUrl)) {
         $code = 400;
         $this->_sendJSONResponse(array('code' => $code, 'content' => '', 'message' => 'dsdUrl is not valid'), $code);
         return;
     }
     // check if dsUrl is valid
     if (false === Erfurt_Uri::check($dsUrl)) {
         $code = 400;
         $this->_sendJSONResponse(array('code' => $code, 'content' => '', 'message' => 'dsUrl is not valid'), $code);
         return;
     }
     try {
         $model = new Erfurt_Rdf_Model($modelIri);
         $query = new DataCube_Query($model, $this->_titleHelperLimit, $this->_dimensionElementLimit);
         $code = 200;
         // result object
         $content = array('code' => $code, 'content' => array(), 'message' => '');
         // get slice keys
         $sliceKeys = $query->getSliceKeys($dsdUrl, $dsUrl);
         // collect all slices in one list
         foreach ($sliceKeys as $sliceKey) {
             $content['content'] = array_merge($content['content'], $sliceKey['slices']);
         }
     } catch (Exception $e) {
         $code = 400;
         $content = array('code' => $code, 'content' => '', 'message' => $e->getMessage());
     }
     $this->_sendJSONResponse($content, $code);
 }