public function testInitWithLabelAndDatatype() { $literal1 = Erfurt_Rdf_Literal::initWithLabelAndDatatype("true", "http://www.w3.org/2001/XMLSchema#boolean"); $literal2 = Erfurt_Rdf_Literal::initWithLabelAndDatatype("Testliteral2", "http://www.w3.org/2001/XMLSchema#string"); $this->assertSame("true", $literal1->getLabel()); $this->assertSame("Testliteral2", $literal2->getLabel()); $this->assertSame("http://www.w3.org/2001/XMLSchema#boolean", $literal1->getDatatype()); $this->assertSame("http://www.w3.org/2001/XMLSchema#string", $literal2->getDatatype()); }
public static function initWithArray($array) { if ($array['type'] != 'literal') { throw new Erfurt_Exception('Array not a literal.'); } $l = new Erfurt_Rdf_Literal($array['value']); if (isset($array['lang'])) { $l->setLanguage($array['lang']); } else { if (isset($array['xml:lang'])) { $l->setLanguage($array['xml:lang']); } else { if (isset($array['datatype'])) { $l->setDatatype($array['datatype']); } } } return $l; }
/** * Parses a literal. * * @param string $node * @param string $sep used separator " or ' */ protected function _parseLiteral(&$node, $sep) { if ($sep !== null) { do { next($this->_tokens); $node = $node . current($this->_tokens); } while (current($this->_tokens) != $sep); $this->_checkDtypeLang($node, strlen($sep)); } else { $datatype = ''; if (is_string($node) && strpos($node, '.') !== false) { $datatype = EF_XSD_NS . 'integer'; } else { $datatype = EF_XSD_NS . 'decimal'; } require_once 'Erfurt/Rdf/Literal.php'; $node = Erfurt_Rdf_Literal::initWithLabel($node); $node->setDatatype($datatype); } }
protected function _parseQNameOrBoolean() { $c = $this->_read(); #if ($c !== ':' && !$this->_isPrefixStartChar($c)) { # $this->_throwException('Expected ":" or letter.'); #} $namespace = null; if ($c === ':') { // QName with default namespace if (isset($this->_namespaces[''])) { $namespace = $this->_namespaces['']; } else { $this->_throwException('Default namespace used, but not defined.'); } } else { $prefix = $c; $c = $this->_read(); while ($c !== -1 && !$this->_isWS($c) && $c !== ':') { $prefix .= $c; $c = $this->_read(); } if ($c !== ':') { // Prefix might be a boolean value. $value = $prefix; if ($prefix === 'true' || $prefix === 'false') { require_once 'Erfurt/Rdf/Literal.php'; return Erfurt_Rdf_Literal::initWithLabelAndDatatype($value, EF_XSD_BOOLEAN); } } $this->_verifyChar($c, ':'); if (isset($this->_namespaces[$prefix])) { $namespace = $this->_namespaces[$prefix]; } else { $this->_throwException("Namespace '{$prefix}' used, but not defined."); } } $localName = ''; $c = $this->_read(); while ($c !== -1 && !$this->_isWS($c) && $c !== ',' && $c !== ';' && $c !== ')') { $localName .= $c; $c = $this->_read(); } $this->_unread(); require_once 'Erfurt/Rdf/Resource.php'; return Erfurt_Rdf_Resource::initWithNamespaceAndLocalName($namespace, $localName); }