diff -Naur -x '*~' -x CVS -w rdfapi-php-0.92/api/constants.php rap-anti/api/constants.php
--- rdfapi-php-0.92/api/constants.php 2005-07-04 19:35:38.000000000 +0000
+++ rap-anti/api/constants.php 2006-01-29 01:51:23.000000000 +0000
@@ -138,7 +138,7 @@
// RDF, N3, N-Triple Serializer: set to TRUE in oder to suppres the "Generated by RAP"
// comment in the output files.
-define('HIDE_ADVERTISE',FALSE);
+define('HIDE_ADVERTISE',TRUE);
// RDF Serializer: Set to TRUE, if the serializer should use entities for URIs.
define('SER_USE_ENTITIES', FALSE );
diff -Naur -x '*~' -x CVS -w rdfapi-php-0.92/api/syntax/N3Parser.php rap-anti/api/syntax/N3Parser.php
--- rdfapi-php-0.92/api/syntax/N3Parser.php 2005-06-24 13:15:10.000000000 +0000
+++ rap-anti/api/syntax/N3Parser.php 2005-12-14 02:38:54.000000000 +0000
@@ -35,6 +35,7 @@
*
* History:
*
+ * - 11-08-2005 replace die() with error notice, return false on parse error (evan@wikitravel.org)
*
* - 04-05-2005 toke() function improved by Hannes Gassert hannes.gassert@deri.org
* - 03-25-2005 N3 list processing added by Hannes Gassert hannes.gassert@deri.org
* - 12-06-2004 improved namespace handling added (tobias.gauss@web.de)
@@ -68,7 +69,9 @@
var $RDF_NS, $DAML_NS, $OWL_NS;
var $debug;
var $parseError;
+ var $errors;
var $parsedNamespaces = array();
+ var $baseURI;
/* ==================== Public Methods ==================== */
@@ -109,6 +112,8 @@
$this->bNodeMap = array();
$this->FixBnodes = FIX_BLANKNODES;
$this->parseError=false;
+ $this->errors = array();
+ $this->baseURI = null;
}
@@ -132,6 +137,9 @@
function parse($s) {
// """Get a string, tokenize, create list, convert to Eep store."""
$stat=$this->n3tolist($s);
+ if ($stat === false) {
+ return false;
+ }
foreach ( $stat as $t) {
if (count($t)>3) {
@@ -160,6 +168,9 @@
function uparse($s,$func) {
// """Get a string, tokenize, create list, convert to Eep store."""
$stat=$this->n3tolist($s);
+ if ($stat === false) {
+ return false;
+ }
foreach ( $stat as $t) {
if (count($t)>3) {
@@ -174,6 +185,7 @@
$func($t[0],$t[1],$object);
}
+
// return [[eep.Article(t[0]), eep.Article(t[1]), eep.Article(t[2])]
// for t in n3tolist(s)]
}
@@ -195,11 +207,21 @@
// """Get a string, tokenize, create list, convert to Eep store."""
$stat=$this->n3tolist($s);
+ if ($stat === false) {
+ return $stat;
+ }
foreach ( $stat as $t) {
$s=$this->toRDFNode($t[0],$t);
$p=$this->toRDFNode($t[1],$t);
$o=$this->toRDFNode($t[2],$t);
+ if (is_a($p, 'BlankNode')) {
+ $this->parseError = true;
+ $this->errors[] = "Can't have a blank node as predicate";
+ $fake = false;
+ return $fake;
+ }
+
$new_statement= new Statement($s,$p,$o);
$m->add($new_statement);
@@ -222,7 +244,13 @@
*/
function & generateModel($path,$dummy=false,$model=false) {
- $handle = fopen($path,'r') or die("N3 Parser: Could not open File: '$path' - Stopped parsing.");
+ $handle = fopen($path,'r');
+ if (!$handle) {
+ $this->parseError = true;
+ $this->errors[] = "Could not open file: '$path'";
+ $res = false;
+ return $res;
+ }
$done=false;
$input="";
while(!$done)
@@ -235,7 +263,8 @@
fclose($handle);
- return $this->parse2model($input,$model);
+ $res = $this->parse2model($input,$model);
+ return $res;
}
@@ -429,7 +458,6 @@
// print "$s\n";
// """Notation3 tokenizer. Takes in a string, returns a raw token list."""
- if (strlen($s) == 0) die('Document has no content!');
$s=str_replace("\r\n","\n",$s);
$s=str_replace("\r","\n",$s);
@@ -448,6 +476,8 @@
//}
$res=array();
+ if (strlen($s) == 0) return $res;
+
preg_match_all($this->Tokens, $s, $newres);
$res=$this->array_concat($res, array_map('trim', $newres[0]));
@@ -560,12 +590,12 @@
// if a <> resource occours, change it to the parsed filename or local URI + timestamp
if ($list[$i]=='<>') {
- if (!isset($path)) {
+ if (!isset($this->baseURI)) {
if (!isset($_SERVER['SERVER_ADDR'])) $_SERVER['SERVER_ADDR']='localhost';
if (!isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI']='/rdfapi-php';
$list[$i]='';
- }else {$list[$i]='<'.$path.'>';};
+ }else {$list[$i]='<'.$this->baseURI.'>';};
};
@@ -582,9 +612,9 @@
if (isset($prefixes[$ns])) $list[$i] = '<'.$prefixes[$ns].$name.'>';
else if (isset($prefixes[substr($ns,2)])) $list[$i] = '^^'.$prefixes[substr($ns,2)].$name.'';
else {
- #die('Prefix not declared:'.$ns);
$this->parseError=true;
- trigger_error('Prefix not declared: '.$ns, E_USER_ERROR);
+ $this->errors[] = 'Prefix not declared: '.$ns;
+ return false;
break;
@@ -602,9 +632,17 @@
$list[$i] = '"'.$lit.'"';
}
- else { die ('Incorrect string formatting: '.substr($list[$i],-3,3)); }
+ else {
+ $this->parseError = true;
+ $this->errors[] = 'Incorrect string formatting: '.substr($list[$i],-3,3);
+ return false;
+ }
} else {
- if (strstr($list[$i],"\n")) die('Newline in literal: '+$list[$i]);
+ if (strstr($list[$i],"\n")) {
+ $this->parseError = true;
+ $this->errors[] = 'Newline in literal: '+$list[$i];
+ return false;
+ }
}
}
}
@@ -616,7 +654,6 @@
}
-
return $list;
}
@@ -730,7 +767,11 @@
if (count($list) == 3) return array($list);
- if (count($list) < 3) die("Error: statement too short!");
+ if (count($list) < 3) {
+ $this->parseError = true;
+ $this->errors[] = "Statement too short : " . join(',', $list);
+ return false;
+ }
//Get all ;
$r=$this->getPovs($list);
@@ -941,7 +982,9 @@
}
}
else {
- die('Only [ ] and () lists are supported!');
+ $this->parseError = true;
+ $this->errors[] = 'Only [ ] and () lists are supported!';
+ return false;
}
}
@@ -960,14 +1003,25 @@
// """Convert an N3 string into a list of triples as strings."""
$result = array();
+ $t = $this->toke($s);
+ if ($t === false) {
+ return false;
+ }
- $t = $this->filterWs($this->toke($s)); # tokenize the stream, and filter whitespace tokens
+ $t = $this->filterWs($t); # tokenize the stream, and filter whitespace tokens
+ if ($t === false) {
+ return false;
+ }
if ($this->debug) {
print "Filter WS:\n";
var_dump($t);
}
$r=$this->getPrefixes($t); # get the prefix directives, and add to a dict
+ if ($r === false) {
+ return false;
+ }
+
$prefixes=$r[0];
$t=$r[1];
if ($this->debug) {
@@ -977,32 +1031,51 @@
var_dump($t);
}
$t=$this->applyStuff($prefixes, $t);#apply prefixes, keywords, and string formatting
+ if ($t === false) {
+ return false;
+ }
+
if ($this->debug) {
print "Stuff applied:\n";
var_dump($t);
}
$t=$this->fixAnon($t); # fix _:a anons
+
+ if ($t === false) {
+ return false;
+ }
if ($this->debug) {
print "Fix anon:\n";
var_dump($t);
}
$t = $this->listStuff($t); # apply list stuff: todo
+ if ($t === false) {
+ return false;
+ }
if ($this->debug) {
print "Lists done:\n";
var_dump($t);
}
$t=$this->expandLists($t);
+ if ($t === false) {
+ return false;
+ }
if ($this->debug) {
print "Lists applied:\n";
var_dump($t);
}
$t = $this->getStatements($t); # get all of the "statements" from the stream
+ if ($t === false) {
+ return false;
+ }
foreach ($t as $stat) {
$stats=$this->statementize($stat);
-
+ if ($stats === false) {
+ return false;
+ }
foreach ($stats as $y) {
$result[]=$y;
}
diff -Naur -x '*~' -x CVS -w rdfapi-php-0.92/test/unit/Syntax/n3Parser_test.php rap-anti/test/unit/Syntax/n3Parser_test.php
--- rdfapi-php-0.92/test/unit/Syntax/n3Parser_test.php 2004-12-17 15:24:34.000000000 +0000
+++ rap-anti/test/unit/Syntax/n3Parser_test.php 2005-12-14 02:38:56.000000000 +0000
@@ -90,7 +90,7 @@
$n3pars= new N3Parser();
$model=$n3pars->parse2model($rdfInput,false);
//var_dump($model);
- $this->assertErrorPattern('[Prefix not declared: p:]');
+ $this->assertTrue($model === false);
}
}