/** * Parses a String to an RDF node. * * @param String $node * * @return Node The parsed RDF node * @throws SparqlParserException */ protected function parseNode($node = false) { //$eon = 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; $this->query->addUsedVar($node); 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) { $node = new Resource(substr(substr($base, 0, -1) . substr($node, 1), 1, -1)); } else { $node = new Resource(substr($node, 1, -1)); } return $node; } else { if ($this->qnameCheck($node)) { $node = $this->query->getFullUri($node); $node = new Resource($node); return $node; } else { if ($this->literalCheck($node)) { $ch = substr($node, 0, 1); $chLong = str_repeat($ch, 3); if (substr($node, 0, 3) == $chLong) { $ch = $chLong; } $this->parseLiteral($node, $ch); } else { if ($this->varCheck($node)) { $pos = strpos($node, '.'); 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) != '>') { throw new SparqlParserException("Unclosed IRI: " . $node, null, key($this->tokens)); } return $this->parseNode($node); } else { throw new SparqlParserException('"' . $node . '" is neither a valid rdf- node nor a variable.', null, key($this->tokens)); } } } } } return $node; }