Source for file RdfParser.php
Documentation is available at RdfParser.php
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
* This class reads RDF data from files or URIs and generates models out of it. All valid
* RDF XML syntaxes defined by the W3C in RDF/XML Syntax Specification (Revised)
* - W3C Working Draft 10 October 2003
* (http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20031010/) are supported.
* The parser is based on the PHP version of repat
* (http://phpxmlclasses.sourceforge.net/show_doc.php?class=class_rdf_parser.html)
* by Luis Argerich (lrargerich@yahoo.com).
* @version $Id: fsource_syntax__syntaxRdfParser.php.html 443 2007-06-01 16:25:38Z cax $
* @author Luis Argerich <lrargerich@yahoo.com>,
* Chris Bizer <chris@bizer.de>,
* Radoslaw Oldakowski <radol@gmx.de>
* Daniel Westphal <mail@d-westphal.de>
* converts a string to its unicode NFC form (e.g. \uHHHH or \UHHHHHHHH).
function str2unicode_nfc($str=
""){
/* try to detect encoding */
for($i=
0,$i_max=
strlen($str);$i<
$i_max;$i++
){
$nr=
0;/* unicode dec nr */
/* 110##### 10###### = 192+x 128+x */
$nr=
((ord($utf8_char[0])-
192)*
64) +
(ord($utf8_char[1])-
128);
/* 1110#### 10###### 10###### = 224+x 128+x 128+x */
$nr=
((ord($utf8_char[0])-
224)*
4096) +
((ord($utf8_char[1])-
128)*
64) +
(ord($utf8_char[2])-
128);
/* 1111#### 10###### 10###### 10###### = 240+x 128+x 128+x 128+x */
$nr=
((ord($utf8_char[0])-
240)*
262144) +
((ord($utf8_char[1])-
128)*
4096) +
((ord($utf8_char[2])-
128)*
64) +
(ord($utf8_char[3])-
128);
/* result (see http://www.w3.org/TR/rdf-testcases/#ntrip_strings) */
if($nr<
9){/* #x0-#x8 (0-8) */
$result.=
"\\u".
sprintf("%04X",$nr);
elseif($nr==
9){/* #x9 (9) */
elseif($nr==
10){/* #xA (10) */
elseif($nr<
13){/* #xB-#xC (11-12) */
$result.=
"\\u".
sprintf("%04X",$nr);
elseif($nr==
13){/* #xD (13) */
elseif($nr<
32){/* #xE-#x1F (14-31) */
$result.=
"\\u".
sprintf("%04X",$nr);
elseif($nr<
34){/* #x20-#x21 (32-33) */
elseif($nr==
34){/* #x22 (34) */
elseif($nr<
92){/* #x23-#x5B (35-91) */
elseif($nr==
92){/* #x5C (92) */
elseif($nr<
127){/* #x5D-#x7E (93-126) */
elseif($nr<
65536){/* #x7F-#xFFFF (128-65535) */
$result.=
"\\u".
sprintf("%04X",$nr);
elseif($nr<
1114112){/* #x10000-#x10FFFF (65536-1114111) */
$result.=
"\\U".
sprintf("%08X",$nr);
/* other chars are not defined => ignore */
$e['parent']=
Array(); // Parent is a blank Array
$e['has_property_atributes']=
0;
$e['has_member_attributes']=
0;
$e['element_base_uri'] =
'';
* @param string &$destination
function _copy_element($source, &$destination )
$destination['parent'] =
$source;
$destination['state'] =
$source['state'];
$destination['xml_lang'] =
$source['xml_lang'];
$destination['element_base_uri'] =
$source['element_base_uri'];
function _clear_element(&$e)
if(isset
($e['parent'])) {
if( $e['parent']['xml_lang'] !=
$e['xml_lang'] )
$e['has_property_attributes']=
0;
$e['has_member_attributes']=
0;
$e['element_base_uri'] =
'';
if(isset
($e['parent'])) {
$e =
$this->_new_element();
$this->_copy_element( $this->rdf_parser['top'], $e );
$this->_clear_element( $e );
* @param string $local_name
function _is_rdf_property_attribute_resource($local_name )
* @param string $local_name
function _is_rdf_property_attribute_literal($local_name )
* @param string $local_name
function _is_rdf_ordinal( $local_name )
if( $local_name{0} ==
'_' )
$ordinal =
substr($local_name,1) +
1 ;
return ( $ordinal >
0 ) ?
$ordinal :
0;
* @param string $local_name
function _is_rdf_property_attribute( $local_name )
return $this->_is_rdf_property_attribute_resource( $local_name )
||
$this->_is_rdf_property_attribute_literal( $local_name );
* @param string $local_name
function _is_rdf_property_element( $local_name )
||
( $local_name{0} ==
'_' );
* @param string $local_name
function _is_forbidden_rdf_property_element ($local_name)
* @param string $local_name
function _is_rdf_node_element( $local_name )
||
( $local_name{0} ==
'_' );
* @param string $local_name
function _is_forbidden_rdf_node_element ($local_name)
function _istalnum($val) {
return ereg("[A-Za-z0-9]",$val);
function _istalpha($val) {
return ereg("[A-Za-z]",$val);
function _is_absolute_uri($uri )
if( $uri &&
$this->_istalpha( $uri{$uri_p} ) )
&&
( $this->_istalnum( $uri{$uri_p} )
||
( $uri{$uri_p} ==
'+' )
||
( $uri{$uri_p} ==
'-' )
||
( $uri{$uri_p} ==
'.' ) ) )
$result =
( $uri{$uri_p} ==
':' );
* This function returns an associative array returning any of the various components of the URL that are present. This includes the
* query - after the question mark ?
* fragment - after the hashmark #
* @param string &$authority
* @param string &$fragment
function _parse_uri($uri,$buffer,&$scheme,&$authority,&$path,&$query,&$fragment ) {
if(isset
($parsed['scheme'])) {
$scheme=
$parsed['scheme'];
if(isset
($parsed['host'])) {
if(isset
($parsed['host'])) {
$authority=
$parsed['host'];
if(isset
($parsed['path'])) {
if(isset
($parsed['query'])) {
if(isset
($parsed['fragment'])) {
$fragment=
$parsed['fragment'];
* @param string $base_uri
* @param string $reference_uri
function _resolve_uri_reference($base_uri,$reference_uri,&$buffer )
if ($reference_uri ==
'')
return ($buffer =
preg_replace("/\#[^\/\\\]*$/", '', $base_uri));
if( $reference_scheme ==
''
&&
$reference_authority ==
''
&&
$reference_query ==
'' )
if( $reference_fragment !=
'' )
if ($base_path ==
'' ||
$base_path ==
'/' ||
$base_path ==
"\\") {
// CB: Changed for base URI
if (!($c==
'#' ||
$c==
':' ||
$c==
'/' ||
$c==
"\\"))
$buffer.=
$reference_fragment;
else if( $reference_scheme !=
'' )
$result_scheme =
$base_scheme;
if( $reference_authority !=
'' )
$result_authority =
$reference_authority;
$result_authority =
$base_authority;
if ($reference_path !=
'')
if ($reference_path{0} ==
'/' ||
$reference_path{0} ==
"\\")
if ($reference_path{1} ==
'/' ||
$reference_path{1} ==
"\\")
$result_path =
$reference_path;
$result_path =
$reference_path;
elseif (substr($reference_path, 0, 3) ==
'../' ||
substr($reference_path, 0, 3) ==
'..\\')
$slash =
$reference_path{2};
while($base_path !=
'' &&
( substr($reference_path, 0, 3) ==
'../'
||
substr($reference_path, 0, 3) ==
'..\\'))
$base_path =
preg_replace("/((\/)|(\\\))[^\/\\\]*$/", '', $base_path);
$base_path =
preg_replace("/((\/)|(\\\))[^\/\\\]*$/", '', $base_path);
$reference_path =
substr($reference_path, 3);
$result_path =
$base_path .
$slash .
$reference_path;
$result_path =
preg_replace("/[^\/\\\]*$/", $reference_path, $base_path, 1);
$result_path =
'/' .
$reference_path;
if( $result_scheme !=
'' )
if( $result_authority !=
'' )
$buffer.=
$result_authority;
if( $reference_query !=
'' )
$buffer.=
$reference_query;
if( $reference_fragment !=
'' )
$buffer.=
$reference_fragment;
* IDs which contain CombiningChars or Extenders
* (see http://www.w3.org/TR/REC-xml-names/#NT-NCName) are assumed to be invalid.
* If you want to use IDs containing these characters you can turn off
* the validating by setting the constant VALIDATE_IDS to FALSE (see constants.php).
function is_valid_id($id )
if( $this->_istalpha($id{0}) ||
$id{0} ==
'_')
while( $result !=
FALSE && ++
$i <
$len )
if( !($this->_istalnum( $id{$i})
$this->_report_error('illegal ID, nodeID or bagID attribute value');
function _resolve_id($id,&$buffer )
if( $this->is_valid_id($id) )
$this->_resolve_uri_reference( $this->rdf_get_base(), $id_buffer, $buffer );
* @param string &$namespace_uri
* @param string &$local_name
function _split_name($name, &$buffer, &$namespace_uri, &$local_name )
if( strstr( $buffer, NAMESPACE_SEPARATOR_CHAR ) )
$cosas=
explode(NAMESPACE_SEPARATOR_CHAR,$buffer);
$namespace_uri =
$cosas[0];
if( ( $buffer{ 0 } ==
'x' )
&&
( $buffer{ 1 } ==
'm' )
&&
( $buffer{ 2 } ==
'l' )
&&
( $buffer{ 3 } ==
':' ) )
$local_name =
substr($buffer,4);
function _generate_anonymous_uri(&$buf )
* @param string $subject_type
* @param string $predicate
* @param string $object_type
* @param string $xml_lang
* @param string $statements
* @param string $statement_id
function _report_statement( $subject_type, $subject, $predicate, $ordinal, $object_type, $object, $xml_lang, $bag_id, $statements, $statement_id, $datatype )
$xml_lang =
$this->rdf_parser['document_xml_lang'];
$this->add_statement_to_model($this->rdf_parser['user_data'],$subject_type,$subject,$predicate,$ordinal,$object_type,$object,$xml_lang, $datatype );
$this->_generate_anonymous_uri( $statement_id_buffer );
$statement_id =
$statement_id_buffer;
$predicate_buffer=
'RDF_NAMESPACE_URI_'.
$statements;
$this->_report_statement(
// rdf:type = rdf:Statement
$this->_report_statement(
$this->_report_statement(
$this->_report_statement(
$this->_report_statement(
* @param string $subject_type
* @param string $attributes
* @param string $xml_lang
* @param string $statements
function _handle_property_attributes($subject_type, $subject, $attributes, $xml_lang, $bag_id, $statements )
$attribute_namespace_uri=
'';
$attribute_local_name=
'';
for( $i =
0; isset
($attributes[ $i ]); $i +=
2 )
$attribute_namespace_uri,
$attribute_value =
$attributes[ $i +
1 ];
$predicate=
$attribute_namespace_uri;
$predicate.=
$attribute_local_name;
if( $this->_is_rdf_property_attribute_literal( $attribute_local_name ) )
$this->_report_statement(
else if( $this->_is_rdf_property_attribute_resource( $attribute_local_name ) )
$this->_report_statement(
else if( ( $ordinal =
$this->_is_rdf_ordinal( $attribute_local_name ) ) !=
0 )
$this->_report_statement(
else if ( ($attribute_local_name !=
RDF_ABOUT)
&&
($attribute_local_name !=
RDF_RDF)
&&
($attribute_local_name !=
RDF_ID)
&&
($attribute_local_name !=
RDF_LI)
&&
($attribute_local_name !=
RDF_NIL)
$this->_report_statement(
if ($attribute_local_name ==
'base')
$this->rdf_parser['top']['element_base_uri'] =
$attribute_value;
else if( $attribute_namespace_uri )
// is it required that property attributes be in an explicit namespace?
$this->_report_statement(
function _report_warning($warning)
$errmsg =
RDFAPI_ERROR .
'(class: parser): ' .
$warning .
'.';
* @param string $namespace_uri
* @param string $local_name
* @param string $attributes
function _handle_resource_element( $namespace_uri, $local_name, $attributes, $parent )
foreach($attributes as $atkey=>
$atvalue) {
$attribute_namespace_uri=
'';
$attribute_local_name=
'';
$this->rdf_parser['top']['has_property_attributes'] =
false;
$this->rdf_parser['top']['has_member_attributes'] =
false;
if( ! $this->_is_rdf_node_element( $local_name ) )
$msg =
'unknown or out of context rdf node element: '.
$local_name;
if ($this->_is_forbidden_rdf_node_element($local_name))
$this->_report_warning($msg);
// examine each attribute for the standard RDF "keywords"
for( $i =
0; isset
($attributes[$i]); $i +=
2 )
$attribute_namespace_uri,
$attribute_value =
$attributes[ $i +
1 ];
// if the attribute is not in any namespace
// or the attribute is in the RDF namespace
if( ( $attribute_namespace_uri ==
'' )
if( $attribute_local_name ==
RDF_ID )
} else if( $attribute_local_name ==
RDF_ABOUT ) {
$about =
'_'.
$attribute_value;
$node_id =
$attribute_value;
$error =
'aboutEach has been removed from the RDF specifications';
$error =
'aboutEachPrefix has been removed from the RDF specifications';
$bag_id =
$attribute_value;
$datatype =
$attribute_value;
} else if( $this->_is_rdf_property_attribute( $attribute_local_name )) {
$this->rdf_parser['top']['has_property_attributes'] =
true;
} else if( $this->_is_rdf_ordinal( $attribute_local_name )) {
$this->rdf_parser['top']['has_property_attributes'] =
true;
$this->rdf_parser['top']['has_member_attributes'] =
true;
$this->rdf_parser['top']['has_property_attributes'] =
true;
$msg =
'unknown or out of context rdf attribute: '.
$attribute_local_name;
$this->_report_warning($msg);
$this->rdf_parser['top']['xml_lang'] =
$attribute_value;
elseif ($attribute_local_name ==
'base')
$this->rdf_parser['top']['element_base_uri'] =
$attribute_value;
else if( $attribute_namespace_uri )
$this->rdf_parser['top']['has_property_attributes'] =
true;
// if no subjects were found, generate one.
if( $subjects_found ==
0 )
$this->_generate_anonymous_uri( $id_buffer );
else if( $subjects_found >
1 )
$this->_report_error('ID, about and nodeID are mutually exclusive');
$this->_resolve_id( $id, $id_buffer );
$this->_resolve_uri_reference( $this->rdf_get_base(), substr($about,1), $id_buffer );
$this->is_valid_id($node_id);
// if the subject is empty, assign it the document uri
$this->rdf_parser['top']['subject']=
$this->rdf_get_base();
$this->_resolve_id( $bag_id, $id_buffer );
// only report the type for non-rdf:Description elements.
$this->_report_statement(
// if this element is the child of some property,
// report the appropriate statement.
$this->_report_statement(
$parent['parent']['subject_type'],
$parent['parent']['subject'],
$parent['parent']['bag_id'],
$parent['parent']['statements'],
if( $this->rdf_parser['top']['has_property_attributes'] )
$this->_handle_property_attributes(
* @param string &$namespace_uri
* @param string &$local_name
* @param string &$attributes
function _handle_property_element( &$namespace_uri, &$local_name, &$attributes )
foreach($attributes as $atkey=>
$atvalue) {
$attribute_namespace_uri=
'';
$attribute_local_name=
'';
if( ! $this->_is_rdf_property_element( $local_name ) )
$msg =
'unknown or out of context rdf property element: '.
$local_name;
if ($this->_is_forbidden_rdf_property_element($local_name))
$this->_report_warning($msg);
&&
( $local_name ==
RDF_LI ) )
$this->rdf_parser['top']['has_property_attributes'] =
false;
$this->rdf_parser['top']['has_member_attributes'] =
false;
for( $i =
0; isset
($attributes[$i]); $i +=
2 )
$attribute_namespace_uri,
$attribute_value =
$attributes[$i +
1];
// if the attribute is not in any namespace
// or the attribute is in the RDF namespace
if( ( $attribute_namespace_uri ==
'' )
if( ( $attribute_local_name ==
RDF_ID ) )
$statement_id =
$attribute_value;
$parse_type =
$attribute_value;
$resource =
$attribute_value;
$node_id =
$attribute_value;
$bag_id =
$attribute_value;
$datatype =
$attribute_value;
$this->rdf_parser['top']['datatype'] =
$attribute_value;
else if( $this->_is_rdf_property_attribute( $attribute_local_name ) )
$this->rdf_parser['top']['has_property_attributes'] =
true;
$this->_report_warning('unknown rdf attribute: '.
$attribute_local_name );
$this->rdf_parser['top']['xml_lang'] =
$attribute_value;
elseif ($attribute_local_name ==
'base')
$this->rdf_parser['top']['element_base_uri'] =
$attribute_value;
else if( $attribute_namespace_uri )
$this->rdf_parser['top']['has_property_attributes'] =
true;
$this->_resolve_id($statement_id, $buffer );
$this->is_valid_id($node_id);
$this->_report_error('nodeID and resource are mutually exclusive');
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
$this->_report_error('property elements with rdf:parseType do not allow rdf:resource' );
$this->_report_warning('property elements with rdf:parseType do not allow rdf:bagID' );
if( $this->rdf_parser['top']['has_property_attributes'] )
$this->_report_error('property elements with rdf:parseType do not allow property attributes');
$this->_generate_anonymous_uri( $buffer );
// since we are sure that this is now a resource property we can report it
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
$this->_generate_anonymous_uri( $buffer );
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
$this->rdf_parser['top']['collection']['first_blank_node_id'] =
$buffer;
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
else if( $resource !==
NULL ||
$bag_id ||
$this->rdf_parser['top']['has_property_attributes'] )
$this->_resolve_uri_reference( $this->rdf_get_base(), $resource, $buffer );
$this->_generate_anonymous_uri( $buffer );
// since we are sure that this is now a resource property we can report it.
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
$datatype ); // should we allow IDs?
$this->_resolve_id( $bag_id, $buffer );
if( $this->rdf_parser['top']['has_property_attributes'] )
$this->_handle_property_attributes(
* @param string &$namespace_uri
* @param string &$local_name
* @param string &$attributes
function _handle_collection_element(&$namespace_uri, &$local_name, &$attributes)
foreach($attributes as $atkey=>
$atvalue) {
/* collection construction site
if ( ($namespace_uri == RDF_NAMESPACE_URI || $namespace_uri == '')
&& ($local_name == RDF_DESCRIPTION || $local_name == RDF_LI) )
for( $i = 0; isset($attributes[$i]); $i += 2 )
$attribute_namespace_uri,
$attribute_value = $attributes[ $i + 1 ];
if( $attribute_namespace_uri == '' || $attribute_namespace_uri == RDF_NAMESPACE_URI )
if( $attribute_local_name == RDF_ABOUT ||
$attribute_local_name == RDF_RESOURCE)
$this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_RESOURCE;
elseif ( $attribute_local_name == RDF_NODEID ) {
$this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_BNODE;
$this->rdf_parser['top']['parent']['collection']['object_label'][] = $attribute_value;
for( $i =
0; isset
($attributes[$i]); $i +=
2 )
$attribute_namespace_uri,
$attribute_value =
$attributes[ $i +
1 ];
if( $attribute_namespace_uri ==
'' ||
$attribute_namespace_uri ==
RDF_NAMESPACE_URI )
$this->_resolve_uri_reference( $this->rdf_get_base(), $attribute_value, $id_buffer );
$this->rdf_parser['top']['parent']['collection']['object_label'][] =
$id_buffer;
$this->_report_statement(
$namespace_uri.
$local_name,
// collection construction site
* @param string &$namespace_uri
* @param string &$local_name
* @param string &$attributes
function _handle_xml_start_element(&$namespace_uri, &$local_name, &$attributes)
foreach($attributes as $atkey=>
$atvalue) {
$element =
'<' .
$this->_join_name_and_declare_prefix($namespace_uri, $local_name);
for( $i =
0; isset
($attributes[$i]); $i +=
2 )
$attribute_namespace_uri,
$attribute_value =
$attributes[ $i +
1 ];
$element .=
' ' .
$this->_join_name_and_declare_prefix($attribute_namespace_uri, $attribute_local_name);
$element .=
'=\"' .
$attribute_value .
'\"';
$this->rdf_parser['xml_literal']['buffer'] .=
$element;
function _handle_xml_end_element($name)
if ($namespace_uri && isset
($this->rdf_parser['default_namespace'])
&&
$namespace_uri !=
$this->rdf_parser['default_namespace'])
$element .=
$this->rdf_parser['namespaces'][$namespace_uri] .
':';
$element .=
$local_name .
'>';
$this->rdf_parser['xml_literal']['buffer'] .=
$element;
$depth =
$this->rdf_parser['xml_literal']['depth']--
;
if (isset
($this->rdf_parser['xml_literal']['declared_ns']))
foreach ($this->rdf_parser['xml_literal']['declared_ns'] as $prefix =>
$_depth)
unset
($this->rdf_parser['xml_literal']['declared_ns'][$prefix]);
* @param string $namespace_uri
* @param string $local_name
function _join_name_and_declare_prefix($namespace_uri, $local_name) {
&&
$namespace_uri ==
$this->rdf_parser['default_namespace'])
if (!isset
($this->rdf_parser['xml_literal']['declared_ns']['_DEFAULT_'])
$name .=
' xmlns=' .
'\"' .
$namespace_uri .
'\"';
$this->rdf_parser['xml_literal']['declared_ns']['_DEFAULT_']
$ns_prefix =
$this->rdf_parser['namespaces'][$namespace_uri];
$name .=
$ns_prefix .
':' .
$local_name;
if (!isset
($this->rdf_parser['xml_literal']['declared_ns'][$ns_prefix])
$name .=
" xmlns:$ns_prefix=" .
'\"' .
$namespace_uri .
'\"';
$this->rdf_parser['xml_literal']['declared_ns'][$ns_prefix]
function _end_collection() {
if (isset
($this->rdf_parser['top']['collection']))
$subject =
$this->rdf_parser['top']['collection']['first_blank_node_id'];
for ($i=
0; isset
($this->rdf_parser['top']['collection']['object_label'][$i]); $i++
)
$this->_report_statement(
$this->rdf_parser['top']['collection']['object_type'][$i],
$this->rdf_parser['top']['collection']['object_label'][$i],
if (!isset
($this->rdf_parser['top']['collection']['object_label'][$i+
1]))
$this->_generate_anonymous_uri($object_2);
$this->_report_statement(
* @param string $attributes
function _start_element_handler($parser, $name, $attributes )
// set base_uri, if possible
foreach ($attributes as $key =>
$value) {
if (!($c==
'#' ||
$c==
':' ||
$c==
'/' ||
$c==
"\\"))
$this->rdf_parser['normalized_base_uri'] =
$value .
'#';
$this->rdf_parser['normalized_base_uri'] =
$value;
$this->_handle_resource_element( $namespace_uri, $local_name, $attributes, '' );
$this->_handle_property_element( $namespace_uri, $local_name, $attributes );
$this->_handle_collection_element($namespace_uri, $local_name, $attributes);
/* if we're in a property with an unknown object type and we encounter
an element, the object must be a resource, */
$this->_handle_resource_element(
$this->_report_warning( 'no markup allowed in literals' );
$this->_handle_xml_start_element($namespace_uri, $local_name, $attributes);
'only one element allowed inside a property element' );
'no content allowed in property with rdf:resource, rdf:bagID, or property attributes' );
property elements with text only as content set the state to
IN_PROPERTY_LITERAL. as character data is received from expat,
it is saved in a buffer and reported when the end tag is
function _end_literal_property()
if(!isset
($this->rdf_parser['top']['statement_id'])) {
if(!isset
($this->rdf_parser['top']['parent']['subject_type'])) {
$this->rdf_parser['top']['parent']['subject_type']=
'';
if(!isset
($this->rdf_parser['top']['parent']['subject'])) {
if(!isset
($this->rdf_parser['top']['parent']['bag_id'])) {
if(!isset
($this->rdf_parser['top']['parent']['statements'])) {
$this->rdf_parser['top']['parent']['statements']=
0;
if(!isset
($this->rdf_parser['top']['predicate'])) {
if(!isset
($this->rdf_parser['top']['datatype'])) {
$this->_report_statement(
$this->rdf_parser['top']['parent']['subject_type'],
function _end_element_handler( $parser, $name )
$this->_handle_xml_end_element($name);
$this->_end_literal_property( );
// $search = array((0) => chr(10), (1) => chr(13), (2) => chr(9));
// $replace = array((0) => '\n' , (1) => '\r' , (2) => '\t');
// $this->rdf_parser["xml_literal"]["buffer"]
// = str_replace($search, $replace, $this->rdf_parser["xml_literal"]["buffer"]);
$this->_end_literal_property();
$this->_end_collection();
function _character_data_handler( $parser,$s)
/* look for non-whitespace */
for( $i =
0; (( $i <
$len ) &&
( ereg(" |\n|\t",$s{ $i }) )); $i++
);
/* if we found non-whitespace, this is a literal */
* Adds a new statement to the model
* This method is called by generateModel().
* @param string &$user_data
* @param string $subject_type
* @param string $predicate
* @param string $object_type
* @param string $xml_lang )
* @return object MemModel
function add_statement_to_model(
$subject=
$this->str2unicode_nfc($subject);
$predicate=
$this->str2unicode_nfc($predicate);
$object=
$this->str2unicode_nfc($object);
$objobj->setDatatype($datatype);
elseif ($xml_lang !=
'') {
$objobj->setLanguage($xml_lang);
$statement =
new Statement($objsub, $objpred, $objobj);
// add statement to model
$this->model->addWithoutDuplicates($statement);
$this->model->add($statement);
* Generates a new MemModel 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.
* @param boolean $rdfBaseURI
* @return object MemModel
function & generateModel($base,$rdfBaseURI =
false, $model =
false) {
// Check if $base is a URI or filename or a string containing RDF code.
// $base is URL or filename
$input =
fopen($base,'r') or die("RDF Parser: Could not open File: $base. Stopped parsing.");
$this->rdf_parser_create( NULL );
$this->rdf_set_base($base);
$buf =
fread( $input, 512 );
if ( ! $this->rdf_parse( $buf, feof($input) ) )
$errmsg =
RDFAPI_ERROR .
'(class: parser; method: generateModel): XML-parser-error ' .
$err_code .
' in Line ' .
$line .
' of input document.';
$this->rdf_parser_create( NULL );
$this->rdf_set_base($rdfBaseURI);
$this->rdf_set_base( NULL );
if ( ! $this->rdf_parse( $base, TRUE ) )
$errmsg =
RDFAPI_ERROR .
'(class: parser; method: generateModel): XML-parser-error ' .
$err_code .
' in Line ' .
$line .
' of input document.';
// base_uri could have changed while parsing
$this->rdf_parser_free();
* @param string $encoding
function rdf_parser_create( $encoding )
* @param resource &$parser
* @param string $ns_prefix
function _start_ns_declaration_handler(&$parser, $ns_prefix, $ns_uri)
$this->rdf_parser['namespaces'][$ns_uri] =
$ns_prefix;
function rdf_parser_free( )
* @param string $is_final
function rdf_parse( $s, $is_final )
return XML_Parse( $this->rdf_parser['xml_parser'], $s, $is_final );
function rdf_get_xml_parser()
function rdf_set_base($base )
if (!($c==
'#' ||
$c==
':' ||
$c==
'/' ||
$c==
"\\"))
$this->rdf_parser['normalized_base_uri'] =
$base .
'#';
return $this->rdf_parser['top']['element_base_uri'];
Documentation generated on Fri, 1 Jun 2007 16:50:45 +0200 by phpDocumentor 1.3.2