Example #1
0
 /**
  * @todo Implement testInitWithIri().
  */
 public function testInitWithIri()
 {
     $r = Erfurt_Rdf_Resource::initWithIri('http://example.org/resourceXX');
     $this->assertTrue($r instanceof Erfurt_Rdf_Resource);
     $this->assertEquals('http://example.org/resourceXX', $r->getUri());
     $this->assertEquals('http://example.org/', $r->getNamespace());
     $this->assertEquals('resourceXX', $r->getLocalName());
 }
Example #2
0
 /**
  * Parses a String to an RDF node.
  *
  * @param  string $node
  * @return Erfurt_Rdf_Node The parsed RDF node
  * @throws Erfurt_Sparql_ParserException
  */
 protected function _parseNode($node = false)
 {
     if ($node) {
         $node = $node;
     } else {
         $node = current($this->_tokens);
     }
     if ($node[strlen($node) - 1] === '.') {
         $node = substr($node, 0, -1);
     }
     if ($this->_dtypeCheck($node)) {
         return $node;
     }
     if ($this->_bNodeCheck($node)) {
         $node = '?' . $node;
         if (isset($this->_usedBlankNodes[$node]) && $this->_usedBlankNodes[$node] === false) {
             require_once 'Erfurt/Sparql/ParserException.php';
             throw new Erfurt_Sparql_ParserException('Reuse of blank node id not allowed here.' - 1, key($this->_tokens));
         }
         $this->_query->addUsedVar($node);
         $this->_usedBlankNodes[$node] = true;
         return $node;
     }
     if ($node === '[') {
         $node = '?' . substr($this->_query->getBlanknodeLabel(), 1);
         $this->_query->addUsedVar($node);
         $this->_fastForward();
         if (current($this->_tokens) !== ']') {
             prev($this->_tokens);
         }
         return $node;
     }
     if ($this->_iriCheck($node)) {
         $base = $this->_query->getBase();
         if ($base != null) {
             require_once 'Erfurt/Rdf/Resource.php';
             $node = Erfurt_Rdf_Resource::initWithNamespaceAndLocalName(substr($base, 1, -1), substr($node, 1, -1));
         } else {
             require_once 'Erfurt/Rdf/Resource.php';
             $node = Erfurt_Rdf_Resource::initWithIri(substr($node, 1, -1));
         }
         return $node;
     } else {
         if ($this->_qnameCheck($node)) {
             $node = $this->_query->getFullUri($node);
             require_once 'Erfurt/Rdf/Resource.php';
             $node = Erfurt_Rdf_Resource::initWithIri($node);
             return $node;
         } else {
             if ($this->_literalCheck($node)) {
                 if (substr($node, 0, 1) === '"' || substr($node, 0, 1) === "'") {
                     $ch = substr($node, 0, 1);
                     $chLong = str_repeat($ch, 3);
                     if (substr($node, 0, 3) == $chLong) {
                         $ch = $chLong;
                     }
                     $this->_parseLiteral($node, $ch);
                 } else {
                     $this->_parseLiteral($node, null);
                 }
             } else {
                 if ($this->_varCheck($node)) {
                     $pos = is_string($node) ? strpos($node, '.') : false;
                     if ($pos) {
                         return substr($node, 0, $pos);
                     } else {
                         return $node;
                     }
                 } else {
                     if ($node[0] === '<') {
                         //partial IRI? loop tokens until we find a closing >
                         while (next($this->_tokens)) {
                             $node .= current($this->_tokens);
                             if (substr($node, -1) === '>') {
                                 break;
                             }
                         }
                         if (substr($node, -1) != '>') {
                             var_dump($this->_tokens);
                             exit;
                             require_once 'Erfurt/Sparql/ParserException.php';
                             throw new Erfurt_Sparql_ParserException('Unclosed IRI: ' . $node, -1, key($this->_tokens));
                         }
                         return $this->_parseNode($node);
                     } else {
                         require_once 'Erfurt/Sparql/ParserException.php';
                         throw new Erfurt_Sparql_ParserException('"' . $node . '" is neither a valid rdf- node nor a variable.', -1, key($this->_tokens));
                     }
                 }
             }
         }
     }
     return $node;
 }
Example #3
0
 protected function _parseUri()
 {
     $this->_read();
     $c = $this->_read();
     $token = '';
     while ($c !== -1 && $c !== '>') {
         $token .= $c;
         $c = $this->_read();
     }
     #$c = $this->_skipWS();
     $uri = $this->_resolveUri($this->_decodeString($token, true));
     require_once 'Erfurt/Rdf/Resource.php';
     return Erfurt_Rdf_Resource::initWithIri($uri);
 }