/** * * @param STRING $elementName * @access private */ function getElementText($elementName) { $namespace = RDF_Util::guessNamespace($elementName); $localName = RDF_Util::guessName($elementName); if ($namespace == "") { return $localName; } $prefix = array_search($namespace, $this->m_namespaces); if ($prefix === false) { $errmsg = "Prefix for element '{$elementName}' cannot be found."; return RDF::raiseError(RDF_ERROR, null, null, $errmsg); } if ($prefix != RDF_NAMESPACE_PREFIX) { return $prefix . ':' . $localName; } else { return $this->rdf_qname_prefix . $localName; } }
/** * Add the given model to this Model_MDB. * This function monitors for SQL errors, and will commit if no errors have occured, * otherwise it will rollback. * If any statement of the model to be added to this model contains a blankNode * with an identifier already existing in this model, a new blankNode is generated. * * @param object Model $model * @throw PhpError * @access public */ function addModel(&$model) { if (!is_a($model, 'RDF_Model')) { $errmsg = 'Model expected, got unexpected: ' . (is_object($model) ? get_class($model) : gettype($model)); return RDF::raiseError(RDF_ERROR_UNEXPECTED, null, null, $errmsg); } $blankNodes_tmp = array(); if (is_a($model, 'RDF_Model_Memory')) { $this->dbConn->autoCommit(false); foreach ($model->triples as $statement) { $this->_addStatementFromAnotherModel($statement, $blankNodes_tmp); } $this->dbConn->commit(); $this->dbConn->autoCommit(true); } elseif (is_a($model, 'RDF_Model_MDB')) { $this->dbConn->autoCommit(false); $Model_Memory =& $model->getMemModel(); foreach ($Model_Memory->triples as $statement) { $this->_addStatementFromAnotherModel($statement, $blankNodes_tmp); } $this->dbConn->commit(); $this->dbConn->autoCommit(true); } }
function factory() { $errmsg = 'Not implemented'; return RDF::raiseError(RDF_ERROR, null, null, $errmsg); }
/** * Generates a new Model_Memory from a URI, a file or from memory. * If you want to parse an RDF document, pass the URI or location in the filesystem * of the RDF document. You can also pass RDF code direct to the function. If you pass * RDF code directly to the parser and there is no xml:base included, you should set * the base URI manually using the optional second parameter $rdfBaseURI. * Make sure that here are proper namespace declarations in your input document. * * @access public * @param string $base * @param boolean $rdfBaseURI * @return object Model_Memory */ function &generateModel($base, $rdfBaseURI = false) { // Check if $base is a URI or filename or a string containing RDF code. if (substr(ltrim($base), 0, 1) != '<') { // $base is URL or filename $this->model =& new RDF_Model_Memory($base); $input = @fopen($base, 'r'); if (!$input) { $errmsg = "RDF Parser: Could not open File: {$base}. Stopped parsing."; return RDF::raiseError(RDF_ERROR, null, null, $errmsg); } $this->rdf_parser_create(null); $this->rdf_set_base($base); $done = false; while (!$done) { $buf = fread($input, 512); $done = feof($input); if (!$this->rdf_parse($buf, feof($input))) { $err_code = xml_get_error_code($this->rdf_get_xml_parser()); $line = xml_get_current_line_number($this->rdf_get_xml_parser()); $errmsg = 'XML-parser-error ' . $err_code . ' in Line ' . $line . ' of input document.'; return RDF::raiseError(RDF_ERROR, null, null, $errmsg); } } /* close file. */ fclose($input); } else { // $base is RDF string $this->model =& new RDF_Model_Memory(); $this->rdf_parser_create(null); if ($rdfBaseURI !== false) { $this->rdf_set_base($rdfBaseURI); } else { $this->rdf_set_base(null); } if (!$this->rdf_parse($base, true)) { $err_code = xml_get_error_code($this->rdf_get_xml_parser()); $line = xml_get_current_line_number($this->rdf_get_xml_parser()); $errmsg = RDF_ERROR . '(class: parser; method: generateModel): XML-parser-error ' . $err_code . ' in Line ' . $line . ' of input document.'; return RDF::raiseError(RDF_RDQL_ERR, null, null, $errmsg); } } // base_uri could have changed while parsing $this->model->setBaseURI($this->rdf_parser['base_uri']); $this->rdf_parser_free(); return $this->model; }
/** * Set the object of the triple. * * @access public * @return object node */ function setObject($obj) { if (!(is_a($obj, 'RDF_Resource') or is_a($obj, 'RDF_Literal'))) { $errmsg = 'Resource or Literal expected as object, got unexpected: ' . (is_object($obj) ? get_class($obj) : gettype($obj)); return RDF::raiseError(RDF_ERROR_UNEXPECTED, null, null, $errmsg); } $this->obj = $obj; }