|
From: <cw...@us...> - 2007-08-12 08:57:47
|
Revision: 480
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=480&view=rev
Author: cweiske
Date: 2007-08-12 01:57:45 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
BlankNode wasn't loaded automatically
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-08 16:27:35 UTC (rev 479)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 08:57:45 UTC (rev 480)
@@ -1,5 +1,6 @@
<?php
require_once RDFAPI_INCLUDE_DIR . 'util/Object.php';
+require_once RDFAPI_INCLUDE_DIR . 'model/Blanknode.php';
require_once RDFAPI_INCLUDE_DIR . 'model/Resource.php';
require_once RDFAPI_INCLUDE_DIR . 'model/Literal.php';
require_once RDFAPI_INCLUDE_DIR . 'model/Statement.php';
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-12 10:14:42
|
Revision: 481
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=481&view=rev
Author: cweiske
Date: 2007-08-12 03:14:41 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Fix N3Parser includes
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 08:57:45 UTC (rev 480)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 10:14:41 UTC (rev 481)
@@ -4,6 +4,8 @@
require_once RDFAPI_INCLUDE_DIR . 'model/Resource.php';
require_once RDFAPI_INCLUDE_DIR . 'model/Literal.php';
require_once RDFAPI_INCLUDE_DIR . 'model/Statement.php';
+require_once RDFAPI_INCLUDE_DIR . 'model/MemModel.php';
+require_once RDFAPI_INCLUDE_DIR . 'constants.php';
// ----------------------------------------------------------------------------------
// Class: N3Parser
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-12 11:03:14
|
Revision: 482
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=482&view=rev
Author: cweiske
Date: 2007-08-12 04:03:13 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
nicify indentation
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 10:14:41 UTC (rev 481)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 11:03:13 UTC (rev 482)
@@ -793,33 +793,34 @@
while (in_array($schar, $list)) {
// while schar in list {
- $ndict=array();
- $nestingLevel=0;
- $biggest=0;
- for ($i=0;$i<count($list);$i++) {
- if ($list[$i] == $schar) {
- $nestingLevel += 1;
- if (!in_array($nestingLevel, array_keys($ndict))) {
- $ndict[$nestingLevel] = array(array($i));
- } else {
- $ndict[$nestingLevel][]=array($i);
- }
- }
- if ($list[$i] == $echar) {
- if (!in_array($nestingLevel, array_keys($ndict))) {
- $ndict[$nestingLevel]=array(array($i));
- } else {
+ $ndict = array();
+ $nestingLevel = 0;
+ $biggest = 0;
+ for ($i = 0; $i < count($list); $i++) {
+ if ($list[$i] == $schar) {
+ $nestingLevel += 1;
+ if (!in_array($nestingLevel, array_keys($ndict))) {
+ $ndict[$nestingLevel] = array(array($i));
+ } else {
+ $ndict[$nestingLevel][]=array($i);
+ }
+ }
+ if ($list[$i] == $echar) {
+ if (!in_array($nestingLevel, array_keys($ndict))) {
+ $ndict[$nestingLevel]=array(array($i));
+ } else {
$ndict[$nestingLevel][count($ndict[$nestingLevel])-1][]=$i;
$nestingLevel-= 1;
# elif type(list[i]) == type([]) {
# list[i] = doLists(list[i], schar, echar)
- }
- }
+ }
+ }
}
- foreach (array_keys($ndict) as $key)
- if ($key > $biggest) $biggest = $key;
+ foreach (array_keys($ndict) as $key) {
+ if ($key > $biggest) $biggest = $key;
+ }
- $tol = $ndict[$biggest][0];
+ $tol = $ndict[$biggest][0];
$list = $this->listify($list, $tol[0], ($tol[1]+1));
}
return $list;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-12 17:42:08
|
Revision: 491
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=491&view=rev
Author: cweiske
Date: 2007-08-12 10:42:05 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Make it throw an exception instead of die()ing hard
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 15:26:47 UTC (rev 490)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 17:42:05 UTC (rev 491)
@@ -42,8 +42,11 @@
*
*
*
- * @author Sean B. Palmer <se...@my...>, Gunnar AA. Grimnes <ggr...@cs...>, Daniel Westphal <ma...@d-...>
+ * @author Sean B. Palmer <se...@my...>
+ * @author Gunnar AA. Grimnes <ggr...@cs...>
+ * @author Daniel Westphal <ma...@d-...>
* @version $Id$
+ * @license GPL http://www.gnu.org/licenses/gpl.txt
* @package syntax
* @access public
**/
@@ -68,37 +71,37 @@
**/
function N3Parser() {
//Regular expressions:
- $Name = '[A-Za-z0-9_@\.]+[^\.,;\[\]\s\) ]*';
- $URI = '<[^> ]*>';
- $bNode = '_:'.$Name;
- $Univar = '\?'.$Name;
- $QName = '(?:[A-Za-z][A-Za-z0-9_@\.]*)?:'.$Name;
- $Literal = '"(\\\"|[^"])*"'; # '"(?:\\"|[^"])*"'
-// $Literal = '"[^"\\\\]*(?:\\.\\[^"\\]*)*"'; # '"(?:\\"|[^"])*"'
- $LangTag = '@[A-Za-z\-]*[^ \^\.\;\,]';
+ $Name = '[A-Za-z0-9_@\.]+[^\.,;\[\]\s\) ]*';
+ $URI = '<[^> ]*>';
+ $bNode = '_:'.$Name;
+ $Univar = '\?'.$Name;
+ $QName = '(?:[A-Za-z][A-Za-z0-9_@\.]*)?:'.$Name;
+ $Literal = '"(\\\"|[^"])*"'; # '"(?:\\"|[^"])*"'
+// $Literal = '"[^"\\\\]*(?:\\.\\[^"\\]*)*"'; # '"(?:\\"|[^"])*"'
+ $LangTag = '@[A-Za-z\-]*[^ \^\.\;\,]';
$Datatype = '(\^\^)[^ ,\.;)]+';
$Datatype_URI = '(\^\^)'.$URI;
// $LLiteral = '"""[^"\\\\]*(?:(?:.|"(?!""))[^"\\\\]*)*"""';
$LLiteral = '"""[^"\\\\]*(?:(?:\\\\.|"(?!""))[^"\\\\]*)*"""';
// '"""[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""'
- $Comment = '#.*$';
- $Prefix = '(?:[A-Za-z][A-Za-z0-9_]*)?:';
+ $Comment = '#.*$';
+ $Prefix = '(?:[A-Za-z][A-Za-z0-9_]*)?:';
$PrefixDecl = '@prefix';
- $WS = '[ \t]';
- $this->RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; # for 'a' keyword
+ $WS = '[ \t]';
+ $this->RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; # for 'a' keyword
$this->DAML_NS = 'http://www.daml.org/2001/03/daml+oil#'; # for '=' keyword
- $this->OWL_NS = 'http://www.w3.org/2002/07/owl#';
+ $this->OWL_NS = 'http://www.w3.org/2002/07/owl#';
// $t = array( $LLiteral, $URI); //, $Literal, $PrefixDecl, $QName, $bNode, $Prefix,
// $Univar, 'a', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment);
$t = array( $Datatype_URI,$Datatype,$LLiteral, $URI, $Literal, $PrefixDecl, $QName, $bNode, $Prefix, $Univar, 'a','=', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment,$LangTag);
- $this->Tokens="/(".join($t,"|").")/m";
+ $this->Tokens = "/(".join($t,"|").")/m";
- $this->bNode=0;
- $this->debug=0;
- $this->bNodeMap = array();
- $this->FixBnodes = FIX_BLANKNODES;
- $this->parseError=false;
+ $this->bNode = 0;
+ $this->debug = 0;
+ $this->bNodeMap = array();
+ $this->FixBnodes = FIX_BLANKNODES;
+ $this->parseError =false;
}
@@ -142,7 +145,7 @@
/**
- * This parses a N3 string and calls func($subject, $predicate, $object) with each trioke
+ * This parses a N3 string and calls func($subject, $predicate, $object) with each triple
* @param string $s
* @param string $func
* @access public
@@ -722,7 +725,9 @@
if (count($list) == 3) return array($list);
- if (count($list) < 3) die("Error: statement too short!");
+ if (count($list) < 3) {
+ throw new Exception('N3 statement too short.');
+ }
//Get all ;
$r=$this->getPovs($list);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-12 18:10:09
|
Revision: 494
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=494&view=rev
Author: cweiske
Date: 2007-08-12 11:10:08 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Indent nicely so that you can actually see what the code is meant to be
If anyone of the original authors reads that: Thank you for giving me
so many hours of fun that I needed to indent the code so that
I could begin to understand what it was supposed to do.
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 17:43:07 UTC (rev 493)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 18:10:08 UTC (rev 494)
@@ -77,6 +77,7 @@
$Univar = '\?'.$Name;
$QName = '(?:[A-Za-z][A-Za-z0-9_@\.]*)?:'.$Name;
$Literal = '"(\\\"|[^"])*"'; # '"(?:\\"|[^"])*"'
+ $Number = '[0-9]+(:?[\\.e][0-9]+)?';
// $Literal = '"[^"\\\\]*(?:\\.\\[^"\\]*)*"'; # '"(?:\\"|[^"])*"'
$LangTag = '@[A-Za-z\-]*[^ \^\.\;\,]';
$Datatype = '(\^\^)[^ ,\.;)]+';
@@ -94,7 +95,7 @@
// $t = array( $LLiteral, $URI); //, $Literal, $PrefixDecl, $QName, $bNode, $Prefix,
// $Univar, 'a', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment);
- $t = array( $Datatype_URI,$Datatype,$LLiteral, $URI, $Literal, $PrefixDecl, $QName, $bNode, $Prefix, $Univar, 'a','=', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment,$LangTag);
+ $t = array( $Datatype_URI,$Datatype,$LLiteral, $URI, $Literal, $PrefixDecl, $QName, $Number, $bNode, $Prefix, $Univar, 'a','=', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment,$LangTag);
$this->Tokens = "/(".join($t,"|").")/m";
$this->bNode = 0;
@@ -443,7 +444,7 @@
$res=array();
preg_match_all($this->Tokens, $s, $newres);
$res=$this->array_concat($res, array_map('trim', $newres[0]));
-
+//var_dump($newres[0]);
return $res;
}
@@ -530,88 +531,87 @@
if ($l=='this') $l='<urn:urn-n:this>';
}
- /**
- * Applies stuff :)
- * Expands namespace prefixes etc.
- * @param array $prefixes
- * @param array $list
- * @returns $list
- * @access private
- **/
- function applyStuff($prefixes, $list) {
+ /**
+ * Applies stuff :)
+ * Expands namespace prefixes etc.
+ * @param array $prefixes
+ * @param array $list
+ * @returns $list
+ * @access private
+ **/
+ function applyStuff($prefixes, $list)
+ {
+ array_walk($list, array($this, 'replace_a_type'));
+ array_walk($list, array($this, 'replace_equal'));
+ array_walk($list, array($this, 'replace_this'));
- array_walk($list, array($this, 'replace_a_type'));
- array_walk($list, array($this, 'replace_equal'));
- array_walk($list, array($this, 'replace_this'));
+ for ($i=0; $i<count($list); $i++) {
+ if ($list[$i]=='<>') {
+ if (!isset($path)) {
+ if (!isset($_SERVER['SERVER_ADDR'])) {
+ $_SERVER['SERVER_ADDR'] = 'localhost';
+ }
+ if (!isset($_SERVER['REQUEST_URI'])) {
+ $_SERVER['REQUEST_URI'] = '/rdfapi-php';
+ }
+ $list[$i] = '<http://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'].'#generate_timestamp_'.time().'>';
+ } else {
+ $list[$i] = '<'.$path.'>';
+ };
+ };
- for ($i=0;$i<count($list);$i++) {
- // for i in range(len(list)) {
-// if (!strstr('<_"?.;,{}[]()',$list[$i]{0})) {
+ if ((!strstr('<_"?.;,{}[]()@',$list[$i]{0}))
+ && (substr($list[$i],0,3)!='^^<')
+ ) {
+ $_r = explode(":",$list[$i]);
+ $ns = $_r[0].':';
+ $name = $_r[1];
-// if a <> resource occours, change it to the parsed filename or local URI + timestamp
+ 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);
+ break;
+ }
- if ($list[$i]=='<>') {
- if (!isset($path)) {
- if (!isset($_SERVER['SERVER_ADDR'])) $_SERVER['SERVER_ADDR']='localhost';
- if (!isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI']='/rdfapi-php';
- $list[$i]='<http://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'].'#generate_timestamp_'.time().'>';
+ } else {
+ if ($list[$i]{0} == '"') { // Congratulations - it's a literal!
+ if (substr($list[$i],0,3) == '"""') {
+ if (substr($list[$i],-3,3) == '"""') { // A big literal...
+ $lit = substr($list[$i],3,-3);
+ // print "++$lit++";
+ $lit=str_replace('\n', '\\n',$lit);
- }else {$list[$i]='<'.$path.'>';};
- };
+ $lit=ereg_replace("[^\\]\"", "\\\"", $lit);
+ $list[$i] = '"'.$lit.'"';
+ } else {
+ die ('Incorrect string formatting: '.substr($list[$i],-3,3));
+ }
+ } else {
+ if (strstr($list[$i],"\n")) {
+ die('Newline in literal: '+$list[$i]);
+ }
+ }
+ }
+ }
- if ((!strstr('<_"?.;,{}[]()@',$list[$i]{0}))AND (substr($list[$i],0,3)!='^^<')) {
- $_r= explode(":",$list[$i]);
+ if (substr($list[$i],0,2)=='^^') {
+ if ($list[$i][2]!='<'){$list[$i]='^^<'.substr($list[$i],2).'>';};
+ };
+ }//foreach list item
+ return $list;
+ }//function applyStuff($prefixes, $list)
- $ns=$_r[0].':';
- $name=$_r[1];
-
- 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);
- break;
-
-
- }
-
- } else {
- if ($list[$i]{0} == '"') { // Congratulations - it's a literal!
- if (substr($list[$i],0,3) == '"""') {
- if (substr($list[$i],-3,3) == '"""') { // A big literal...
- $lit = substr($list[$i],3,-3);
- // print "++$lit++";
- $lit=str_replace('\n', '\\n',$lit);
-
- $lit=ereg_replace("[^\\]\"", "\\\"", $lit);
-
- $list[$i] = '"'.$lit.'"';
- }
- else { die ('Incorrect string formatting: '.substr($list[$i],-3,3)); }
- } else {
- if (strstr($list[$i],"\n")) die('Newline in literal: '+$list[$i]);
- }
- }
- }
-
- if (substr($list[$i],0,2)=='^^') {
- if ($list[$i][2]!='<'){$list[$i]='^^<'.substr($list[$i],2).'>';};
- };
-
-
- }
-
-
- return $list;
- }
-
/**
* Returns an array of triples extracted from the list of n3 tokens
* @param array $list
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cw...@us...> - 2007-08-13 05:58:51
|
Revision: 498
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=498&view=rev
Author: cweiske
Date: 2007-08-12 22:58:50 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
More verbose error message that helps to find the error better
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-13 05:14:26 UTC (rev 497)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-13 05:58:50 UTC (rev 498)
@@ -744,7 +744,11 @@
if (count($list) == 3) return array($list);
if (count($list) < 3) {
- throw new Exception('N3 statement too short.');
+ throw new Exception(
+ 'N3 statement too short,'
+ . ' only ' . count($list) . ' elements instead of 3:' . "\n"
+ . implode("\n", $list)
+ );
}
//Get all ;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|