当前位置: 首页>>代码示例>>PHP>>正文


PHP EasyRdf_Namespace::shorten方法代码示例

本文整理汇总了PHP中EasyRdf_Namespace::shorten方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Namespace::shorten方法的具体用法?PHP EasyRdf_Namespace::shorten怎么用?PHP EasyRdf_Namespace::shorten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EasyRdf_Namespace的用法示例。


在下文中一共展示了EasyRdf_Namespace::shorten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: types

 /** Get a list of types for a resource
  *
  * The types will each be a shortened URI as a string.
  * This method will return an empty array if the resource has no types.
  *
  * If $resource is null, then it will get the types for the URI of the graph.
  *
  * @return array All types assocated with the resource (e.g. foaf:Person)
  */
 public function types($resource = null)
 {
     $resources = $this->typesAsResources($resource);
     $types = array();
     foreach ($resources as $type) {
         $types[] = EasyRdf_Namespace::shorten($type);
     }
     return $types;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:18,代码来源:Graph.php

示例2: getTypes

 /**
  * Return all types (RDFS/OWL classes) present in the specified vocabulary or all vocabularies.
  * @return array Array with URIs (string) as key and array of (label, superclassURI) as value
  */
 public function getTypes($vocid = null, $lang = null)
 {
     $sparql = isset($vocid) ? $this->getVocabulary($vocid)->getSparql() : $this->getDefaultSparql();
     $result = $sparql->queryTypes($lang);
     foreach ($result as $uri => $values) {
         if (empty($values)) {
             $shorteneduri = EasyRdf_Namespace::shorten($uri);
             if ($shorteneduri !== null) {
                 $trans = gettext($shorteneduri);
                 if ($trans) {
                     $result[$uri] = array('label' => $trans);
                 }
             }
         }
     }
     return $result;
 }
开发者ID:jneubert,项目名称:Skosmos,代码行数:21,代码来源:Model.php

示例3: testShortenNonString

 public function testShortenNonString()
 {
     $this->setExpectedException('InvalidArgumentException');
     EasyRdf_Namespace::shorten($this);
 }
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:5,代码来源:NamespaceTest.php

示例4: shorten

 /** Get a shortened version of the resources URI.
  *
  * This method will return the full URI if the resource isn't part of any
  * registered namespace.
  *
  * @return string The shortened URI of this resource (e.g. foaf:name)
  */
 public function shorten()
 {
     return EasyRdf_Namespace::shorten($this->_uri);
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:11,代码来源:Resource.php

示例5: getResourceType

 /**
  * Get the type of a resource from some RDF/PHP
  * (http://n2.talis.com/wiki/RDF_PHP_Specification)
  */
 private function getResourceType($data, $uri)
 {
     if (array_key_exists($uri, $data)) {
         $subj = $data[$uri];
         if (array_key_exists(self::RDF_TYPE_URI, $subj)) {
             $types = array();
             foreach ($subj[self::RDF_TYPE_URI] as $type) {
                 if ($type['type'] == 'uri') {
                     $type = EasyRdf_Namespace::shorten($type['value']);
                     if ($type) {
                         array_push($types, $type);
                     }
                 }
             }
             if (count($types) > 0) {
                 return $types;
             }
         }
     }
     return null;
 }
开发者ID:richardhodgson,项目名称:console,代码行数:25,代码来源:Graph.php

示例6: testShortNamespace

 /**
  * Namespace which is too short shouldn't apply
  */
 public function testShortNamespace()
 {
     EasyRdf_Namespace::set('ex', 'http://example.org/');
     $this->assertSame('ex:foo', EasyRdf_Namespace::shorten('http://example.org/foo'));
     $this->assertNull(EasyRdf_Namespace::shorten('http://example.org/bar/baz'));
 }
开发者ID:takin,项目名称:workshop-semantic-web,代码行数:9,代码来源:NamespaceTest.php

示例7: testShortenNonString

 public function testShortenNonString()
 {
     $this->setExpectedException('InvalidArgumentException', '$uri should be a string or EasyRdf_Resource');
     EasyRdf_Namespace::shorten($this);
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:5,代码来源:NamespaceTest.php

示例8: getDatatype

 /** Returns the shortened datatype URI of the literal.
  *
  * @return string  Datatype of this literal (e.g. xsd:integer).
  */
 public function getDatatype()
 {
     if ($this->_datatype) {
         return EasyRdf_Namespace::shorten($this->_datatype);
     } else {
         return null;
     }
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:12,代码来源:Literal.php

示例9: getAllLabels

 /**
  * Gets the values for the property in question in all other languages than the ui language.
  * @param string $property
  */
 public function getAllLabels($property)
 {
     $labels = array();
     if (EasyRdf_Namespace::shorten($property) !== null) {
         // shortening property labels if possible
         $property = EasyRdf_Namespace::shorten($property);
     } else {
         $property = "<{$property}>";
     }
     // EasyRdf requires full URIs to be in angle brackets
     foreach ($this->resource->allLiterals($property) as $lit) {
         $labels[Punic\Language::getName($lit->getLang(), $this->getEnvLang())][] = new ConceptPropertyValueLiteral($lit, $property);
     }
     ksort($labels);
     return $labels;
 }
开发者ID:jneubert,项目名称:Skosmos,代码行数:20,代码来源:Concept.php

示例10: rdfxmlResource

 /**
  * Protected method to serialise a whole resource and its properties
  * @ignore
  */
 protected function rdfxmlResource($res, $showNodeId, $depth = 1)
 {
     // Keep track of the resources we have already serialised
     if (isset($this->_outputtedResources[$res->getUri()])) {
         return '';
     } else {
         $this->_outputtedResources[$res->getUri()] = true;
     }
     // If the resource has no properties - don't serialise it
     $properties = $res->propertyUris();
     if (count($properties) == 0) {
         return '';
     }
     $type = $res->type();
     if ($type) {
         $this->addPrefix($type);
     } else {
         $type = 'rdf:Description';
     }
     $indent = str_repeat('  ', $depth);
     $xml = "\n{$indent}<{$type}";
     if ($res->isBNode()) {
         if ($showNodeId) {
             $xml .= ' rdf:nodeID="' . htmlspecialchars($res->getNodeId()) . '"';
         }
     } else {
         $xml .= ' rdf:about="' . htmlspecialchars($res->getUri()) . '"';
     }
     $xml .= ">\n";
     foreach ($properties as $property) {
         $short = EasyRdf_Namespace::shorten($property, true);
         if ($short) {
             $this->addPrefix($short);
             $objects = $res->all("<{$property}>");
             if ($short == 'rdf:type') {
                 array_shift($objects);
             }
             foreach ($objects as $object) {
                 $xml .= $this->rdfxmlObject($short, $object, $depth + 1);
             }
         } else {
             throw new EasyRdf_Exception("It is not possible to serialse the property " . "'{$property}' to RDF/XML.");
         }
     }
     $xml .= "{$indent}</{$type}>\n";
     return $xml;
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:51,代码来源:RdfXml.php

示例11: dumpLiteralValue

 /** Return pretty-print view of a literal
  *
  * This method is mainly intended for internal use and is used by
  * EasyRdf_Graph and EasyRdf_Sparql_Result to format a literal
  * for display.
  *
  * @param  mixed $resource An EasyRdf_Literal object or an associative array
  * @param  bool  $html     Set to true to format the dump using HTML
  * @param  string $color   The colour of the text
  * @return string
  */
 public static function dumpLiteralValue($literal, $html = true, $color = 'black')
 {
     if (is_object($literal)) {
         $literal = $literal->toArray();
     } else {
         if (!is_array($literal)) {
             $literal = array('value' => $literal);
         }
     }
     $text = '"' . $literal['value'] . '"';
     if (isset($literal['lang'])) {
         $text .= '@' . $literal['lang'];
     }
     if (isset($literal['datatype'])) {
         $datatype = EasyRdf_Namespace::shorten($literal['datatype']);
         $text .= "^^{$datatype}";
     }
     if ($html) {
         return "<span style='color:{$color}'>" . htmlentities($text, ENT_COMPAT, "UTF-8") . "</span>";
     } else {
         return $text;
     }
 }
开发者ID:rowanthorpe,项目名称:myprofile,代码行数:34,代码来源:Utils.php

示例12: serialise

 /**
  * Method to serialise an EasyRdf_Graph to RDF/XML
  *
  * @param string  $graph   An EasyRdf_Graph object.
  * @param string  $format  The name of the format to convert to.
  * @return string          The RDF in the new desired format.
  */
 public function serialise($graph, $format)
 {
     parent::checkSerialiseParams($graph, $format);
     if ($format != 'rdfxml') {
         throw new EasyRdf_Exception("EasyRdf_Serialiser_RdfXml does not support: {$format}");
     }
     // store of namespaces to be appended to the rdf:RDF tag
     $this->_prefixes = array('rdf' => true);
     $xml = '';
     foreach ($graph->resources() as $resource) {
         $properties = $resource->propertyUris();
         if (count($properties) == 0) {
             continue;
         }
         $xml .= "\n  " . $this->rdfxmlResource($resource) . "\n";
         foreach ($properties as $property) {
             $short = EasyRdf_Namespace::shorten($property, true);
             if ($short) {
                 $this->addPrefix($short);
                 $objects = $resource->all($property);
                 foreach ($objects as $object) {
                     $xml .= $this->rdfxmlObject($short, $object);
                 }
             } else {
                 throw new EasyRdf_Exception("It is not possible to serialse the property " . "'{$property}' to RDF/XML.");
             }
         }
         $xml .= "  </rdf:Description>\n";
     }
     // iterate through namepsaces array prefix and output a string.
     $namespaceStr = '';
     foreach ($this->_prefixes as $prefix => $count) {
         $url = EasyRdf_Namespace::get($prefix);
         if (strlen($namespaceStr)) {
             $namespaceStr .= "\n        ";
         }
         $namespaceStr .= ' xmlns:' . $prefix . '="' . htmlspecialchars($url) . '"';
     }
     return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" . "<rdf:RDF" . $namespaceStr . ">\n" . $xml . "\n</rdf:RDF>\n";
 }
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:47,代码来源:RdfXml.php

示例13: serialiseProperties

 /**
  * Protected method to serialise the properties of a resource
  * @ignore
  */
 protected function serialiseProperties($res, $depth = 1)
 {
     $properties = $res->propertyUris();
     $indent = str_repeat(' ', $depth * 2 - 1);
     $turtle = '';
     if (count($properties) > 1) {
         $turtle .= "\n{$indent}";
     }
     $pCount = 0;
     foreach ($properties as $property) {
         $short = EasyRdf_Namespace::shorten($property, true);
         if ($short) {
             if ($short == 'rdf:type') {
                 $pStr = 'a';
             } else {
                 $this->addPrefix($short);
                 $pStr = $short;
             }
         } else {
             $pStr = '<' . str_replace('>', '\\>', $property) . '>';
         }
         if ($pCount) {
             $turtle .= " ;\n{$indent}";
         }
         $turtle .= ' ' . $pStr;
         $oCount = 0;
         foreach ($res->all("<{$property}>") as $object) {
             if ($oCount) {
                 $turtle .= ',';
             }
             if ($object instanceof EasyRdf_Resource and $object->isBnode()) {
                 $id = $object->getNodeId();
                 $rpcount = $this->reversePropertyCount($object);
                 if ($rpcount <= 1 and !isset($this->_outputtedBnodes[$id])) {
                     // Nested unlabelled Blank Node
                     $this->_outputtedBnodes[$id] = true;
                     $turtle .= ' [';
                     $turtle .= $this->serialiseProperties($object, $depth + 1);
                     $turtle .= ' ]';
                 } else {
                     // Multiple properties pointing to this blank node
                     $turtle .= ' ' . $this->serialiseObject($object);
                 }
             } else {
                 $turtle .= ' ' . $this->serialiseObject($object);
             }
             $oCount++;
         }
         $pCount++;
     }
     if ($depth == 1) {
         $turtle .= " .";
         if ($pCount > 1) {
             $turtle .= "\n";
         }
     } elseif ($pCount > 1) {
         $turtle .= "\n" . str_repeat(' ', ($depth - 1) * 2 - 1);
     }
     return $turtle;
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:64,代码来源:Turtle.php

示例14: serialise

 /**
  * Serialise an EasyRdf_Graph to Turtle.
  *
  * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
  * @param string  $format               The name of the format to convert to.
  * @return string                       The RDF in the new desired format.
  */
 public function serialise($graph, $format)
 {
     parent::checkSerialiseParams($graph, $format);
     if ($format != 'turtle' and $format != 'n3') {
         throw new EasyRdf_Exception("EasyRdf_Serialiser_Turtle does not support: {$format}");
     }
     $this->_prefixes = array('rdf' => true);
     $turtle = '';
     foreach ($graph->resources() as $subject) {
         $properties = $subject->propertyUris();
         if (count($properties) == 0) {
             continue;
         }
         $turtle .= $this->serialiseResource($subject);
         if (count($properties) > 1) {
             $turtle .= "\n   ";
         }
         $pCount = 0;
         foreach ($properties as $property) {
             $short = EasyRdf_Namespace::shorten($property, true);
             if ($short) {
                 $this->addPrefix($short);
                 $pStr = $short == 'rdf:type' ? 'a' : $short;
             } else {
                 $pStr = '<' . str_replace('>', '\\>', $property) . '>';
             }
             if ($pCount) {
                 $turtle .= " ;\n   ";
             }
             $turtle .= " " . $pStr;
             $objects = $subject->all($property);
             $oCount = 0;
             foreach ($objects as $object) {
                 if ($oCount) {
                     $turtle .= ",";
                 }
                 $turtle .= " " . $this->serialiseObject($object);
                 $oCount++;
             }
             $pCount++;
         }
         $turtle .= " .\n\n";
     }
     return $this->serialisePrefixes() . "\n" . $turtle;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:52,代码来源:Turtle.php

示例15: hasMultiLingualProperty

 /**
  * Queries whether the property should be shown with all the label language variations.
  * @param string $property
  * @return boolean
  */
 public function hasMultiLingualProperty($property)
 {
     $resources = $this->resource->allResources("skosmos:hasMultiLingualProperty");
     foreach ($resources as $res) {
         $prop = $res->getURI();
         if (EasyRdf_Namespace::shorten($prop) !== null) {
             $prop = EasyRdf_Namespace::shorten($prop);
         }
         if ($prop === $property) {
             return true;
         }
     }
     return false;
 }
开发者ID:jneubert,项目名称:Skosmos,代码行数:19,代码来源:VocabularyConfig.php


注:本文中的EasyRdf_Namespace::shorten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。