class EasyRdf_Parser_Rapper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rapper.php \EasyRdf_Parser_Rapper
Class to parse RDF using the 'rapper' command line tool.
@package EasyRdf @copyright Copyright (c) 2009-2013 Nicholas J Humfrey @license http://www.opensource.org/licenses/bsd-license.php
Hierarchy
- class \EasyRdf_Parser
- class \EasyRdf_Parser_RdfPhp
- class \EasyRdf_Parser_Json
- class \EasyRdf_Parser_Rapper
- class \EasyRdf_Parser_Json
- class \EasyRdf_Parser_RdfPhp
Expanded class hierarchy of EasyRdf_Parser_Rapper
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Rapper.php, line 45
View source
class EasyRdf_Parser_Rapper extends EasyRdf_Parser_Json {
private $rapperCmd = null;
const MINIMUM_RAPPER_VERSION = '1.4.17';
/**
* Constructor
*
* @param string $rapperCmd Optional path to the rapper command to use.
* @return object EasyRdf_Parser_Rapper
*/
public function __construct($rapperCmd = 'rapper') {
$result = exec("{$rapperCmd} --version 2>/dev/null", $output, $status);
if ($status != 0) {
throw new EasyRdf_Exception("Failed to execute the command '{$rapperCmd}': {$result}");
}
elseif (version_compare($result, self::MINIMUM_RAPPER_VERSION) < 0) {
throw new EasyRdf_Exception("Version " . self::MINIMUM_RAPPER_VERSION . " or higher of rapper is required.");
}
else {
$this->rapperCmd = $rapperCmd;
}
}
/**
* Parse an RDF document into an EasyRdf_Graph
*
* @param object EasyRdf_Graph $graph the graph to load the data into
* @param string $data the RDF document data
* @param string $format the format of the input data
* @param string $baseUri the base URI of the data being parsed
* @return integer The number of triples added to the graph
*/
public function parse($graph, $data, $format, $baseUri) {
parent::checkParseParams($graph, $data, $format, $baseUri);
$json = EasyRdf_Utils::execCommandPipe($this->rapperCmd, array(
'--quiet',
'--input',
$format,
'--output',
'json',
'--ignore-errors',
'--input-uri',
$baseUri,
'--output-uri',
'-',
'-',
), $data);
// Parse in the JSON
return parent::parse($graph, $json, 'json', $baseUri);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EasyRdf_Parser:: |
protected | property | The base URI for the document currently being parsed | |
EasyRdf_Parser:: |
private | property | Mapping from source to graph bnode identifiers | |
EasyRdf_Parser:: |
protected | property | The format of the document currently being parsed | |
EasyRdf_Parser:: |
protected | property | The current graph to insert triples into | |
EasyRdf_Parser:: |
protected | property | ||
EasyRdf_Parser:: |
protected | function | Add a triple to the current graph, and keep count of the number of triples @ignore | 1 |
EasyRdf_Parser:: |
protected | function | Check, cleanup parameters and prepare for parsing @ignore | |
EasyRdf_Parser:: |
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:: |
protected | function | Delete the bnode mapping - to be called at the start of a new parse @ignore | |
EasyRdf_Parser_Json:: |
private | property | ||
EasyRdf_Parser_Json:: |
protected | function | Return the last JSON parser error as a string | |
EasyRdf_Parser_Json:: |
protected | function | Parse the triple-centric JSON format, as output by libraptor | |
EasyRdf_Parser_Rapper:: |
private | property | ||
EasyRdf_Parser_Rapper:: |
constant | |||
EasyRdf_Parser_Rapper:: |
public | function |
Parse an RDF document into an EasyRdf_Graph Overrides EasyRdf_Parser_Json:: |
|
EasyRdf_Parser_Rapper:: |
public | function |
Constructor Overrides EasyRdf_Parser_Json:: |