Пример #1
0
 public function testInitWithLabelAndLanguage()
 {
     $literal1 = Erfurt_Rdf_Literal::initWithLabelAndLanguage("Testliteral1", "de");
     $literal2 = Erfurt_Rdf_Literal::initWithLabelAndLanguage("Testliteral2", "en");
     $this->assertSame("Testliteral1", $literal1->getLabel());
     $this->assertSame("Testliteral2", $literal2->getLabel());
     $this->assertSame("de", $literal1->getLanguage());
     $this->assertSame("en", $literal2->getLanguage());
 }
Пример #2
0
 /**
  * Checks if there is a datatype given and appends it to the node.
  *
  * @param string $node Node to check
  */
 protected function _checkDtypeLang(&$node, $nSubstrLength = 1)
 {
     $this->_fastForward();
     switch (substr(current($this->_tokens), 0, 1)) {
         case '^':
             if (substr(current($this->_tokens), 0, 2) === '^^') {
                 if (strlen(current($this->_tokens)) === 2) {
                     next($this->_tokens);
                 }
                 require_once 'Erfurt/Rdf/Literal.php';
                 $node = Erfurt_Rdf_Literal::initWithLabel(substr($node, 1, -1));
                 $node->setDatatype($this->_query->getFullUri(substr(current($this->_tokens), 2)));
             }
             break;
         case '@':
             require_once 'Erfurt/Rdf/Literal.php';
             $node = Erfurt_Rdf_Literal::initWithLabelAndLanguage(substr($node, $nSubstrLength, -$nSubstrLength), substr(current($this->_tokens), $nSubstrLength));
             break;
         default:
             prev($this->_tokens);
             require_once 'Erfurt/Rdf/Literal.php';
             $node = Erfurt_Rdf_Literal::initWithLabel(substr($node, $nSubstrLength, -$nSubstrLength));
             break;
     }
 }
Пример #3
0
 protected function _parseQuotedLiteral()
 {
     $label = $this->_parseQuotedString();
     $c = $this->_peek();
     if ($c === '@') {
         $this->_read();
         $lang = '';
         $c = $this->_read();
         if (!$this->_isLanguageStartChar($c)) {
             throw new Erfurt_Syntax_RdfParserException('Character "' . $c . '" not allowed as starting char in language tags.');
         }
         $lang .= $c;
         $c = $this->_read();
         while ($c !== -1 && !$this->_isWS($c) && !($c === ',') && !($c === '.')) {
             if (!$this->_isLanguageChar($c)) {
                 throw new Erfurt_Syntax_RdfParserException('Character "' . $c . '" not allowed in language tags.');
             }
             $lang .= $c;
             $c = $this->_read();
         }
         $this->_unread();
         require_once 'Erfurt/Rdf/Literal.php';
         return Erfurt_Rdf_Literal::initWithLabelAndLanguage($label, $lang);
     } else {
         if ($c === '^') {
             $this->_read();
             $this->_verifyChar($this->_read(), '^');
             $datatype = $this->_parseValue();
             if ($datatype instanceof Erfurt_Rdf_Resource) {
                 require_once 'Erfurt/Rdf/Literal.php';
                 return Erfurt_Rdf_Literal::initWithLabelAndDatatype($label, (string) $datatype);
             } else {
                 $this->_throwException('Illegal datatype value.');
                 return null;
             }
         } else {
             require_once 'Erfurt/Rdf/Literal.php';
             return Erfurt_Rdf_Literal::initWithLabel($label);
         }
     }
 }