コード例 #1
0
ファイル: Link.php プロジェクト: cfrancois7/site.ontowiki
 public function link($options = array())
 {
     $model = OntoWiki::getInstance()->selectedModel;
     $titleHelper = new OntoWiki_Model_TitleHelper($model);
     // check for options and assign local vars or null
     $uri = isset($options['uri']) ? (string) $options['uri'] : null;
     $literal = isset($options['literal']) ? $options['literal'] : null;
     $text = isset($options['text']) ? $options['text'] : null;
     $property = isset($options['property']) ? $options['property'] : null;
     $class = isset($options['class']) ? ' class="' . $options['class'] . '"' : '';
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $iprefix = isset($options['iprefix']) ? $options['iprefix'] : '';
     $isuffix = isset($options['isuffix']) ? $options['isuffix'] : '';
     $direct = isset($options['direct']) ? true : false;
     // resolve short forms (overwrite full name values with short forms values)
     $uri = isset($options['r']) ? (string) $options['r'] : $uri;
     $literal = isset($options['l']) ? $options['l'] : $literal;
     $text = isset($options['t']) ? $options['t'] : $text;
     $property = isset($options['p']) ? $options['p'] : $property;
     // if an uri is given, we do not need to search for
     if (isset($uri)) {
         // resolve qnames and check uri input
         $uri = Erfurt_Uri::getFromQnameOrUri((string) $uri, $model);
     } else {
         // if no uri is given, we need to search by using the literal
         if (!isset($literal)) {
             throw new Exception('The link helper needs at least one parameter literal or uri');
         }
         // if a property is given, use <properyuri> instead of a variable part in the query
         $property = $property ? '<' . Erfurt_Uri::getFromQnameOrUri($property, $model) . '>' : '?property';
         // build the query including PREFIX declarations
         $query = '';
         foreach ($model->getNamespaces() as $ns => $nsprefix) {
             $query .= 'PREFIX ' . $nsprefix . ': <' . $ns . '>' . PHP_EOL;
         }
         $query .= 'SELECT DISTINCT ?resourceUri WHERE {?resourceUri ' . $property . ' ?literal
             FILTER (!isBLANK(?resourceUri))
             FILTER (REGEX(?literal, "^' . $literal . '$", "i"))
             }  LIMIT 1';
         $result = $model->sparqlQuery($query);
         if (!$result) {
             // resource not found, so return plain literal or given text
             return isset($text) ? $text : $literal;
         } else {
             $uri = $result[0]['resourceUri'];
         }
     }
     // generate the link URL from the resource URI
     if ($direct == true) {
         $url = $uri;
     } else {
         $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
         $url->setParam('r', $uri, true);
         $url = (string) $url;
     }
     // link text comes from title helper or option
     $text = isset($text) ? $text : $titleHelper->getTitle($uri);
     return "{$prefix}<a{$class} href='{$url}'>{$iprefix}{$text}{$isuffix}</a>{$suffix}";
 }
コード例 #2
0
 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');
 }
コード例 #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
 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;
     }
 }
コード例 #5
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;
 }
コード例 #6
0
ファイル: TitleHelper.php プロジェクト: cfrancois7/aksw.org
 /**
  * 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();
     }
 }
コード例 #7
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>';
     }
 }
コード例 #8
0
ファイル: Table.php プロジェクト: cfrancois7/site.ontowiki
 public function table($options = array())
 {
     $model = OntoWiki::getInstance()->selectedModel;
     $titleHelper = new OntoWiki_Model_TitleHelper($model);
     // check for options and assign local vars or default values
     $class = isset($options['class']) ? $options['class'] : '';
     $id = isset($options['id']) ? $options['id'] : '';
     $tag = isset($options['tag']) ? $options['tag'] : 'span';
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $iprefix = isset($options['iprefix']) ? $options['iprefix'] : '';
     $isuffix = isset($options['isuffix']) ? $options['isuffix'] : '';
     // choose, which uri to use: option over helper default over view value
     $uri = isset($this->resourceUri) ? $this->resourceUri : null;
     $uri = isset($options['selectedResource']) ? (string) $options['selectedResource'] : $uri;
     $uri = isset($options['uri']) ? (string) $options['uri'] : $uri;
     $uri = Erfurt_Uri::getFromQnameOrUri($uri, $model);
     // choose, which properties to use (todo: allow multple properties)
     $contentProperties = isset($options['property']) ? array($options['property']) : null;
     $contentProperties = !$contentProperties ? $this->contentProperties : $contentProperties;
     foreach ($contentProperties as $key => $value) {
         try {
             $validatedValue = Erfurt_Uri::getFromQnameOrUri($value, $model);
             $contentProperties[$key] = $validatedValue;
         } catch (Exception $e) {
             unset($contentProperties[$key]);
         }
     }
     // create description from resource URI
     $resource = new OntoWiki_Resource($uri, $model);
     $description = $resource->getDescription();
     $description = $description[$uri];
     // get the table size
     $tableRows = 0;
     // the URI of the main content property
     $tableColumns = 0;
     // the URI of the main content property
     foreach ($contentProperties as $contentProperty) {
         if (isset($description[$contentProperty . 'Rows'])) {
             $tableRows = (int) $description[$contentProperty . 'Rows'][0]['value'];
         }
         if (isset($description[$contentProperty . 'Columns'])) {
             $tableColumns = (int) $description[$contentProperty . 'Columns'][0]['value'];
         }
         if (null != $tableRows && null != $tableColumns) {
             $mainProperty = $contentProperty;
             break;
         }
     }
     $content = '';
     // filter and render the table
     if (0 < $tableRows && 0 < $tableColumns) {
         $content .= '<table id=' . $id . '><thead>';
         for ($row = 1; $row <= $tableRows; $row++) {
             $content .= '<tr id="R' . $row . '">';
             for ($column = 1; $column <= $tableColumns; $column++) {
                 $content .= (1 == $row ? '<th' : '<td') . ' id="R' . $row . 'C' . $column . '">';
                 $currentMainProperty = $mainProperty . 'R' . $row . 'C' . $column;
                 unset($firstLiteral);
                 // search for language tag
                 foreach ($description[$currentMainProperty] as $literalNumber => $literal) {
                     $currentLanguage = OntoWiki::getInstance()->getConfig()->languages->locale;
                     if (isset($literal['lang']) && $currentLanguage == $literal['lang']) {
                         $firstLiteral = $description[$currentMainProperty][$literalNumber];
                         break;
                     }
                 }
                 if (!isset($firstLiteral)) {
                     $firstLiteral = $description[$currentMainProperty][0];
                 }
                 $cellContent = $firstLiteral['value'];
                 // execute the helper markup on the content (after the extensions)
                 $cellContent = $this->view->executeHelperMarkup($cellContent);
                 // filter by using available extensions
                 if (isset($firstLiteral['datatype'])) {
                     $datatype = $firstLiteral['datatype'];
                     $cellContent = $this->view->displayLiteralPropertyValue($cellContent, $currentMainProperty, $datatype);
                 } else {
                     $cellContent = $this->view->displayLiteralPropertyValue($cellContent, $currentMainProperty);
                 }
                 $curie = $this->view->curie($currentMainProperty);
                 $cellContent = $iprefix . $cellContent . $isuffix;
                 $content .= "{$prefix}<{$tag} class='{$class}' property='{$curie}'>{$cellContent}</{$tag}>{$suffix}";
                 $content .= 1 == $row ? '</th>' : '</td>';
             }
             $content .= '</tr>';
             $content .= 1 == $row ? '</thead><tbody>' : '';
         }
         $content .= '</tbody></table>';
     }
     return $content;
 }
コード例 #9
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;
 }
コード例 #10
0
ファイル: Literal.php プロジェクト: cfrancois7/site.ontowiki
 protected function _selectMainProperty($model, $description, $options)
 {
     // choose, which properties to use (todo: allow multple properties)
     $contentProperties = isset($options['property']) ? array($options['property']) : null;
     $contentProperties = !$contentProperties ? $this->contentProperties : $contentProperties;
     foreach ($contentProperties as $key => $value) {
         try {
             $validatedValue = Erfurt_Uri::getFromQnameOrUri($value, $model);
             $contentProperties[$key] = $validatedValue;
         } catch (Exception $e) {
             unset($contentProperties[$key]);
         }
     }
     // select the main property from existing ones
     $mainProperty = null;
     // the URI of the main content property
     foreach ($contentProperties as $contentProperty) {
         if (isset($description[$contentProperty])) {
             $mainProperty = $contentProperty;
             break;
         }
     }
     return $mainProperty;
 }
コード例 #11
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);
 }
コード例 #12
0
 /**
  *
  */
 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);
 }
コード例 #13
0
ファイル: Namespaces.php プロジェクト: FTeichmann/Erfurt
 /**
  * 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);
 }
コード例 #14
0
 /**
  *
  * 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;
 }
コード例 #15
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;
 }
コード例 #16
0
ファイル: Img.php プロジェクト: cfrancois7/site.ontowiki
 public function img($options = array())
 {
     $owapp = OntoWiki::getInstance();
     $store = $owapp->erfurt->getStore();
     $model = $owapp->selectedModel;
     $extManager = $owapp->extensionManager;
     // check for options and assign local vars or null
     $src = isset($options['src']) ? (string) $options['src'] : null;
     $class = isset($options['class']) ? ' class="' . $options['class'] . '"' : '';
     $alt = isset($options['alt']) ? ' alt="' . $options['alt'] . '"' : '';
     $filter = isset($options['filter']) ? $options['filter'] : null;
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $nordfa = isset($options['nordfa']) ? true : false;
     // choose, which uri to use: option over helper default over view value
     $uri = isset($this->resourceUri) ? $this->resourceUri : null;
     $uri = isset($options['selectedResource']) ? (string) $options['selectedResource'] : $uri;
     $uri = isset($options['uri']) ? (string) $options['uri'] : $uri;
     // in case qname is given, transform to full URI
     $uri = Erfurt_Uri::getFromQnameOrUri($uri, $model);
     // look for a valid image url somewhere
     if ($src == null) {
         // choose, which properties to use for lookup (todo: allow multple properties)
         $properties = isset($options['property']) ? array($options['property']) : null;
         $properties = !$properties ? $this->_properties : $properties;
         // validate each given property
         foreach ($properties as $key => $value) {
             try {
                 $validatedValue = Erfurt_Uri::getFromQnameOrUri($value, $model);
                 $properties[$key] = $validatedValue;
             } catch (Exception $e) {
                 // unset invalid properties
                 unset($properties[$key]);
             }
         }
         // create description from resource URI
         $resource = new OntoWiki_Resource($uri, $model);
         $description = $resource->getDescription();
         $description = $description[$uri];
         // select the used property
         $imgProperty = null;
         foreach ($properties as $property) {
             if (isset($description[$property])) {
                 $imgProperty = $property;
                 break;
             }
         }
         if ($imgProperty != null) {
             //search for language tag
             foreach ($description[$imgProperty] as $literalNumber => $literal) {
                 $currentLanguage = OntoWiki::getInstance()->getConfig()->languages->locale;
                 if (isset($literal['lang']) && $currentLanguage == $literal['lang']) {
                     $imgSrc = $description[$imgProperty][$literalNumber]['value'];
                     break;
                 }
             }
             if (!isset($imgSrc)) {
                 $imgSrc = $description[$imgProperty][0]['value'];
             }
         } else {
             // we do not have an image src
             return '';
         }
     } else {
         $imgSrc = $src;
     }
     // modify the image imgSrc for the IPC extension
     // @todo: use an event here
     if ($filter && $extManager->isExtensionRegistered('ipc')) {
         $ipcSrc = $owapp->config->urlBase . '/ipc/get';
         $ipcSrc = $ipcSrc . '?img=' . urlencode($imgSrc) . '&filter=' . urlencode($filter);
         $imgSrc = $ipcSrc;
     }
     // build the image tag for output
     $return = $prefix;
     $return .= '<img' . $class . $alt;
     if ($nordfa == false) {
         $return .= !$src ? ' about="' . $this->view->curie($uri) . '"' : '';
         $return .= !$src ? ' property="' . $this->view->curie($imgProperty) . '"' : '';
         // this property is needed since ipc maybe rewrites the src
         $return .= !$src ? ' resource="' . htmlentities($imgSrc) . '"' : '';
         if (isset($options['attributes']) && is_array($options['attributes'])) {
             foreach ($options['attributes'] as $key => $value) {
                 $return .= ' ' . $key . '="' . $value . '"';
             }
         }
     }
     $return .= ' src="' . htmlentities($imgSrc) . '" />';
     $return .= $suffix;
     return $return;
 }
コード例 #17
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);
 }
コード例 #18
0
ファイル: UriTest.php プロジェクト: FTeichmann/Erfurt
 /**
  * @expectedException Erfurt_Uri_Exception
  */
 public function testGetFromQnameInvalidUri()
 {
     $model = $this->_getMockedModel();
     $input = 'nothing:good';
     Erfurt_Uri::getFromQnameOrUri($input, $model);
 }