You are here

protected function EasyRdf_Parser_Ntriples::parseNtriplesObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php \EasyRdf_Parser_Ntriples::parseNtriplesObject()

@ignore

1 call to EasyRdf_Parser_Ntriples::parseNtriplesObject()
EasyRdf_Parser_Ntriples::parse in vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php
Parse an N-Triples document into an EasyRdf_Graph

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php, line 128

Class

EasyRdf_Parser_Ntriples
A pure-php class to parse N-Triples with no dependancies.

Code

protected function parseNtriplesObject($obj, $lineNum) {
  if (preg_match('/"(.+)"\\^\\^<([^<>]+)>/', $obj, $matches)) {
    return array(
      'type' => 'literal',
      'value' => $this
        ->unescapeString($matches[1]),
      'datatype' => $this
        ->unescapeString($matches[2]),
    );
  }
  elseif (preg_match('/"(.+)"@([\\w\\-]+)/', $obj, $matches)) {
    return array(
      'type' => 'literal',
      'value' => $this
        ->unescapeString($matches[1]),
      'lang' => $this
        ->unescapeString($matches[2]),
    );
  }
  elseif (preg_match('/"(.*)"/', $obj, $matches)) {
    return array(
      'type' => 'literal',
      'value' => $this
        ->unescapeString($matches[1]),
    );
  }
  elseif (preg_match('/<([^<>]+)>/', $obj, $matches)) {
    return array(
      'type' => 'uri',
      'value' => $matches[1],
    );
  }
  elseif (preg_match('/_:([A-Za-z0-9]*)/', $obj, $matches)) {
    if (empty($matches[1])) {
      return array(
        'type' => 'bnode',
        'value' => $this->graph
          ->newBNodeId(),
      );
    }
    else {
      $nodeid = $this
        ->unescapeString($matches[1]);
      return array(
        'type' => 'bnode',
        'value' => $this
          ->remapBnode($nodeid),
      );
    }
  }
  else {
    throw new EasyRdf_Parser_Exception("Failed to parse object: {$obj}", $lineNum);
  }
}