本文整理汇总了PHP中EasyRdf_Namespace::get方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Namespace::get方法的具体用法?PHP EasyRdf_Namespace::get怎么用?PHP EasyRdf_Namespace::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Namespace
的用法示例。
在下文中一共展示了EasyRdf_Namespace::get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetEmptyNamespace
public function testGetEmptyNamespace()
{
EasyRdf_Namespace::set('', 'http://xmlns.com/foaf/0.1/name');
$url = EasyRdf_Namespace::get('');
$this->assertSame('http://xmlns.com/foaf/0.1/name', $url);
}
示例2: expandCurie
protected function expandCurie($node, &$context, $value)
{
if (preg_match("/^(\\w*?):(.*)\$/", $value, $matches)) {
list(, $prefix, $local) = $matches;
$prefix = strtolower($prefix);
if ($prefix === '_') {
// It is a bnode
return $this->remapBnode(substr($value, 2));
} elseif (empty($prefix) and $context['vocab']) {
// Empty prefix
return $context['vocab'] . $local;
} elseif (isset($context['prefixes'][$prefix])) {
return $context['prefixes'][$prefix] . $local;
} elseif ($uri = $node->lookupNamespaceURI($prefix)) {
return $uri . $local;
} elseif (!empty($prefix) and $uri = EasyRdf_Namespace::get($prefix)) {
// Expand using well-known prefixes
return $uri . $local;
}
}
}
示例3: parseQNameOrBoolean
/**
* Parses qnames and boolean values, which have equivalent starting
* characters.
* @ignore
*/
protected function parseQNameOrBoolean()
{
// First character should be a ':' or a letter
$c = $this->read();
if ($c == -1) {
throw new EasyRdf_Exception("Turtle Parse Error: unexpected end of file while readying value");
}
if ($c != ':' && !self::isPrefixStartChar($c)) {
throw new EasyRdf_Exception("Turtle Parse Error: expected a ':' or a letter, found '{$c}'");
}
$namespace = NULL;
if ($c == ':') {
// qname using default namespace
$namespace = $this->_namespaces[""];
if ($namespace == NULL) {
throw new EasyRdf_Exception("Turtle Parse Error: default namespace used but not defined");
}
} else {
// $c is the first letter of the prefix
$prefix = $c;
$c = $this->read();
while (self::isPrefixChar($c)) {
$prefix .= $c;
$c = $this->read();
}
if ($c != ':') {
// prefix may actually be a boolean value
$value = $prefix;
if ($value == "true" || $value == "false") {
return array('type' => 'literal', 'value' => $value, 'datatype' => EasyRdf_Namespace::get('xsd') . 'boolean');
}
}
$this->verifyCharacter($c, ":");
if (isset($this->_namespaces[$prefix])) {
$namespace = $this->_namespaces[$prefix];
} else {
throw new EasyRdf_Exception("Turtle Parse Error: namespace prefix '{$prefix}' used but not defined");
}
}
// $c == ':', read optional local name
$localName = '';
$c = $this->read();
if (self::isNameStartChar($c)) {
$localName .= $c;
$c = $this->read();
while (self::isNameChar($c)) {
$localName .= $c;
$c = $this->read();
}
}
// Unread last character
$this->unread($c);
// Note: namespace has already been resolved
return array('type' => 'uri', 'value' => $namespace . $localName);
}
示例4: serialisePrefixes
/**
* @ignore
*/
protected function serialisePrefixes()
{
$turtle = '';
foreach ($this->_prefixes as $prefix => $count) {
$url = EasyRdf_Namespace::get($prefix);
$turtle .= "@prefix {$prefix}: <{$url}> .\n";
}
return $turtle;
}
示例5: getVocabularies
/**
* Returns the cached vocabularies.
* @return array of Vocabulary dataobjects
*/
public function getVocabularies()
{
if ($this->all_vocabularies === null) {
// initialize cache
$vocs = $this->graph->allOfType('skosmos:Vocabulary');
$this->all_vocabularies = $this->createDataObjects("Vocabulary", $vocs);
foreach ($this->all_vocabularies as $voc) {
// register vocabulary ids as RDF namespace prefixes
$prefix = preg_replace('/\\W+/', '', $voc->getId());
// strip non-word characters
try {
if ($prefix != '' && EasyRdf_Namespace::get($prefix) === null) {
EasyRdf_Namespace::set($prefix, $voc->getUriSpace());
}
} catch (Exception $e) {
// not valid as namespace identifier, ignore
}
}
}
return $this->all_vocabularies;
}
示例6: testDeleteNamespace
public function testDeleteNamespace()
{
EasyRdf_Namespace::set('po', 'http://purl.org/ontology/po/');
$this->assertNotNull(EasyRdf_Namespace::get('po'));
EasyRdf_Namespace::delete('po');
$this->assertNull(EasyRdf_Namespace::get('po'));
}
示例7: serialise
/**
* Method to serialise an EasyRdf_Graph to RDF/XML
*
* @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 != '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);
// store of the resource URIs we have serialised
$this->_outputtedResources = array();
$xml = '';
foreach ($graph->resources() as $resource) {
$xml .= $this->rdfxmlResource($resource, true, 1);
}
// 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";
}
示例8: 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";
}