Permalink
Browse files

Fixes in JSON serializer (quote removal), NTriples Serializer (multib…

…yte-subjects), SELECT Handler (FROM + MySQL 5.5), LOAD Handler (automatic table column update, utf8) check), Store (better term caching, automatic db-creation), minor tweaks in other places.
  • Loading branch information...
1 parent 495d10b commit 093d2a2afd8a481eae4573a902d582c3d4ad3711 @bnowack bnowack committed Dec 1, 2011
View
9 ARC2.php 100755 → 100644
@@ -6,7 +6,6 @@
* @license <http://arc.semsol.org/license>
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2011-01-07
*/
/* E_STRICT hack */
@@ -17,7 +16,7 @@
class ARC2 {
static function getVersion() {
- return '2011-01-07';
+ return '2011-12-01';
}
/* */
@@ -42,10 +41,10 @@ static function getIncPath($f = '') {
}
static function getScriptURI() {
- if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
+ if (isset($_SERVER) && (isset($_SERVER['SERVER_NAME']) || isset($_SERVER['HTTP_HOST']))) {
$proto = preg_replace('/^([a-z]+)\/.*$/', '\\1', strtolower($_SERVER['SERVER_PROTOCOL']));
$port = $_SERVER['SERVER_PORT'];
- $server = $_SERVER['SERVER_NAME'];
+ $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$script = $_SERVER['SCRIPT_NAME'];
/* https */
if (($proto == 'http') && $port == 443) {
@@ -69,7 +68,7 @@ static function getScriptURI() {
static function getRequestURI() {
if (isset($_SERVER) && isset($_SERVER['REQUEST_URI'])) {
return preg_replace('/^([a-z]+)\/.*$/', '\\1', strtolower($_SERVER['SERVER_PROTOCOL'])) .
- '://' . $_SERVER['SERVER_NAME'] .
+ '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']) .
($_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '') .
$_SERVER['REQUEST_URI'];
}
View
47 ARC2_Class.php 100755 → 100644
@@ -6,7 +6,6 @@
* @license <http://arc.semsol.org/license>
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2010-11-16
*/
class ARC2_Class {
@@ -31,6 +30,7 @@ function __init() {/* base, time_limit */
$this->warnings = array();
$this->adjust_utf8 = $this->v('adjust_utf8', 0, $this->a);
$this->max_errors = $this->v('max_errors', 25, $this->a);
+ $this->has_pcre_unicode = @preg_match('/\pL/u', 'test');/* \pL = block/point which is a Letter */
}
/* */
@@ -477,14 +477,51 @@ function mdAttrs($id, $type = '') {
function queryDB($sql, $con, $log_errors = 0) {
$t1 = ARC2::mtime();
$r = mysql_query($sql, $con);
- $t2 = ARC2::mtime() - $t1;
- if ($t2 > 1) {
- //echo "\n needed " . $t2 . ' secs for ' . $sql;
+ if (0) {
+ $t2 = ARC2::mtime() - $t1;
+ $call_obj = $this;
+ $call_path = '';
+ while ($call_obj) {
+ $call_path = get_class($call_obj) . ' / ' . $call_path;
+ $call_obj = isset($call_obj->caller) ? $call_obj->caller : false;
+ }
+ echo "\n" . $call_path . " needed " . $t2 . ' secs for ' . str_replace("\n" , ' ', $sql);;
}
if ($log_errors && ($er = mysql_error($con))) $this->addError($er);
return $r;
}
- /* */
+ /**
+ * Shortcut method to create an RDF/XML backup dump from an RDF Store object.
+ */
+ function backupStoreData($store, $target_path, $offset = 0) {
+ $limit = 10;
+ $q = '
+ SELECT DISTINCT ?s WHERE {
+ ?s ?p ?o .
+ }
+ ORDER BY ?s
+ LIMIT ' . $limit . '
+ ' . ($offset ? 'OFFSET ' . $offset : '') . '
+ ';
+ $rows = $store->query($q, 'rows');
+ $tc = count($rows);
+ $full_tc = $tc + $offset;
+ $mode = $offset ? 'ab' : 'wb';
+ $fp = fopen($target_path, $mode);
+ foreach ($rows as $row) {
+ $index = $store->query('DESCRIBE <' . $row['s'] . '>', 'raw');
+ if ($index) {
+ $doc = $this->toRDFXML($index);
+ fwrite($fp, $doc . "\n\n");
+ }
+ }
+ fclose($fp);
+ if ($tc == 10) {
+ set_time_limit(300);
+ $this->backupStoreData($store, $target_path, $offset + $limit);
+ }
+ return $full_tc;
+ }
}
View
6 ARC2_Resource.php 100755 → 100644
@@ -6,7 +6,7 @@
* @license http://arc.semsol.org/license
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2010-11-16
+ * @version 2011-01-19
*/
ARC2::inc('Class');
@@ -35,6 +35,10 @@ function setIndex($index) {
$this->index = $index;
}
+ function getIndex($index) {
+ return $this->index;
+ }
+
function setProps($props, $s = '') {
if (!$s) $s = $this->uri;
$this->index[$s] = $props;
@@ -5,7 +5,7 @@
class: ARC2 DAWG Test Handler
author: Benjamin Nowack
-version: 2010-11-16
+version: 2011-12-01
*/
ARC2::inc('Class');
@@ -50,6 +50,9 @@ function getFile($url) {
$fname = 'f' . crc32($url) . '.txt';
if (!file_exists('tmp/' . $fname)) {
$r = '';
+ if (!isset($this->reader)) {
+ $this->reader = new ARC2_Reader($this->a, $this);
+ }
$this->reader->activate($url);
while ($d = $this->reader->readStream()) {
$r .= $d;
View
@@ -6,7 +6,6 @@
* @license http://arc.semsol.org/license
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2010-11-16
*/
ARC2::inc('RDFParser');
@@ -447,7 +446,7 @@ function h6Open($t, $a) {
$data = isset($s['o_xml_data']) ? $s['o_xml_data'] : '';
$ns = isset($s['ns']) ? $s['ns'] : array();
$parts = $this->splitURI($t);
- if (count($parts) === 1) {
+ if ((count($parts) === 1) || empty($parts[1])) {
$data .= '<'.$t;
}
else {
@@ -587,7 +586,7 @@ function h6Close($t) {
}
else {
$parts = $this->splitURI($t);
- if (count($parts) == 1) {
+ if ((count($parts) === 1) || empty($parts[1])) {
$data .= '</'.$t.'>';
}
else {
@@ -6,7 +6,6 @@
* @license <http://arc.semsol.org/license>
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2010-11-16
*/
ARC2::inc('RDFSerializer');
@@ -26,16 +25,24 @@ function __init() {
/* */
function getTerm($v) {
- if (!is_array($v)) {
+ // type detection
+ if (!is_array($v) || empty($v['type'])) {
if (preg_match('/^\_\:/', $v)) {
- return $v;
+ return $this->getTerm(array('value' => $v, 'type' => 'bnode'));
}
- if (preg_match('/^[a-z0-9]+\:[^\s\"]*$/is', $v)) {
- return '<' . $this->escape($v) . '>';
+ if (preg_match('/^[a-z0-9]+\:[^\s\"]*$/is' . ($this->has_pcre_unicode ? 'u' : ''), $v)) {
+ return $this->getTerm(array('value' => $v, 'type' => 'uri'));
}
return $this->getTerm(array('type' => 'literal', 'value' => $v));
}
- if ($v['type'] != 'literal') {
+ if ($v['type'] == 'bnode') {
+ return $v['value'];
+ }
+ elseif ($v['type'] == 'uri') {
+ return '<' . $this->escape($v['value']) . '>';
+ }
+ // something went wrong
+ elseif ($v['type'] != 'literal') {
return $this->getTerm($v['value']);
}
/* literal */
@@ -6,7 +6,6 @@
* @license http://arc.semsol.org/license
* @homepage <http://arc.semsol.org/>
* @package ARC2
- * @version 2010-11-16
*/
ARC2::inc('RDFSerializer');
@@ -49,7 +48,9 @@ function getTerm($v, $term = 's') {
}
function jsonEscape($v) {
- if (function_exists('json_encode')) return trim(json_encode($v), '"');
+ if (function_exists('json_encode')) {
+ return preg_replace('/^"(.*)"$/', '\\1', json_encode($v));
+ }
$from = array("\\", "\r", "\t", "\n", '"', "\b", "\f", "/");
$to = array('\\\\', '\r', '\t', '\n', '\"', '\b', '\f', '\/');
return str_replace($from, $to, $v);
Oops, something went wrong.

0 comments on commit 093d2a2

Please sign in to comment.