You are here

class EasyRdf_Parser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php \EasyRdf_Parser

Parent class for the EasyRdf parsers

@package EasyRdf @copyright Copyright (c) 2009-2013 Nicholas J Humfrey @license http://www.opensource.org/licenses/bsd-license.php

Hierarchy

Expanded class hierarchy of EasyRdf_Parser

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php, line 45

View source
class EasyRdf_Parser {

  /** Mapping from source to graph bnode identifiers */
  private $bnodeMap = array();

  /** The current graph to insert triples into */
  protected $graph = null;

  /** The format of the document currently being parsed */
  protected $format = null;

  /** The base URI for the document currently being parsed */
  protected $baseUri = null;
  protected $tripleCount = 0;

  /**
   * Create a new, unique bnode identifier from a source identifier.
   * If the source identifier has previously been seen, the
   * same new bnode identifier is returned.
   * @ignore
   */
  protected function remapBnode($name) {
    if (!isset($this->bnodeMap[$name])) {
      $this->bnodeMap[$name] = $this->graph
        ->newBNodeId();
    }
    return $this->bnodeMap[$name];
  }

  /**
   * Delete the bnode mapping - to be called at the start of a new parse
   * @ignore
   */
  protected function resetBnodeMap() {
    $this->bnodeMap = array();
  }

  /**
   * Check, cleanup parameters and prepare for parsing
   * @ignore
   */
  protected function checkParseParams($graph, $data, $format, $baseUri) {
    if ($graph == null or !is_object($graph) or !$graph instanceof EasyRdf_Graph) {
      throw new InvalidArgumentException("\$graph should be an EasyRdf_Graph object and cannot be null");
    }
    else {
      $this->graph = $graph;
    }
    if ($format == null or $format == '') {
      throw new InvalidArgumentException("\$format cannot be null or empty");
    }
    elseif (is_object($format) and $format instanceof EasyRdf_Format) {
      $this->format = $format = $format
        ->getName();
    }
    elseif (!is_string($format)) {
      throw new InvalidArgumentException("\$format should be a string or an EasyRdf_Format object");
    }
    else {
      $this->format = $format;
    }
    if ($baseUri) {
      if (!is_string($baseUri)) {
        throw new InvalidArgumentException("\$baseUri should be a string");
      }
      else {
        $this->baseUri = new EasyRdf_ParsedUri($baseUri);
      }
    }
    else {
      $this->baseUri = null;
    }

    // Prepare for parsing
    $this
      ->resetBnodeMap();
    $this->tripleCount = 0;
  }

  /**
   * Sub-classes must follow this protocol
   * @ignore
   */
  public function parse($graph, $data, $format, $baseUri) {
    throw new EasyRdf_Exception("This method should be overridden by sub-classes.");
  }

  /**
   * Add a triple to the current graph, and keep count of the number of triples
   * @ignore
   */
  protected function addTriple($resource, $property, $value) {
    $count = $this->graph
      ->add($resource, $property, $value);
    $this->tripleCount += $count;
    return $count;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EasyRdf_Parser::$baseUri protected property The base URI for the document currently being parsed
EasyRdf_Parser::$bnodeMap private property Mapping from source to graph bnode identifiers
EasyRdf_Parser::$format protected property The format of the document currently being parsed
EasyRdf_Parser::$graph protected property The current graph to insert triples into
EasyRdf_Parser::$tripleCount protected property
EasyRdf_Parser::addTriple protected function Add a triple to the current graph, and keep count of the number of triples @ignore 1
EasyRdf_Parser::checkParseParams protected function Check, cleanup parameters and prepare for parsing @ignore
EasyRdf_Parser::parse public function Sub-classes must follow this protocol @ignore 6
EasyRdf_Parser::remapBnode protected function Create a new, unique bnode identifier from a source identifier. If the source identifier has previously been seen, the same new bnode identifier is returned. @ignore
EasyRdf_Parser::resetBnodeMap protected function Delete the bnode mapping - to be called at the start of a new parse @ignore