diff --git a/composer.json b/composer.json index dca14bfa0d12f667a106897ff6e83a152baaad50..b7e9683395f6a4301b78cd4c5c310d4054ca5fdf 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "guzzle/http": "3.7.*", "kriswallsmith/assetic": "1.1.*@alpha", "symfony-cmf/routing": "1.1.*@alpha", - "easyrdf/easyrdf": "0.8.*@beta", + "easyrdf/easyrdf": "0.8.*", "phpunit/phpunit": "3.7.*", "zendframework/zend-feed": "2.2.*" }, diff --git a/composer.lock b/composer.lock index 6108435d9e18910a90a7e144181c584336477a53..226faba655fa00275ade4ef667a586c39baf9155 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "ac2a8ee2f49fcb0535259847306a2bdc", + "hash": "0733d59446085cb815b72923c37e0fd6", "packages": [ { "name": "doctrine/annotations", @@ -400,16 +400,16 @@ }, { "name": "easyrdf/easyrdf", - "version": "0.8.0-beta.1", + "version": "0.8.0", "source": { "type": "git", - "url": "git://github.com/njh/easyrdf.git", - "reference": "0.8.0-beta.1" + "url": "https://github.com/njh/easyrdf.git", + "reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2" }, "dist": { "type": "zip", - "url": "https://github.com/njh/easyrdf/archive/0.8.0-beta.1.zip", - "reference": "0.8.0-beta.1", + "url": "https://api.github.com/repos/njh/easyrdf/zipball/3e43ab7274004e9f4192e06b9fc147781e1f85c2", + "reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2", "shasum": "" }, "require": { @@ -423,6 +423,9 @@ "sami/sami": "dev-master", "squizlabs/php_codesniffer": ">=1.4.3" }, + "suggest": { + "ml/json-ld": "dev-master" + }, "type": "library", "autoload": { "psr-0": { @@ -448,9 +451,10 @@ "RDF", "Semantic Web", "Turtle", - "rdfa" + "rdfa", + "sparql" ], - "time": "2013-01-18 15:54:28" + "time": "2013-12-30 22:31:37" }, { "name": "guzzle/common", @@ -2134,8 +2138,7 @@ "doctrine/common": 20, "doctrine/annotations": 20, "kriswallsmith/assetic": 15, - "symfony-cmf/routing": 15, - "easyrdf/easyrdf": 10 + "symfony-cmf/routing": 15 }, "platform": [ diff --git a/core/vendor/autoload.php b/core/vendor/autoload.php index 00592d9d64f14c0be36fae3df20b3e188ba5f156..5052aab9f0f091659ae069b6eb95ae4fceb9a747 100644 --- a/core/vendor/autoload.php +++ b/core/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit8448fbbf88ecb044f224057d631a4472::getLoader(); +return ComposerAutoloaderInit92462a247bf83504e990c5f706f228cc::getLoader(); diff --git a/core/vendor/composer/autoload_real.php b/core/vendor/composer/autoload_real.php index 9f78665fdee20261c20929bae950822c73fb94a3..fea362d1951a8c3a0385bafcfb29c16e3d7694ff 100644 --- a/core/vendor/composer/autoload_real.php +++ b/core/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit8448fbbf88ecb044f224057d631a4472 +class ComposerAutoloaderInit92462a247bf83504e990c5f706f228cc { private static $loader; @@ -19,9 +19,9 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit8448fbbf88ecb044f224057d631a4472', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit92462a247bf83504e990c5f706f228cc', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit8448fbbf88ecb044f224057d631a4472', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit92462a247bf83504e990c5f706f228cc', 'loadClassLoader')); $vendorDir = dirname(__DIR__); $baseDir = dirname(dirname($vendorDir)); diff --git a/core/vendor/composer/installed.json b/core/vendor/composer/installed.json index b9dd77e1823a68410ff1bb3f208e31679dc4d0b1..81d0e48f41a5a63f95ebbb2d7764da3ff5edf9f6 100644 --- a/core/vendor/composer/installed.json +++ b/core/vendor/composer/installed.json @@ -1,60 +1,4 @@ [ - { - "name": "easyrdf/easyrdf", - "version": "0.8.0-beta.1", - "version_normalized": "0.8.0.0-beta1", - "source": { - "type": "git", - "url": "git://github.com/njh/easyrdf.git", - "reference": "0.8.0-beta.1" - }, - "dist": { - "type": "zip", - "url": "https://github.com/njh/easyrdf/archive/0.8.0-beta.1.zip", - "reference": "0.8.0-beta.1", - "shasum": "" - }, - "require": { - "php": ">=5.2.8" - }, - "replace": { - "njh/easyrdf": "self.version" - }, - "require-dev": { - "phpunit/phpunit": ">=3.5.15", - "sami/sami": "dev-master", - "squizlabs/php_codesniffer": ">=1.4.3" - }, - "time": "2013-01-18 15:54:28", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "EasyRdf_": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nicholas Humfrey", - "email": "njh@aelius.com", - "homepage": "http://www.aelius.com/njh/", - "role": "Developer" - } - ], - "description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.", - "homepage": "http://www.easyrdf.org/", - "keywords": [ - "Linked Data", - "RDF", - "Semantic Web", - "Turtle", - "rdfa" - ] - }, { "name": "psr/log", "version": "1.0.0", @@ -2193,5 +2137,65 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com" + }, + { + "name": "easyrdf/easyrdf", + "version": "0.8.0", + "version_normalized": "0.8.0.0", + "source": { + "type": "git", + "url": "https://github.com/njh/easyrdf.git", + "reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/njh/easyrdf/zipball/3e43ab7274004e9f4192e06b9fc147781e1f85c2", + "reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2", + "shasum": "" + }, + "require": { + "php": ">=5.2.8" + }, + "replace": { + "njh/easyrdf": "self.version" + }, + "require-dev": { + "phpunit/phpunit": ">=3.5.15", + "sami/sami": "dev-master", + "squizlabs/php_codesniffer": ">=1.4.3" + }, + "suggest": { + "ml/json-ld": "dev-master" + }, + "time": "2013-12-30 22:31:37", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "EasyRdf_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nicholas Humfrey", + "email": "njh@aelius.com", + "homepage": "http://www.aelius.com/njh/", + "role": "Developer" + } + ], + "description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.", + "homepage": "http://www.easyrdf.org/", + "keywords": [ + "Linked Data", + "RDF", + "Semantic Web", + "Turtle", + "rdfa", + "sparql" + ] } ] diff --git a/core/vendor/easyrdf/easyrdf/CHANGELOG.md b/core/vendor/easyrdf/easyrdf/CHANGELOG.md index 482076e37f1d834081d8b0d4ea5ac441bf430457..f902b3c9e13e23dad770058a44a9e5fdf497cb04 100644 --- a/core/vendor/easyrdf/easyrdf/CHANGELOG.md +++ b/core/vendor/easyrdf/easyrdf/CHANGELOG.md @@ -1,21 +1,49 @@ EasyRdf 0.8.0 ============= -API changes ------------ -* is_a() has been renamed to isA() - Major new features ------------------ * Now PSR-2 compliant * Added RDFa parser +* Added SPARQL Update support to `EasyRdf_Sparql_Client` + +API changes +----------- +* `is_a()` has been renamed to `isA()` +* `isBnode()` has been renamed to `isBNode()` +* `getNodeId()` has been renamed to `getBNodeId()` +* Added a `$value` property to `hasProperty()` +* Renamed `toArray()` to `toRdfPhp()` +* Renamed `count()` to `countValues()` in `EasyRdf_Graph` and `EasyRdf_Resource` +* Made passing a URI to `delete()` behave more like `all()` and `get()` - you must enclose in `<>` +* `dump(true)` has changed to `dump('html')` +* `getUri()` in `EasyRdf_Sparql_Client` has been renamed to `getQueryUri()` Enhancements ------------ +* Added `EasyRdf_Container` class to help iterate through `rdf:Alt`, `rdf:Bag` and `rdf:Seq` +* Added `EasyRdf_Collection` class to help iterate through `rdf:List` +* Added `EasyRdf_Literal_HTML` and `EasyRdf_Literal_XML` +* Changed formatting of `xsd:dateTime` from `DateTime::ISO8601` to `DateTime::ATOM` +* Added `rss:title` to the list of properties that `label()` will check for +* Added support for serialising containers to the RDF/XML serialiser +* Added getGraph method to `EasyRdf_Resource` +* Turtle parser improvements +* Added the `application/n-triples` MIME type for the N-Triples format +* Added support to `EasyRdf_Namespace` for expanding `a` to `rdf:type` +* Added `listNamedGraphs()` function to `EasyRdf_Sparql_Client` +* Added line and column number to exceptions in the built-in parsers Bug Fixes --------- - +* Fixed bug in `EasyRdf_Namespace::expand()` (see issue #114) +* Fix for dumping SPARQL SELECT query with unbound result (see issue #112) +* Sesame compatibility : avoid duplicate Content-Length header +* Fix for for passing objects of type DateTime to $graph->add() (see issue #119) +* Fix for SPARQL queries longer than 2KB (see issue #85) +* Fix for dumping literal with unshortenable datatype uri (see issue #120) +* Fix for getting default mime type or extension when there isn't one +* Fix for missing trailing slash the HTTP client EasyRdf 0.7.2 diff --git a/core/vendor/easyrdf/easyrdf/DEVELOPER.md b/core/vendor/easyrdf/easyrdf/DEVELOPER.md new file mode 100644 index 0000000000000000000000000000000000000000..a4516ef577db9a94284163743ba2636523562176 --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/DEVELOPER.md @@ -0,0 +1,32 @@ +Contributing to EasyRdf +======================= + + +Contributions to the EasyRdf codebase are welcome using the usual Github pull request workflow. + +To run the code style checker: +``` +make cs + +``` +You can run the PHP unit test suite with: +``` +make test +``` + +Unit tests are automatically run after being received by Github: +http://ci.aelius.com/job/easyrdf/ + +The tests for the examples are run in a sperate test: +http://ci.aelius.com/job/easyrdf-examples/ + + +Notes +----- + +* Please ask on the [mailing list] before starting work on any significant chnages +* Please write tests for any new features or bug fixes. The tests should be checked in the same commit as the code. + + + +[mailing list]:http://groups.google.com/group/easyrdf diff --git a/core/vendor/easyrdf/easyrdf/README.md b/core/vendor/easyrdf/easyrdf/README.md index 182b1a54a18634046f34bb99f6ae17fb49885644..d5b9956bf2106d036e530b60d096006646137c63 100644 --- a/core/vendor/easyrdf/easyrdf/README.md +++ b/core/vendor/easyrdf/easyrdf/README.md @@ -29,14 +29,14 @@ an [EasyRdf_Graph] object. Downloads --------- -The latest version of EasyRdf can be [downloaded from GitHub]. +The latest _stable_ version of EasyRdf can be [downloaded from the EasyRdf website]. Links ----- * [EasyRdf Homepage](http://www.easyrdf.org/) -* [API documentation](http://www.easyrdf.org/docs/api/) +* [API documentation](http://www.easyrdf.org/docs/api) * [Change Log](http://github.com/njh/easyrdf/blob/master/CHANGELOG.md) * Source Code: <http://github.com/njh/easyrdf> * Issue Tracker: <http://github.com/njh/easyrdf/issues> @@ -86,6 +86,7 @@ More Examples * [zend_framework.php](https://github.com/njh/easyrdf/blob/master/examples/zend_framework.php#slider) - Example of using Zend_Http_Client and Zend_Loader_Autoloader with EasyRdf + Licensing --------- @@ -101,7 +102,7 @@ The examples are in the public domain, for more information see [UNLICENSE]. [ARC2]:http://github.com/semsol/arc2/ [BSD-3-Clause]:http://www.opensource.org/licenses/BSD-3-Clause -[downloaded from github]:https://github.com/njh/easyrdf/downloads +[downloaded from the EasyRdf website]:http://www.easyrdf.org/downloads [GraphViz]:http://www.graphviz.org/ [rapper]:http://librdf.org/raptor/rapper.html [RDF]:http://en.wikipedia.org/wiki/Resource_Description_Framework diff --git a/core/vendor/easyrdf/easyrdf/composer.json b/core/vendor/easyrdf/easyrdf/composer.json index c93d98dcfa977efa088d0478d65e56a6e70e47b6..15be804810767e9d3038e11da84f5d18e849434b 100644 --- a/core/vendor/easyrdf/easyrdf/composer.json +++ b/core/vendor/easyrdf/easyrdf/composer.json @@ -1,9 +1,9 @@ { "name": "easyrdf/easyrdf", "description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.", - "version": "0.8.0-beta.1", + "version": "0.8.0", "type": "library", - "keywords": ["RDF", "Semantic Web", "Linked Data", "Turtle", "RDFa"], + "keywords": ["RDF", "Semantic Web", "Linked Data", "Turtle", "RDFa", "SPARQL"], "homepage": "http://www.easyrdf.org/", "license": "BSD-3-Clause", "authors": [ @@ -22,6 +22,9 @@ "require": { "php": ">=5.2.8" }, + "suggest": { + "ml/json-ld": "dev-master" + }, "require-dev": { "phpunit/PHPUnit": ">=3.5.15", "squizlabs/php_codesniffer": ">=1.4.3", diff --git a/core/vendor/easyrdf/easyrdf/doap.php b/core/vendor/easyrdf/easyrdf/doap.php index ff9f190a48e9624f3a7d5576e88c0b5f1a1bab72..4393fe0df2fff6eba295b10b19cdf2b5ec0793e6 100644 --- a/core/vendor/easyrdf/easyrdf/doap.php +++ b/core/vendor/easyrdf/easyrdf/doap.php @@ -27,8 +27,8 @@ $easyrdf->addResource('doap:category', 'http://dbpedia.org/resource/Resource_Description_Framework'); $easyrdf->addResource('doap:category', 'http://dbpedia.org/resource/PHP'); - $easyrdf->addResource('doap:category', 'http://dbpedialite.org/things/24131#id'); - $easyrdf->addResource('doap:category', 'http://dbpedialite.org/things/53847#id'); + $easyrdf->addResource('doap:category', 'http://www.dbpedialite.org/things/24131#id'); + $easyrdf->addResource('doap:category', 'http://www.dbpedialite.org/things/53847#id'); $repository = $doap->newBNode('doap:GitRepository'); $repository->addResource('doap:browse', 'http://github.com/njh/easyrdf'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf.php index 2aaae30d9f78ba810a2780af712e1e71a6829fce..8c7248b589bfd67a6d77646755edaf23e02cfd78 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf.php @@ -8,7 +8,7 @@ * * LICENSE * - * Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,9 +34,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2011 Nicholas J Humfrey + * @copyright Copyright (c) 2011-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -74,6 +73,11 @@ */ require_once "EasyRdf/Http/Response.php"; +/** + * @see EasyRdf_Isomorphic + */ +require_once "EasyRdf/Isomorphic.php"; + /** * @see EasyRdf_Namespace */ @@ -134,6 +138,11 @@ */ require_once "EasyRdf/Parser.php"; +/** + * @see EasyRdf_Parser_Exception + */ +require_once "EasyRdf/Parser/Exception.php"; + /** * @see EasyRdf_Parser_RdfPhp */ @@ -169,6 +178,16 @@ */ require_once "EasyRdf/Resource.php"; +/** + * @see EasyRdf_Collection + */ +require_once "EasyRdf/Collection.php"; + +/** + * @see EasyRdf_Container + */ +require_once "EasyRdf/Container.php"; + /** * @see EasyRdf_Serialiser */ diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Collection.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Collection.php new file mode 100644 index 0000000000000000000000000000000000000000..b66646cefb6865bb2f3420d31395ebe736a3c4ee --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Collection.php @@ -0,0 +1,333 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +/** + * Sub-class of EasyRdf_Resource that represents an RDF collection (rdf:List) + * + * This class can be used to iterate through a collection of items. + * + * Note that items are numbered from 1 (not 0) for consistency with RDF Containers. + * + * @package EasyRdf + * @link http://www.w3.org/TR/xmlschema-2/#date + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ +class EasyRdf_Collection extends EasyRdf_Resource implements ArrayAccess, Countable, SeekableIterator +{ + private $position; + private $current; + + /** Create a new collection - do not use this directly + * + * @ignore + */ + public function __construct($uri, $graph) + { + $this->position = 1; + $this->current = null; + parent::__construct($uri, $graph); + } + + /** Seek to a specific position in the container + * + * The first item is postion 1 + * + * @param integer $position The position in the container to seek to + * @throws OutOfBoundsException + */ + public function seek($position) + { + if (is_int($position) and $position > 0) { + list($node, $actual) = $this->getCollectionNode($position); + if ($actual === $position) { + $this->position = $actual; + $this->current = $node; + } else { + throw new OutOfBoundsException( + "Unable to seek to position $position in the collection" + ); + } + } else { + throw new InvalidArgumentException( + "Collection position must be a positive integer" + ); + } + } + + /** Rewind the iterator back to the start of the collection + * + */ + public function rewind() + { + $this->position = 1; + $this->current = null; + } + + /** Return the current item in the collection + * + * @return mixed The current item + */ + public function current() + { + if ($this->position === 1) { + return $this->get('rdf:first'); + } elseif ($this->current) { + return $this->current->get('rdf:first'); + } + } + + /** Return the key / current position in the collection + * + * Note: the first item is number 1 + * + * @return int The current position + */ + public function key() + { + return $this->position; + } + + /** Move forward to next item in the collection + * + */ + public function next() + { + if ($this->position === 1) { + $this->current = $this->get('rdf:rest'); + } elseif ($this->current) { + $this->current = $this->current->get('rdf:rest'); + } + $this->position++; + } + + /** Checks if current position is valid + * + * @return bool True if the current position is valid + */ + public function valid() + { + if ($this->position === 1 and $this->hasProperty('rdf:first')) { + return true; + } elseif ($this->current !== null and $this->current->hasProperty('rdf:first')) { + return true; + } else { + return false; + } + } + + /** Get a node for a particular offset into the collection + * + * This function may not return the item you requested, if + * it does not exist. Please check the $postion parameter + * returned. + * + * If the offset is null, then the last node in the + * collection (before rdf:nil) will be returned. + * + * @param integer $offset The offset into the collection (or null) + * @return array $node, $postion The node object and postion of the node + */ + public function getCollectionNode($offset) + { + $position = 1; + $node = $this; + $nil = $this->graph->resource('rdf:nil'); + while (($rest = $node->get('rdf:rest')) and $rest !== $nil and (is_null($offset) or ($position < $offset))) { + $node = $rest; + $position++; + } + return array($node, $position); + } + + /** Counts the number of items in the collection + * + * Note that this is an slow method - it is more efficient to use + * the iterator interface, if you can. + * + * @return integer The number of items in the collection + */ + public function count() + { + // Find the end of the collection + list($node, $position) = $this->getCollectionNode(null); + if (!$node->hasProperty('rdf:first')) { + return 0; + } else { + return $position; + } + } + + /** Append an item to the end of the collection + * + * @param mixed $value The value to append + * @return integer The number of values appended (1 or 0) + */ + public function append($value) + { + // Find the end of the collection + list($node, $position) = $this->getCollectionNode(null); + $rest = $node->get('rdf:rest'); + + if ($node === $this and is_null($rest)) { + $node->set('rdf:first', $value); + $node->addResource('rdf:rest', 'rdf:nil'); + } else { + $new = $this->graph->newBnode(); + $node->set('rdf:rest', $new); + $new->add('rdf:first', $value); + $new->addResource('rdf:rest', 'rdf:nil'); + } + + return 1; + } + + /** Array Access: check if a position exists in collection using array syntax + * + * Example: isset($list[2]) + */ + public function offsetExists($offset) + { + if (is_int($offset) and $offset > 0) { + list($node, $position) = $this->getCollectionNode($offset); + return ($node and $position === $offset and $node->hasProperty('rdf:first')); + } else { + throw new InvalidArgumentException( + "Collection offset must be a positive integer" + ); + } + } + + /** Array Access: get an item at a specified position in collection using array syntax + * + * Example: $item = $list[2]; + */ + public function offsetGet($offset) + { + if (is_int($offset) and $offset > 0) { + list($node, $position) = $this->getCollectionNode($offset); + if ($node and $position === $offset) { + return $node->get('rdf:first'); + } + } else { + throw new InvalidArgumentException( + "Collection offset must be a positive integer" + ); + } + } + + /** + * Array Access: set an item at a positon in collection using array syntax + * + * Example: $list[2] = $item; + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + // No offset - append to end of collection + $this->append($value); + } elseif (is_int($offset) and $offset > 0) { + list($node, $position) = $this->getCollectionNode($offset); + + // Create nodes, if they are missing + while ($position < $offset) { + $new = $this->graph->newBnode(); + $node->set('rdf:rest', $new); + $new->addResource('rdf:rest', 'rdf:nil'); + $node = $new; + $position++; + } + + // Terminate the list + if (!$node->hasProperty('rdf:rest')) { + $node->addResource('rdf:rest', 'rdf:nil'); + } + + return $node->set('rdf:first', $value); + } else { + throw new InvalidArgumentException( + "Collection offset must be a positive integer" + ); + } + } + + /** + * Array Access: delete an item at a specific postion using array syntax + * + * Example: unset($seq[2]); + */ + public function offsetUnset($offset) + { + if (is_int($offset) and $offset > 0) { + list($node, $position) = $this->getCollectionNode($offset); + } else { + throw new InvalidArgumentException( + "Collection offset must be a positive integer" + ); + } + + // Does the item exist? + if ($node and $position === $offset) { + $nil = $this->graph->resource('rdf:nil'); + if ($position === 1) { + $rest = $node->get('rdf:rest'); + if ($rest and $rest !== $nil) { + // Move second value, so we can keep the head of list + $node->set('rdf:first', $rest->get('rdf:first')); + $node->set('rdf:rest', $rest->get('rdf:rest')); + $rest->delete('rdf:first'); + $rest->delete('rdf:rest'); + } else { + // Just remove the value + $node->delete('rdf:first'); + $node->delete('rdf:rest'); + } + } else { + // Remove the value and re-link the list + $node->delete('rdf:first'); + $rest = $node->get('rdf:rest'); + $previous = $node->get('^rdf:rest'); + if (is_null($rest)) { + $rest = $nil; + } + if ($previous) { + $previous->set('rdf:rest', $rest); + } + } + } + } +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Container.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Container.php new file mode 100644 index 0000000000000000000000000000000000000000..2207956599574fccaf52af7945e8f23c7b0d5598 --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Container.php @@ -0,0 +1,230 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +/** + * Sub-class of EasyRdf_Resource that represents an RDF container + * (rdf:Alt, rdf:Bag and rdf:Seq) + * + * This class can be used to iterate through a list of items. + * + * @package EasyRdf + * @link http://www.w3.org/TR/xmlschema-2/#date + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ +class EasyRdf_Container extends EasyRdf_Resource implements ArrayAccess, Countable, SeekableIterator +{ + private $position; + + /** Create a new container - do not use this directly + * + * @ignore + */ + public function __construct($uri, $graph) + { + $this->position = 1; + parent::__construct($uri, $graph); + } + + /** Seek to a specific position in the container + * + * The first item is postion 1 + * + * @param integer $position The position in the container to seek to + * @throws OutOfBoundsException + */ + public function seek($position) + { + if (is_int($position) and $position > 0) { + if ($this->hasProperty('rdf:_'.$position)) { + $this->position = $position; + } else { + throw new OutOfBoundsException( + "Unable to seek to position $position in the container" + ); + } + } else { + throw new InvalidArgumentException( + "Container position must be a positive integer" + ); + } + } + + /** Rewind the iterator back to the start of the container (item 1) + * + */ + public function rewind() + { + $this->position = 1; + } + + /** Return the current item in the container + * + * @return mixed The current item + */ + public function current() + { + return $this->get('rdf:_'.$this->position); + } + + /** Return the key / current position in the container + * + * @return int The current position + */ + public function key() + { + return $this->position; + } + + /** Move forward to next item in the container + * + */ + public function next() + { + $this->position++; + } + + /** Checks if current position is valid + * + * @return bool True if the current position is valid + */ + public function valid() + { + return $this->hasProperty('rdf:_'.$this->position); + } + + /** Counts the number of items in the container + * + * Note that this is an slow method - it is more efficient to use + * the iterator interface, if you can. + * + * @return integer The number of items in the container + */ + public function count() + { + $pos = 1; + while ($this->hasProperty('rdf:_'.$pos)) { + $pos++; + } + return $pos - 1; + } + + /** Append an item to the end of the container + * + * @param mixed $value The value to append + * @return integer The number of values appended (1 or 0) + */ + public function append($value) + { + // Find the end of the list + $pos = 1; + while ($this->hasProperty('rdf:_'.$pos)) { + $pos++; + } + + // Add the item + return $this->add('rdf:_'.$pos, $value); + } + + /** Array Access: check if a position exists in container using array syntax + * + * Example: isset($seq[2]) + */ + public function offsetExists($offset) + { + if (is_int($offset) and $offset > 0) { + return $this->hasProperty('rdf:_'.$offset); + } else { + throw new InvalidArgumentException( + "Container position must be a positive integer" + ); + } + } + + /** Array Access: get an item at a specified position in container using array syntax + * + * Example: $item = $seq[2]; + */ + public function offsetGet($offset) + { + if (is_int($offset) and $offset > 0) { + return $this->get('rdf:_'.$offset); + } else { + throw new InvalidArgumentException( + "Container position must be a positive integer" + ); + } + } + + /** + * Array Access: set an item at a positon in container using array syntax + * + * Example: $seq[2] = $item; + * + * Warning: creating gaps in the sequence will result in unexpected behavior + */ + public function offsetSet($offset, $value) + { + if (is_int($offset) and $offset > 0) { + return $this->set('rdf:_'.$offset, $value); + } elseif (is_null($offset)) { + return $this->append($value); + } else { + throw new InvalidArgumentException( + "Container position must be a positive integer" + ); + } + } + + /** + * Array Access: delete an item at a specific postion using array syntax + * + * Example: unset($seq[2]); + * + * Warning: creating gaps in the sequence will result in unexpected behavior + */ + public function offsetUnset($offset) + { + if (is_int($offset) and $offset > 0) { + return $this->delete('rdf:_'.$offset); + } else { + throw new InvalidArgumentException( + "Container position must be a positive integer" + ); + } + } +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Exception.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Exception.php index 71530cac2ce5683713a283551031417ebd19bf2f..25090a584c9144177bd7743bffec368b495b3d0e 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Exception.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Exception.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -42,7 +41,7 @@ * All exceptions thrown by EasyRdf are an instance of this class. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Exception extends Exception diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Format.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Format.php index f5bbd5a2a40346c29ffd9b0020bf59921e76548b..031a51dd32311dd81ac59612c8ff4a0664d21d15 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Format.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Format.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -44,7 +43,7 @@ * format. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Format @@ -247,8 +246,8 @@ public static function guessFormat($data, $filename = null) } } - // Then try and guess by the first 255 bytes of content - $short = substr($data, 0, 255); + // Then try and guess by the first 1024 bytes of content + $short = substr($data, 0, 1024); if (preg_match("/^\s*\{/", $short)) { return self::getFormat('json'); } elseif (preg_match("/<rdf:/i", $short)) { @@ -353,7 +352,9 @@ public function setUri($uri) public function getDefaultMimeType() { $types = array_keys($this->mimeTypes); - return $types[0]; + if (isset($types[0])) { + return $types[0]; + } } /** Get all the registered mime types for a format object @@ -388,7 +389,9 @@ public function setMimeTypes($mimeTypes) */ public function getDefaultExtension() { - return $this->extensions[0]; + if (isset($this->extensions[0])) { + return $this->extensions[0]; + } } /** Get all the registered file extensions (filename suffix) for a format object @@ -519,7 +522,11 @@ public function __toString() EasyRdf_Format::register( 'php', 'RDF/PHP', - 'http://n2.talis.com/wiki/RDF_PHP_Specification' + 'http://n2.talis.com/wiki/RDF_PHP_Specification', + array( + 'application/x-httpd-php-source' => 1.0 + ), + array('phps') ); EasyRdf_Format::register( @@ -537,9 +544,10 @@ public function __toString() EasyRdf_Format::register( 'ntriples', 'N-Triples', - 'http://www.w3.org/TR/rdf-testcases/#ntriples', + 'http://www.w3.org/TR/n-triples/', array( - 'text/plain' => 1.0, + 'application/n-triples' => 1.0, + 'text/plain' => 0.9, 'text/ntriples' => 0.9, 'application/ntriples' => 0.9, 'application/x-ntriples' => 0.9 @@ -667,6 +675,7 @@ public function __toString() EasyRdf_Format::registerParser('rdfa', 'EasyRdf_Parser_Rdfa'); EasyRdf_Format::registerSerialiser('json', 'EasyRdf_Serialiser_Json'); +EasyRdf_Format::registerSerialiser('jsonld', 'EasyRdf_Serialiser_JsonLd'); EasyRdf_Format::registerSerialiser('n3', 'EasyRdf_Serialiser_Turtle'); EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Ntriples'); EasyRdf_Format::registerSerialiser('php', 'EasyRdf_Serialiser_RdfPhp'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php index 5bb3ab123fb10b024c99756db3c54de9e6facc3c..ba8ca825a3b70306186b3e75f75ca19a0fb91227 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Container for collection of EasyRdf_Resources. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Graph @@ -158,21 +157,27 @@ public function resource($uri = null, $types = array()) */ protected function classForResource($uri) { - $resClass = 'EasyRdf_Resource'; - $rdfType = EasyRdf_Namespace::expand('rdf:type'); + $rdfType = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; if (isset($this->index[$uri][$rdfType])) { foreach ($this->index[$uri][$rdfType] as $type) { if ($type['type'] == 'uri' or $type['type'] == 'bnode') { $class = EasyRdf_TypeMapper::get($type['value']); if ($class != null) { - $resClass = $class; - break; + return $class; } } - } } - return $resClass; + + // Parsers don't typically add a rdf:type to rdf:List, so we have to + // do a bit of 'inference' here using properties. + if ($uri == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil' or + isset($this->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#first']) or + isset($this->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#rest']) + ) { + return 'EasyRdf_Collection'; + } + return 'EasyRdf_Resource'; } /** @@ -341,7 +346,9 @@ public function load($uri = null, $format = null) public function resources() { foreach ($this->index as $subject => $properties) { - $this->resource($subject); + if (!isset($this->resources[$subject])) { + $this->resource($subject); + } } foreach ($this->revIndex as $object => $properties) { @@ -491,13 +498,11 @@ protected function checkValueParam(&$value) { if (isset($value)) { if (is_object($value)) { - if (method_exists($value, 'toArray')) { - $value = $value->toArray(); - } else { - throw new InvalidArgumentException( - "\$value should respond to the method toArray()" - ); + if (!method_exists($value, 'toRdfPhp')) { + // Convert to a literal object + $value = EasyRdf_Literal::create($value); } + $value = $value->toRdfPhp(); } elseif (is_array($value)) { if (!isset($value['type'])) { throw new InvalidArgumentException( @@ -779,7 +784,7 @@ public function all($resource, $propertyPath, $type = null, $lang = null) $objects = $results; } - return $objects; + return $results; } /** Get all values for a single property of a resource @@ -866,7 +871,7 @@ public function allOfType($type) return $this->all($type, '^rdf:type'); } - /** Count all values for a property of a resource + /** Count the number of values for a property of a resource * * @param string $resource The URI of the resource (e.g. http://example.com/joe#me) * @param string $property The name of the property (e.g. foaf:name) @@ -874,7 +879,7 @@ public function allOfType($type) * @param string $lang The language to filter by (e.g. en) * @return integer The number of values for this property */ - public function count($resource, $property, $type = null, $lang = null) + public function countValues($resource, $property, $type = null, $lang = null) { return count($this->all($resource, $property, $type, $lang)); } @@ -966,25 +971,10 @@ public function addLiteral($resource, $property, $value, $lang = null) $added += $this->addLiteral($resource, $property, $v, $lang); } return $added; - } else { - if ($lang) { - $value = array( - 'type' => 'literal', - 'value' => $value, - 'lang' => $lang - ); - } else { - $value = array( - 'type' => 'literal', - 'value' => $value, - 'datatype' => EasyRdf_Literal::getDatatypeForValue($value) - ); - if (empty($value['datatype'])) { - unset($value['datatype']); - } - } - return $this->add($resource, $property, $value); + } elseif (!is_object($value) or !$value instanceof EasyRdf_Literal) { + $value = EasyRdf_Literal::create($value, $lang); } + return $this->add($resource, $property, $value); } /** Add a resource as a property of another resource @@ -1045,13 +1035,44 @@ public function set($resource, $property, $value) * @return integer The number of values deleted */ public function delete($resource, $property, $value = null) + { + $this->checkResourceParam($resource); + + if (is_object($property) and $property instanceof EasyRdf_Resource) { + return $this->deleteSingleProperty($resource, $property->getUri(), $value); + } elseif (is_string($property) and preg_match('|^(\^?)<(.+)>|', $property, $matches)) { + return $this->deleteSingleProperty($resource, "$matches[1]$matches[2]", $value); + } elseif ($property === null or !is_string($property)) { + throw new InvalidArgumentException( + "\$property should be a string or EasyRdf_Resource and cannot be null" + ); + } elseif ($property === '') { + throw new InvalidArgumentException( + "\$property cannot be an empty string" + ); + } + + // FIXME: finish implementing property paths for delete + return $this->deleteSingleProperty($resource, $property, $value); + } + + + /** Delete a property (or optionally just a specific value) + * + * @param mixed $resource The resource to delete the property from + * @param string $property The name of the property (e.g. foaf:name) + * @param mixed $value The value to delete (null to delete all values) + * @return integer The number of values deleted + * + * @ignore + */ + public function deleteSingleProperty($resource, $property, $value = null) { $this->checkResourceParam($resource); $this->checkSinglePropertyParam($property, $inverse); $this->checkValueParam($value); $count = 0; - $property = EasyRdf_Namespace::expand($property); if (isset($this->index[$resource][$property])) { foreach ($this->index[$resource][$property] as $k => $v) { if (!$value or $v == $value) { @@ -1263,16 +1284,17 @@ public function hasProperty($resource, $property, $value = null) * Example: * $turtle = $graph->serialise('turtle'); * - * @param mixed $format The format to serialise to + * @param mixed $format The format to serialise to + * @param array $options Serialiser-specific options, for fine-tuning the output * @return mixed The serialised graph */ - public function serialise($format) + public function serialise($format, array $options = array()) { if (!$format instanceof EasyRdf_Format) { $format = EasyRdf_Format::getFormat($format); } $serialiser = $format->newSerialiser(); - return $serialiser->serialise($this, $format->getName()); + return $serialiser->serialise($this, $format->getName(), $options); } /** Return a human readable view of all the resources in the graph @@ -1281,13 +1303,13 @@ public function serialise($format) * return a pretty-print view of all the resources and their * properties. * - * @param boolean $html Set to true to format the dump using HTML + * @param string $format Either 'html' or 'text' * @return string */ - public function dump($html = true) + public function dump($format = 'html') { $result = ''; - if ($html) { + if ($format == 'html') { $result .= "<div style='font-family:arial; font-weight: bold; padding:0.5em; ". "color: black; background-color:lightgrey;border:dashed 1px grey;'>". "Graph: ". $this->uri . "</div>\n"; @@ -1296,7 +1318,7 @@ public function dump($html = true) } foreach ($this->index as $resource => $properties) { - $result .= $this->dumpResource($resource, $html); + $result .= $this->dumpResource($resource, $format); } return $result; } @@ -1307,10 +1329,10 @@ public function dump($html = true) * print a resource and its properties. * * @param mixed $resource The resource to dump - * @param boolean $html Set to true to format the dump using HTML + * @param string $format Either 'html' or 'text' * @return string */ - public function dumpResource($resource, $html = true) + public function dumpResource($resource, $format = 'html') { $this->checkResourceParam($resource, true); @@ -1325,9 +1347,9 @@ public function dumpResource($resource, $html = true) $olist = array(); foreach ($values as $value) { if ($value['type'] == 'literal') { - $olist []= EasyRdf_Utils::dumpLiteralValue($value, $html, 'black'); + $olist []= EasyRdf_Utils::dumpLiteralValue($value, $format, 'black'); } else { - $olist []= EasyRdf_Utils::dumpResourceValue($value['value'], $html, 'blue'); + $olist []= EasyRdf_Utils::dumpResourceValue($value['value'], $format, 'blue'); } } @@ -1335,7 +1357,7 @@ public function dumpResource($resource, $html = true) if ($pstr == null) { $pstr = $property; } - if ($html) { + if ($format == 'html') { $plist []= "<span style='font-size:130%'>→</span> ". "<span style='text-decoration:none;color:green'>". htmlentities($pstr) . "</span> ". @@ -1346,11 +1368,11 @@ public function dumpResource($resource, $html = true) } } - if ($html) { - return "<div id='".htmlentities($resource)."' " . + if ($format == 'html') { + return "<div id='".htmlentities($resource, ENT_QUOTES)."' " . "style='font-family:arial; padding:0.5em; ". "background-color:lightgrey;border:dashed 1px grey;'>\n". - "<div>".EasyRdf_Utils::dumpResourceValue($resource, true, 'blue')." ". + "<div>".EasyRdf_Utils::dumpResourceValue($resource, $format, 'blue')." ". "<span style='font-size: 0.8em'>(". $this->classForResource($resource).")</span></div>\n". "<div style='padding-left: 3em'>\n". @@ -1502,7 +1524,7 @@ public function label($resource = null, $lang = null) if ($resource) { return $this->get( $resource, - 'skos:prefLabel|rdfs:label|foaf:name|dc:title|dc11:title', + 'skos:prefLabel|rdfs:label|foaf:name|rss:title|dc:title|dc11:title', 'literal', $lang ); @@ -1534,7 +1556,7 @@ public function primaryTopic($resource = null) * * @return array The contents of the graph as an array. */ - public function toArray() + public function toRdfPhp() { return $this->index; } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php index 3fcc7b433cafb1d7a40f3a52596bf87fb1eea200..19095751ef7f904294463c03653336f28cd7afac 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2011 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * Implementation of the SPARQL 1.1 Graph Store HTTP Protocol. * * @package EasyRdf - * @copyright Copyright (c) 2009-2011 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_GraphStore @@ -116,7 +115,6 @@ protected function sendGraph($method, $graph, $uriRef, $format) $client->setMethod($method); $client->setRawData($data); $client->setHeaders('Content-Type', $mimeType); - $client->setHeaders('Content-Length', strlen($data)); $response = $client->request(); if (!$response->isSuccessful()) { throw new EasyRdf_Exception( diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http.php index c8a1d3dbae86712d4746a4fbcfee8085bccbfae0..47e8bdb14a174f93df9ee7bf4e921f9c4baeb374 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2011 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ @@ -41,7 +40,7 @@ * Static class to set the HTTP client used by EasyRdf * * @package EasyRdf - * @copyright Copyright (c) 2009-2011 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Http diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Client.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Client.php index 57c6fae5239996d335243be75b5b27f51c1b1601..f6b4be8f2431af3e680bd411bd6f17afec23eab3 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Client.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Client.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * Copyright (c) 2005-2009 Zend Technologies USA Inc. * * Redistribution and use in source and binary forms, with or without @@ -32,10 +32,9 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * Copyright (c) 2005-2009 Zend Technologies USA Inc. * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -44,7 +43,7 @@ * implementation try Zend_Http_Client. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Http_Client @@ -426,6 +425,9 @@ public function request($method = null) // Write the request $path = $uri['path']; + if (empty($path)) { + $path = '/'; + } if (isset($uri['query'])) { $path .= '?' . $uri['query']; } @@ -529,7 +531,7 @@ protected function prepareHeaders($host, $port) $headers[] = "User-Agent: {$this->config['useragent']}"; } - // If we have _rawPostData set, set the content-length header + // If we have rawPostData set, set the content-length header if (isset($this->rawPostData)) { $headers[] = "Content-Length: ".strlen($this->rawPostData); } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php index 2abe00aca182af2574ddc43c96d011227c329faa..80edfc225049114e2f963dd9790a599de090fcd2 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Http/Response.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. + * Copyright (c) 2009-2013 Nicholas J Humfrey. * Copyright (c) 2005-2009 Zend Technologies USA Inc. * All rights reserved. * @@ -33,17 +33,16 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class that represents an HTTP 1.0 / 1.1 response message. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * Copyright (c) 2005-2009 Zend Technologies USA Inc. * @license http://www.opensource.org/licenses/bsd-license.php */ diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Isomorphic.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Isomorphic.php new file mode 100644 index 0000000000000000000000000000000000000000..5b461250edc5bdaef1c23bd25f23efbb12527710 --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Isomorphic.php @@ -0,0 +1,436 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +/** + * Functions for comparing two graphs with each other + * + * Based on rdf-isomorphic.rb by Ben Lavender: + * https://github.com/ruby-rdf/rdf-isomorphic + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ +class EasyRdf_Isomorphic +{ + /** + * Check if one graph is isomorphic (equal) to another graph + * + * For example: + * $graphA = EasyRdf_Graph::newAndLoad('http://example.com/a.ttl'); + * $graphB = EasyRdf_Graph::newAndLoad('http://example.com/b.ttl'); + * if (EasyRdf_Isomorphic::isomorphic($graphA, $graphB)) print "Equal!"; + * + * @param object EasyRdf_Graph $graphA The first graph to be compared + * @param object EasyRdf_Graph $graphB The second graph to be compared + * @return boolean True if the two graphs are isomorphic + */ + public static function isomorphic($graphA, $graphB) + { + return is_array(self::bijectionBetween($graphA, $graphB)); + } + + /** + * Returns an associative array of bnode identifiers representing an isomorphic + * bijection of one EasyRdf_Graph to another EasyRdf_Graph's blank nodes or + * null if a bijection cannot be found. + * + * @param object EasyRdf_Graph $graphA The first graph to be compared + * @param object EasyRdf_Graph $graphB The second graph to be compared + * @return array bnode mapping from $graphA to $graphB + */ + public static function bijectionBetween($graphA, $graphB) + { + $bnodesA = array(); + $bnodesB = array(); + $statementsA = array(); + $statementsB = array(); + + // Quick initial check: are there differing numbers of subjects? + if (self::countSubjects($graphA) != self::countSubjects($graphB)) { + return null; + } + + // Check if all the statements in Graph A exist in Graph B + $groundedStatementsMatch = self::groundedStatementsMatch($graphA, $graphB, $bnodesA, $statementsA); + + if ($groundedStatementsMatch) { + // Check if all the statements in Graph B exist in Graph A + $groundedStatementsMatch = self::groundedStatementsMatch($graphB, $graphA, $bnodesB, $statementsB); + } + + if ($groundedStatementsMatch === false) { + // The grounded statements do not match + return null; + } elseif (count($bnodesA) > 0 or count($bnodesB > 0)) { + // There are blank nodes - build a bi-jection + return self::buildBijectionTo($statementsA, $bnodesA, $statementsB, $bnodesB); + } else { + // No bnodes and the grounded statements match + return array(); + } + } + + /** + * Count the number of subjects in a graph + * @ignore + */ + private static function countSubjects($graph) + { + return count($graph->toRdfPhp()); + } + + /** + * Check if all the statements in $graphA also appear in $graphB + * @ignore + */ + private static function groundedStatementsMatch($graphA, $graphB, &$bnodes, &$anonStatements) + { + $groundedStatementsMatch = true; + + foreach ($graphA->toRdfPhp() as $subject => $properties) { + if (substr($subject, 0, 2) == '_:') { + array_push($bnodes, $subject); + $subjectIsBnode = true; + } else { + $subjectIsBnode = false; + } + + foreach ($properties as $property => $values) { + foreach ($values as $value) { + if ($value['type'] == 'uri' and substr($value['value'], 0, 2) == '_:') { + array_push($bnodes, $value['value']); + $objectIsBnode = true; + } else { + $objectIsBnode = false; + } + + if ($groundedStatementsMatch and + $subjectIsBnode === false and + $objectIsBnode === false and + $graphB->hasProperty($subject, $property, $value) === false + ) { + $groundedStatementsMatch = false; + } + + if ($subjectIsBnode or $objectIsBnode) { + array_push( + $anonStatements, + array( + array('type' => $subjectIsBnode ? 'bnode' : 'uri', 'value' => $subject), + array('type' => 'uri', 'value' => $property), + $value + ) + ); + } + } + } + } + + return $groundedStatementsMatch; + } + + /** + * The main recursive bijection algorithm. + * + * This algorithm is very similar to the one explained by Jeremy Carroll in + * http://www.hpl.hp.com/techreports/2001/HPL-2001-293.pdf. Page 12 has the + * relevant pseudocode. + * + * @ignore + */ + private static function buildBijectionTo + ( + $statementsA, + $nodesA, + $statementsB, + $nodesB, + $groundedHashesA = array(), + $groundedHashesB = array() + ) { + + // Create a hash signature of every node, based on the signature of + // statements it exists in. + // We also save hashes of nodes that cannot be reliably known; we will use + // that information to eliminate possible recursion combinations. + // + // Any mappings given in the method parameters are considered grounded. + list($hashesA, $ungroundedHashesA) = self::hashNodes($statementsA, $nodesA, $groundedHashesA); + list($hashesB, $ungroundedHashesB) = self::hashNodes($statementsB, $nodesB, $groundedHashesB); + + // Grounded hashes are built at the same rate between the two graphs (if + // they are isomorphic). If there exists a grounded node in one that is + // not in the other, we can just return. Ungrounded nodes might still + // conflict, so we don't check them. This is a little bit messy in the + // middle of the method, and probably slows down isomorphic checks, but + // prevents almost-isomorphic cases from getting nutty. + foreach ($hashesA as $nodeA => $hashA) { + if (!in_array($hashA, $hashesB)) { + return null; + } + } + foreach ($hashesB as $nodeB => $hashB) { + if (!in_array($hashB, $hashesA)) { + return null; + } + } + + // Using the created hashes, map nodes to other_nodes + // Ungrounded hashes will also be equal, but we keep the distinction + // around for when we recurse later (we only recurse on ungrounded nodes) + $bijection = array(); + foreach ($nodesA as $nodeA) { + $foundNode = null; + foreach ($ungroundedHashesB as $nodeB => $hashB) { + if ($ungroundedHashesA[$nodeA] == $hashB) { + $foundNode = $nodeB; + } + } + + if ($foundNode) { + $bijection[$nodeA] = $foundNode; + + // Deletion is required to keep counts even; two nodes with identical + // signatures can biject to each other at random. + unset($ungroundedHashesB[$foundNode]); + } + } + + // bijection is now a mapping of nodes to other_nodes. If all are + // accounted for on both sides, we have a bijection. + // + // If not, we will speculatively mark pairs with matching ungrounded + // hashes as bijected and recurse. + $bijectionA = array_keys($bijection); + $bijectionB = array_values($bijection); + sort($bijectionA); + sort($nodesA); + sort($bijectionB); + sort($nodesB); + if ($bijectionA != $nodesA or $bijectionB != $nodesB) { + $bijection = null; + + foreach ($nodesA as $nodeA) { + + // We don't replace grounded nodes' hashes + if (isset($hashesA[$nodeA])) { + continue; + } + + foreach ($nodesB as $nodeB) { + // We don't replace grounded nodesB's hashes + if (isset($hashesB[$nodeB])) { + continue; + } + + // The ungrounded signature must match for this to potentially work + if ($ungroundedHashesA[$nodeA] != $ungroundedHashesB[$nodeB]) { + continue; + } + + $hash = sha1($nodeA); + $hashesA[$nodeA] = $hash; + $hashesB[$nodeB] = $hash; + $bijection = self::buildBijectionTo( + $statementsA, + $nodesA, + $statementsB, + $nodesA, + $hashesA, + $hashesB + ); + } + } + } + + return $bijection; + } + + /** + * Given a set of statements, create a mapping of node => SHA1 for a given + * set of blank nodes. grounded_hashes is a mapping of node => SHA1 pairs + * that we will take as a given, and use those to make more specific + * signatures of other nodes. + * + * Returns a tuple of associative arrats: one of grounded hashes, and one of all + * hashes. grounded hashes are based on non-blank nodes and grounded blank + * nodes, and can be used to determine if a node's signature matches + * another. + * + * @ignore + */ + private static function hashNodes($statements, $nodes, $groundedHahes) + { + $hashes = $groundedHahes; + $ungroundedHashes = array(); + $hashNeeded = true; + + // We may have to go over the list multiple times. If a node is marked as + // grounded, other nodes can then use it to decide their own state of + // grounded. + while ($hashNeeded) { + $startingGroundedNodes = count($hashes); + foreach ($nodes as $node) { + if (!isset($hashes[$node])) { + $hash = self::nodeHashFor($node, $statements, $hashes); + if (self::nodeIsGrounded($node, $statements, $hashes)) { + $hashes[$node] = $hash; + } + } + $ungroundedHashes[$node] = $hash; + } + + // after going over the list, any nodes with a unique hash can be marked + // as grounded, even if we have not tied them back to a root yet. + $uniques = array(); + foreach ($ungroundedHashes as $node => $hash) { + $uniques[$hash] = isset($uniques[$hash]) ? false : $node; + } + foreach ($uniques as $hash => $node) { + if ($node) { + $hashes[$node] = $hash; + } + } + $hashNeeded = ($startingGroundedNodes != count($hashes)); + } + + return array($hashes, $ungroundedHashes); + } + + /** + * Generate a hash for a node based on the signature of the statements it + * appears in. Signatures consist of grounded elements in statements + * associated with a node, that is, anything but an ungrounded anonymous + * node. Creating the hash is simply hashing a sorted list of each + * statement's signature, which is itself a concatenation of the string form + * of all grounded elements. + * + * Nodes other than the given node are considered grounded if they are a + * member in the given hash. + * + * Returns a tuple consisting of grounded being true or false and the string + * for the hash + * + * @ignore + */ + private static function nodeHashFor($node, $statements, $hashes) + { + $statement_signatures = array(); + foreach ($statements as $statement) { + foreach ($statement as $n) { + if ($n['type'] != 'literal' and $n['value'] == $node) { + array_push( + $statement_signatures, + self::hashStringFor($statement, $hashes, $node) + ); + } + } + } + + // Note that we sort the signatures--without a canonical ordering, + // we might get different hashes for equivalent nodes + sort($statement_signatures); + + // Convert statements into one long string and hash it + return sha1(implode('', $statement_signatures)); + } + + /** + * Returns true if a given node is grounded + * A node is groundd if it is not a blank node or it is included + * in the given mapping of grounded nodes. + * + * @ignore + */ + private static function nodeIsGrounded($node, $statements, $hashes) + { + $grounded = true; + foreach ($statements as $statement) { + if (in_array($node, $statement)) { + foreach ($statement as $resource) { + if ($node['type'] != 'bnode' or + isset($hashes[$node['value']]) or + $resource == $node + ) { + $grounded = false; + } + } + } + } + return $grounded; + } + + /** + * Provide a string signature for the given statement, collecting + * string signatures for grounded node elements. + * + * @ignore + */ + private static function hashStringFor($statement, $hashes, $node) + { + $str = ""; + foreach ($statement as $r) { + $str .= self::stringForNode($r, $hashes, $node); + } + return $str; + } + + /** + * Provides a string for the given node for use in a string signature + * Non-anonymous nodes will return their string form. Grounded anonymous + * nodes will return their hashed form. + * + * @ignore + */ + private static function stringForNode($node, $hashes, $target) + { + if (is_null($node)) { + return ""; + } elseif ($node['type'] == 'bnode') { + if ($node['value'] == $target) { + return "itself"; + } elseif (isset($hashes[$node['value']])) { + return $hashes[$node['value']]; + } else { + return "a blank node"; + } + } else { + $s = new EasyRdf_Serialiser_Ntriples(); + return $s->serialiseValue($node); + } + } +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php index eadf2a2adf60dab2a81ee862db6a40cdfdde852f..8030e4e785919117e11825901a955c9c603319c6 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class that represents an RDF Literal * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal @@ -91,8 +90,8 @@ public static function create($value, $lang = null, $datatype = null) $value = isset($value['value']) ? $value['value'] : null; } - if (empty($datatype)) { - if (empty($lang)) { + if (is_null($datatype) or $datatype === '') { + if (is_null($lang) or $lang === '') { // Automatic datatype selection $datatype = self::getDatatypeForValue($value); } @@ -275,7 +274,7 @@ public function getLang() * * @return array The properties of the literal */ - public function toArray() + public function toRdfPhp() { $array = array( 'type' => 'literal', @@ -304,12 +303,25 @@ public function __toString() /** Return pretty-print view of the literal * - * @param bool $html Set to true to format the dump using HTML - * @param string $color The colour of the text + * @param string $format Either 'html' or 'text' + * @param string $color The colour of the text * @return string */ - public function dumpValue($html = true, $color = 'black') + public function dumpValue($format = 'html', $color = 'black') { - return EasyRdf_Utils::dumpLiteralValue($this, $html, $color); + return EasyRdf_Utils::dumpLiteralValue($this, $format, $color); } } + +/* + Register default set of datatype classes +*/ + +EasyRdf_Literal::setDatatypeMapping('xsd:boolean', 'EasyRdf_Literal_Boolean'); +EasyRdf_Literal::setDatatypeMapping('xsd:date', 'EasyRdf_Literal_Date'); +EasyRdf_Literal::setDatatypeMapping('xsd:dateTime', 'EasyRdf_Literal_DateTime'); +EasyRdf_Literal::setDatatypeMapping('xsd:decimal', 'EasyRdf_Literal_Decimal'); +EasyRdf_Literal::setDatatypeMapping('xsd:hexBinary', 'EasyRdf_Literal_HexBinary'); +EasyRdf_Literal::setDatatypeMapping('rdf:HTML', 'EasyRdf_Literal_HTML'); +EasyRdf_Literal::setDatatypeMapping('xsd:integer', 'EasyRdf_Literal_Integer'); +EasyRdf_Literal::setDatatypeMapping('rdf:XMLLiteral', 'EasyRdf_Literal_XML'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Boolean.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Boolean.php index d43863a996466fa7d2dc13e2609d8e9159105dd4..d8ca2ed1664e80c1767d396147ef3089de21f162 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Boolean.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Boolean.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#boolean - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_Boolean extends EasyRdf_Literal @@ -92,5 +91,3 @@ public function isFalse() return strtolower($this->value) === 'false' or $this->value === '0'; } } - -EasyRdf_Literal::setDatatypeMapping('xsd:boolean', 'EasyRdf_Literal_Boolean'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php index fb1a687b11b996979bedd8f3fe34c3bb49a55b07..0e05acf2bf80d08fbdac812e8c1c4ee9c5b48d68 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#date - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_Date extends EasyRdf_Literal @@ -49,6 +48,7 @@ class EasyRdf_Literal_Date extends EasyRdf_Literal /** Constructor for creating a new date literal * * If the value is a DateTime object, then it will be converted to the xsd:date format. + * If no value is given or is is null, then the current date is used. * * @see DateTime * @@ -57,8 +57,13 @@ class EasyRdf_Literal_Date extends EasyRdf_Literal * @param string $datatype Optional datatype (default 'xsd:date') * @return object EasyRdf_Literal_Date */ - public function __construct($value, $lang = null, $datatype = null) + public function __construct($value = null, $lang = null, $datatype = null) { + // If $value is null, use today's date + if (is_null($value)) { + $value = new DateTime('today'); + } + // Convert DateTime object into string if ($value instanceof DateTime) { $value = $value->format('Y-m-d'); @@ -130,5 +135,3 @@ public function day() return (int)$this->format('d'); } } - -EasyRdf_Literal::setDatatypeMapping('xsd:date', 'EasyRdf_Literal_Date'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/DateTime.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/DateTime.php index 577badf2bfdff2b0e3f02483b5db42c8985694e6..c1c602d8ef9d459712701af1e6cf33cce436d94a 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/DateTime.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/DateTime.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#date - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_DateTime extends EasyRdf_Literal_Date @@ -49,6 +48,7 @@ class EasyRdf_Literal_DateTime extends EasyRdf_Literal_Date /** Constructor for creating a new date and time literal * * If the value is a DateTime object, then it will be converted to the xsd:dateTime format. + * If no value is given or is is null, then the current time is used. * * @see DateTime * @@ -57,12 +57,17 @@ class EasyRdf_Literal_DateTime extends EasyRdf_Literal_Date * @param string $datatype Optional datatype (default 'xsd:dateTime') * @return object EasyRdf_Literal_DateTime */ - public function __construct($value, $lang = null, $datatype = null) + public function __construct($value = null, $lang = null, $datatype = null) { + // If $value is null, use 'now' + if (is_null($value)) { + $value = new DateTime('now'); + } + // Convert DateTime objects into string if ($value instanceof DateTime) { - $iso = $value->format(DateTime::ISO8601); - $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $iso); + $atom = $value->format(DateTime::ATOM); + $value = preg_replace('/[\+\-]00(\:?)00$/', 'Z', $atom); } EasyRdf_Literal::__construct($value, null, $datatype); @@ -110,5 +115,3 @@ public function sec() return (int)$this->format('s'); } } - -EasyRdf_Literal::setDatatypeMapping('xsd:dateTime', 'EasyRdf_Literal_DateTime'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php index 680c9781cb922368952eb2959deef3914f796c08..59b2cd1bab3b8a0ed54b0d1bd6a740b5a67d2d6a 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#decimal - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_Decimal extends EasyRdf_Literal @@ -67,5 +66,3 @@ public function getValue() return (double)$this->value; } } - -EasyRdf_Literal::setDatatypeMapping('xsd:decimal', 'EasyRdf_Literal_Decimal'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HTML.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HTML.php index 2d0f9381f573c6ebdb566e76039672fb1f624a11..a4915b777ec409ddbcbb60fa74275a78065198b6 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HTML.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HTML.php @@ -33,7 +33,6 @@ * @package EasyRdf * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -69,5 +68,3 @@ public function stripTags($allowableTags = null) return strip_tags($this->value, $allowableTags); } } - -EasyRdf_Literal::setDatatypeMapping('rdf:HTML', 'EasyRdf_Literal_HTML'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php index 2077a6e5fd77b992c712e656d4e4ea2c89209d4f..75ed24e2ca53d5403d6070b2fee6a3f4b4d5e382 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#hexBinary - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_HexBinary extends EasyRdf_Literal @@ -88,5 +87,3 @@ public function toBinary() return pack("H*", $this->value); } } - -EasyRdf_Literal::setDatatypeMapping('xsd:hexBinary', 'EasyRdf_Literal_HexBinary'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Integer.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Integer.php index b12682e084e509d132b3003f501fc63e695d7775..47de413441affd809ad0bd3b82462feff82faaa1 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Integer.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Integer.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * * @package EasyRdf * @link http://www.w3.org/TR/xmlschema-2/#integer - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Literal_Integer extends EasyRdf_Literal @@ -67,5 +66,3 @@ public function getValue() return (int)$this->value; } } - -EasyRdf_Literal::setDatatypeMapping('xsd:integer', 'EasyRdf_Literal_Integer'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/XML.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/XML.php index 0a90c32d97482b71e9a29ba169145faab82ade3d..3f8dd790421e452e34f5c68b96e8b8194b5836ef 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/XML.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/XML.php @@ -33,7 +33,6 @@ * @package EasyRdf * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -70,5 +69,3 @@ public function domParse() return $dom; } } - -EasyRdf_Literal::setDatatypeMapping('rdf:XMLLiteral', 'EasyRdf_Literal_XML'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Namespace.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Namespace.php index 61437b54b9f628b1a00f17d127c8d4861099431a..353d3ba84f327466a7248dfe03f5d3c138e25cf1 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Namespace.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Namespace.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * A namespace registry and manipulation class. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Namespace @@ -192,7 +191,7 @@ public static function getDefault() */ public static function setDefault($namespace) { - if (empty($namespace)) { + if (is_null($namespace) or $namespace === '') { self::$default = null; } elseif (preg_match("/^\w+$/", $namespace)) { if (isset(self::$namespaces[$namespace])) { @@ -329,13 +328,15 @@ public static function shorten($uri, $createNamespace = false) */ public static function expand($shortUri) { - if (!is_string($shortUri) or empty($shortUri)) { + if (!is_string($shortUri) or $shortUri === '') { throw new InvalidArgumentException( "\$shortUri should be a string and cannot be null or empty" ); } - - if (preg_match("/^(\w+?):([\w\-]+)$/", $shortUri, $matches)) { + + if ($shortUri === 'a') { + return self::$namespaces['rdf'] . 'type'; + } elseif (preg_match("/^(\w+?):([\w\-]+)$/", $shortUri, $matches)) { $long = self::get($matches[1]); if ($long) { return $long . $matches[2]; diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php index 0e9f2456a0b885d2cf8df7d41ed235c3f8abe803..0b8dd4769136caea3679c8d6f25c8caf54f86551 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ @@ -41,7 +40,7 @@ * A RFC3986 compliant URI parser * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php * @link http://www.ietf.org/rfc/rfc3986.txt */ diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php index b077847c464a4bfc846654fafbf155b2aa5c43b1..b15b4493c861a3507753ac4f269eb0be204cef25 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Parent class for the EasyRdf parsers * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Arc.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Arc.php index e1a4b068d7ccc19fb031d1a74e5777194d2dcf6f..b4e5e1ef5bf5d6310d5595c078a310643b657f13 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Arc.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Arc.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to parse RDF using the ARC2 library. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Arc extends EasyRdf_Parser_RdfPhp diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Exception.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Exception.php new file mode 100644 index 0000000000000000000000000000000000000000..d03b5bdc93480d6b3d7d88eccd8c8c0ac0b835b7 --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Exception.php @@ -0,0 +1,76 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +/** + * EasyRdf Exception class + * + * All exceptions thrown by EasyRdf are an instance of this class. + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ +class EasyRdf_Parser_Exception extends EasyRdf_Exception +{ + protected $parserLine; + protected $parserColumn; + + public function __construct($message, $line = null, $column = null) + { + $this->parserLine = $line; + $this->parserColumn = $column; + + if (!is_null($line)) { + $message .= " on line $line"; + if (!is_null($column)) { + $message .= ", column $column"; + } + } + + parent::__construct($message); + } + + public function getParserLine() + { + return $this->parserLine; + } + + public function getParserColumn() + { + return $this->parserColumn; + } +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Json.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Json.php index a4a80c98a72f2502ac0f7a81e87464fdaf117c09..ee31d1d8567abb1e3a1cf39597962bf610c7d688 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Json.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Json.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -42,7 +41,7 @@ * http://n2.talis.com/wiki/RDF_JSON_Specification * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Json extends EasyRdf_Parser_RdfPhp @@ -142,7 +141,7 @@ public function parse($graph, $data, $format, $baseUri) $decoded = @json_decode(strval($data), true); if ($decoded === null) { - throw new EasyRdf_Exception( + throw new EasyRdf_Parser_Exception( $this->jsonLastErrorString() ); } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php index af3503ec3dd49090513a9fd8f508eae4b1ea0e06..1392b5bf80075b880bb48b66e96c46f0254795a1 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * A pure-php class to parse N-Triples with no dependancies. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Ntriples extends EasyRdf_Parser @@ -78,21 +77,22 @@ protected function unescapeString($str) while (preg_match('/\\\(U)([0-9A-F]{8})/', $str, $matches) || preg_match('/\\\(u)([0-9A-F]{4})/', $str, $matches)) { $no = hexdec($matches[2]); - if ($no < 128) { + if ($no < 128) { // 0x80 $char = chr($no); - } elseif ($no < 2048) { + } elseif ($no < 2048) { // 0x800 $char = chr(($no >> 6) + 192) . chr(($no & 63) + 128); - } elseif ($no < 65536) { + } elseif ($no < 65536) { // 0x10000 $char = chr(($no >> 12) + 224) . chr((($no >> 6) & 63) + 128) . chr(($no & 63) + 128); - } elseif ($no < 2097152) { + } elseif ($no < 2097152) { // 0x200000 $char = chr(($no >> 18) + 240) . chr((($no >> 12) & 63) + 128) . chr((($no >> 6) & 63) + 128) . chr(($no & 63) + 128); } else { + # FIXME: throw an exception instead? $char = ''; } $str = str_replace('\\' . $matches[1] . $matches[2], $char, $str); @@ -103,7 +103,7 @@ protected function unescapeString($str) /** * @ignore */ - protected function parseNtriplesSubject($sub) + protected function parseNtriplesSubject($sub, $lineNum) { if (preg_match('/<([^<>]+)>/', $sub, $matches)) { return $this->unescapeString($matches[1]); @@ -115,8 +115,9 @@ protected function parseNtriplesSubject($sub) return $this->remapBnode($nodeid); } } else { - throw new EasyRdf_Exception( - "Failed to parse subject: $sub" + throw new EasyRdf_Parser_Exception( + "Failed to parse subject: $sub", + $lineNum ); } } @@ -124,7 +125,7 @@ protected function parseNtriplesSubject($sub) /** * @ignore */ - protected function parseNtriplesObject($obj) + protected function parseNtriplesObject($obj, $lineNum) { if (preg_match('/"(.+)"\^\^<([^<>]+)>/', $obj, $matches)) { return array( @@ -156,8 +157,9 @@ protected function parseNtriplesObject($obj) ); } } else { - throw new EasyRdf_Exception( - "Failed to parse object: $obj" + throw new EasyRdf_Parser_Exception( + "Failed to parse object: $obj", + $lineNum ); } } @@ -181,15 +183,25 @@ public function parse($graph, $data, $format, $baseUri) ); } - $lines = preg_split("/[\r\n]+/", strval($data)); - foreach ($lines as $line) { + $lines = preg_split("/\x0D?\x0A/", strval($data)); + foreach ($lines as $index => $line) { + $lineNum = $index + 1; if (preg_match("/^\s*#/", $line)) { + # Comment continue; - } elseif (preg_match("/(.+)\s+<([^<>]+)>\s+(.+)\s*\./", $line, $matches)) { + } elseif (preg_match("/^\s*(.+?)\s+<([^<>]+?)>\s+(.+?)\s*\.\s*$/", $line, $matches)) { $this->addTriple( - $this->parseNtriplesSubject($matches[1]), + $this->parseNtriplesSubject($matches[1], $lineNum), $this->unescapeString($matches[2]), - $this->parseNtriplesObject($matches[3]) + $this->parseNtriplesObject($matches[3], $lineNum) + ); + } elseif (preg_match("/^\s*$/", $line)) { + # Blank line + continue; + } else { + throw new EasyRdf_Parser_Exception( + "Failed to parse statement", + $lineNum ); } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rapper.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rapper.php index 31983b7dfb95349e5e7a9d4e2d6420902af78ab8..ed12198a21b2a940ca1fec522f025ec0e6604064 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rapper.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rapper.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to parse RDF using the 'rapper' command line tool. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Rapper extends EasyRdf_Parser_Json diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfPhp.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfPhp.php index baf92773ebc3e6a31a6a6832bfbc0ee6a900b3e3..cea3c8a7d78e9aec96f38cdf5458501d865fd0ab 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfPhp.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfPhp.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -42,7 +41,7 @@ * http://n2.talis.com/wiki/RDF_PHP_Specification * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_RdfPhp extends EasyRdf_Parser diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php index 06e27cfcd5e3c8c7667aa6825cd95d85eb61bec6..b7d59fece0908f86ebf680c850cff86345cb0997 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2010-2011 Nicholas J Humfrey + * Copyright (c) 2010-2013 Nicholas J Humfrey * Copyright (c) 2004-2010 Benjamin Nowack (based on ARC2_RDFXMLParser.php) * * Redistribution and use in source and binary forms, with or without @@ -32,9 +32,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2010 Nicholas J Humfrey + * @copyright Copyright (c) 2010-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ @@ -42,7 +41,7 @@ * A pure-php class to parse RDF/XML. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * Copyright (c) 2004-2010 Benjamin Nowack (based on ARC2_RDFXMLParser.php) * @license http://www.opensource.org/licenses/bsd-license.php */ @@ -217,7 +216,7 @@ protected function startElementHandler($p, $t, $a) case 6: return $this->startState6($t, $a); default: - throw new EasyRdf_Exception( + throw new EasyRdf_Parser_Exception( 'startElementHandler() called at state ' . $this->state . ' in '.$t ); } @@ -240,7 +239,7 @@ protected function endElementHandler($p, $t) case 6: return $this->endState6($t); default: - throw new EasyRdf_Exception( + throw new EasyRdf_Parser_Exception( 'endElementHandler() called at state ' . $this->state . ' in '.$t ); } @@ -794,9 +793,11 @@ public function parse($graph, $data, $format, $baseUri) /* parse */ if (!xml_parse($this->xmlParser, $data, false)) { - throw new EasyRdf_Exception( - 'XML error: "' . xml_error_string(xml_get_error_code($this->xmlParser)) . - '" at line ' . xml_get_current_line_number($this->xmlParser) + $message = xml_error_string(xml_get_error_code($this->xmlParser)); + throw new EasyRdf_Parser_Exception( + 'XML error: "' . $message . '"', + xml_get_current_line_number($this->xmlParser), + xml_get_current_column_number($this->xmlParser) ); } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rdfa.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rdfa.php index 9e7902bacd7e4b2cdc7f06feb22fea54920a7fa2..5811fb23bf3deae3a8063c7e01a25df02ce45e22 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rdfa.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Rdfa.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2012 Nicholas J Humfrey. + * Copyright (c) 2012-2013 Nicholas J Humfrey. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,10 +32,9 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * Copyright (c) 1997-2006 Aduna (http://www.aduna-software.com/) * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -44,7 +43,7 @@ * http://www.w3.org/TR/rdfa-core/ * * @package EasyRdf - * @copyright Copyright (c) 2012 Nicholas J Humfrey + * @copyright Copyright (c) 2012-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Rdfa extends EasyRdf_Parser @@ -373,6 +372,28 @@ protected function processNode($node, &$context, $depth = 1) $lang = $node->getAttribute('lang'); } + // HTML+RDFa 1.1: ignore rel and rev unless they contain CURIEs. + foreach (array('rel', 'rev') as $attr) { + if ($node->hasAttribute('property') and $node->hasAttribute($attr)) { + // Quick check in case there are no CURIEs to deal with. + if (strpos($node->getAttribute($attr), ':') === false) { + $node->removeAttribute($attr); + } else { + // Only keep CURIEs. + $curies = array(); + foreach (preg_split("/\s+/", $node->getAttribute($attr)) as $token) { + if (strpos($token, ':')) { + $curies[] = $token; + } + } + $node->setAttribute($attr, implode(' ', $curies)); + } + } + } + + $rels = $this->processUriList($node, $context, $node->getAttribute('rel')); + $revs = $this->processUriList($node, $context, $node->getAttribute('rev')); + if (!$node->hasAttribute('rel') and !$node->hasAttribute('rev')) { // Step 5: Establish a new subject if no rel/rev if ($property and is_null($content) and is_null($datatype)) { @@ -439,8 +460,6 @@ protected function processNode($node, &$context, $depth = 1) $subject = $context['object']; } - $rels = $this->processUriList($node, $context, $node->getAttribute('rel')); - $revs = $this->processUriList($node, $context, $node->getAttribute('rev')); } # FIXME: better place for this? @@ -519,8 +538,8 @@ protected function processNode($node, &$context, $depth = 1) $datatype = $this->processUri($node, $context, $datatype, true); } - if ($node->nodeName === 'data' and $node->hasAttribute('value')) { - $value['value'] = $node->getAttribute('value'); + if ($content !== null) { + $value['value'] = $content; } elseif ($node->hasAttribute('datetime')) { $value['value'] = $node->getAttribute('datetime'); $datetime = true; @@ -531,9 +550,7 @@ protected function processNode($node, &$context, $depth = 1) foreach ($node->childNodes as $child) { $value['value'] .= $child->C14N(); } - } elseif ($content !== null) { - $value['value'] = $content; - } elseif (is_null($datatype) and empty($rel) and empty($rev)) { + } elseif (is_null($datatype) and empty($rels) and empty($revs)) { $value['value'] = $this->getUriAttribute( $node, $context, diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Redland.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Redland.php index c21c02de865319fea00fdcc750f065f8e5eeeee6..bdeb5a2384a703542db9df07e1b75d4d28508ac4 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Redland.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Redland.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to parse RDF using Redland (librdf) C library. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Redland extends EasyRdf_Parser @@ -121,7 +120,7 @@ protected function nodeUriString($node) * Convert a node into an associate array * @ignore */ - protected function nodeToArray($node) + protected function nodeToRdfPhp($node) { $object = array(); $object['type'] = EasyRdf_Parser_Redland::nodeTypeString($node); @@ -211,8 +210,8 @@ public function parse($graph, $data, $format, $baseUri) $stream = librdf_parser_parse_string_as_stream($parser, $data, $rdfUri); if (!$stream) { - throw new EasyRdf_Exception( - "Failed to parse RDF stream for: $rdfUri" + throw new EasyRdf_Parser_Exception( + "Failed to parse RDF stream" ); } @@ -225,7 +224,7 @@ public function parse($graph, $data, $format, $baseUri) $predicate = EasyRdf_Parser_Redland::nodeUriString( librdf_statement_get_predicate($statement) ); - $object = EasyRdf_Parser_Redland::nodeToArray( + $object = EasyRdf_Parser_Redland::nodeToRdfPhp( librdf_statement_get_object($statement) ); @@ -235,7 +234,7 @@ public function parse($graph, $data, $format, $baseUri) $errorCount = $this->parserErrorCount($parser); if ($errorCount) { - throw new EasyRdf_Exception("$errorCount errors while parsing."); + throw new EasyRdf_Parser_Exception("$errorCount errors while parsing."); } librdf_free_uri($rdfUri); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php index bbbec479b1de1ebe50329e47fef63f9168492eb9..3915e32790bec0af1d91dac73159cbb160c1acf9 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php @@ -5,8 +5,8 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. - * Copyright (c) 1997-2006 Aduna (http://www.aduna-software.com/) + * Copyright (c) 2009-2013 Nicholas J Humfrey. + * Copyright (c) 1997-2013 Aduna (http://www.aduna-software.com/) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,24 +33,36 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * Copyright (c) 1997-2006 Aduna (http://www.aduna-software.com/) * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to parse Turtle with no external dependancies. * - * http://www.w3.org/TR/turtle/ - * + * It is a translation from Java to PHP of the Sesame Turtle Parser: + * http://bit.ly/TurtleParser + * + * Lasted updated against version: + * ecda6a15a200a2fc6a062e2e43081257c3ccd4e6 (Mon Jul 29 12:05:58 2013) + * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey - * Copyright (c) 1997-2006 Aduna (http://www.aduna-software.com/) + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey + * Copyright (c) 1997-2013 Aduna (http://www.aduna-software.com/) * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Parser_Turtle extends EasyRdf_Parser_Ntriples { + protected $data; + protected $namespaces; + protected $subject; + protected $predicate; + protected $object; + + protected $line; + protected $column; + /** * Constructor * @@ -80,13 +92,13 @@ public function parse($graph, $data, $format, $baseUri) } $this->data = $data; - $this->len = strlen($data); - $this->pos = 0; - $this->namespaces = array(); $this->subject = null; $this->predicate = null; $this->object = null; + + $this->line = 1; + $this->column = 1; $this->resetBnodeMap(); @@ -106,15 +118,29 @@ public function parse($graph, $data, $format, $baseUri) */ protected function parseStatement() { - $c = $this->peek(); - if ($c == '@') { - $this->parseDirective(); + $directive = ''; + while (true) { + $c = $this->read(); + if ($c == -1 || self::isWhitespace($c)) { + $this->unread($c); + break; + } else { + $directive .= $c; + } + } + + if (preg_match("/^(@|prefix$|base$)/i", $directive)) { + $this->parseDirective($directive); $this->skipWSC(); - $this->verifyCharacter($this->read(), "."); + // SPARQL BASE and PREFIX lines do not end in . + if ($directive[0] == "@") { + $this->verifyCharacterOrFail($this->read(), "."); + } } else { + $this->unread($directive); $this->parseTriples(); $this->skipWSC(); - $this->verifyCharacter($this->read(), "."); + $this->verifyCharacterOrFail($this->read(), "."); } } @@ -122,30 +148,24 @@ protected function parseStatement() * Parse a directive [3] * @ignore */ - protected function parseDirective() + protected function parseDirective($directive) { - // Verify that the first characters form the string "prefix" - $this->verifyCharacter($this->read(), "@"); - - $directive = ''; - - $c = $this->read(); - while ($c != -1 && !self::isWhitespace($c)) { - $directive .= $c; - $c = $this->read(); - } - - if ($directive == "prefix") { + $directive = strtolower($directive); + if ($directive == "prefix" || $directive == '@prefix') { $this->parsePrefixID(); - } elseif ($directive == "base") { + } elseif ($directive == "base" || $directive == '@base') { $this->parseBase(); - } elseif (strlen($directive) == 0) { - throw new EasyRdf_Exception( - "Turtle Parse Error: directive name is missing, expected @prefix or @base" + } elseif (mb_strlen($directive) == 0) { + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: directive name is missing, expected @prefix or @base", + $this->line, + $this->column ); } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: unknown directive \"@$directive\"" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unknown directive \"$directive\"", + $this->line, + $this->column ); } } @@ -169,8 +189,10 @@ protected function parsePrefixID() } elseif (self::isWhitespace($c)) { break; } elseif ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading prefix id" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading prefix id", + $this->line, + $this->column ); } @@ -178,7 +200,7 @@ protected function parsePrefixID() } $this->skipWSC(); - $this->verifyCharacter($this->read(), ":"); + $this->verifyCharacterOrFail($this->read(), ":"); $this->skipWSC(); // Read the namespace URI @@ -206,9 +228,37 @@ protected function parseBase() */ protected function parseTriples() { - $this->parseSubject(); - $this->skipWSC(); - $this->parsePredicateObjectList(); + $c = $this->peek(); + + // If the first character is an open bracket we need to decide which of + // the two parsing methods for blank nodes to use + if ($c == '[') { + $c = $this->read(); + $this->skipWSC(); + $c = $this->peek(); + if ($c == ']') { + $c = $this->read(); + $this->subject = $this->createBNode(); + $this->skipWSC(); + $this->parsePredicateObjectList(); + } else { + $this->unread('['); + $this->subject = $this->parseImplicitBlank(); + } + $this->skipWSC(); + $c = $this->peek(); + + // if this is not the end of the statement, recurse into the list of + // predicate and objects, using the subject parsed above as the subject + // of the statement. + if ($c != '.') { + $this->parsePredicateObjectList(); + } + } else { + $this->parseSubject(); + $this->skipWSC(); + $this->parsePredicateObjectList(); + } $this->subject = null; $this->predicate = null; @@ -233,6 +283,9 @@ protected function parsePredicateObjectList() if ($c == '.' || $c == ']') { break; + } elseif ($c == ';') { + // empty predicateObjectList, skip to next + continue; } $this->predicate = $this->parsePredicate(); @@ -275,8 +328,10 @@ protected function parseSubject() if ($value['type'] == 'uri' or $value['type'] == 'bnode') { $this->subject = $value; } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: illegal subject type: ".$value['type'] + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: illegal subject type: ".$value['type'], + $this->line, + $this->column ); } } @@ -312,8 +367,10 @@ protected function parsePredicate() if ($predicate['type'] == 'uri') { return $predicate; } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: Illegal predicate value: " . $predicate + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: Illegal predicate type: " . $predicate['type'], + $this->line, + $this->column ); } } @@ -351,12 +408,9 @@ protected function parseObject() */ protected function parseImplicitBlank() { - $this->verifyCharacter($this->read(), "["); + $this->verifyCharacterOrFail($this->read(), "["); - $bnode = array( - 'type' => 'bnode', - 'value' => $this->graph->newBNodeId() - ); + $bnode = $this->createBNode(); $c = $this->read(); if ($c != ']') { @@ -377,7 +431,7 @@ protected function parseImplicitBlank() $this->skipWSC(); // Read closing bracket - $this->verifyCharacter($this->read(), "]"); + $this->verifyCharacterOrFail($this->read(), "]"); // Restore previous subject and predicate $this->subject = $oldSubject; @@ -393,7 +447,7 @@ protected function parseImplicitBlank() */ protected function parseCollection() { - $this->verifyCharacter($this->read(), "("); + $this->verifyCharacterOrFail($this->read(), "("); $c = $this->skipWSC(); if ($c == ')') { @@ -404,10 +458,7 @@ protected function parseCollection() 'value' => EasyRdf_Namespace::get('rdf') . 'nil' ); } else { - $listRoot = array( - 'type' => 'bnode', - 'value' => $this->graph->newBNodeId() - ); + $listRoot = $this->createBNode(); // Remember current subject and predicate $oldSubject = $this->subject; @@ -425,10 +476,7 @@ protected function parseCollection() while ($this->skipWSC() != ')') { // Create another list node and link it to the previous - $newNode = array( - 'type' => 'bnode', - 'value' => $this->graph->newBNodeId() - ); + $newNode = $this->createBNode(); $this->addTriple( $bNode['value'], @@ -481,31 +529,34 @@ protected function parseValue() } elseif ($c == '_') { // node ID, e.g. _:n1 return $this->parseNodeID(); - } elseif ($c == '"' or $c == "'") { + } elseif ($c == '"' || $c == "'") { // quoted literal, e.g. "foo" or """foo""" or 'foo' or '''foo''' - return $this->parseQuotedLiteral($c); + return $this->parseQuotedLiteral(); } elseif (ctype_digit($c) || $c == '.' || $c == '+' || $c == '-') { // integer or double, e.g. 123 or 1.2e3 return $this->parseNumber(); } elseif ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading value" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading value", + $this->line, + $this->column ); } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: expected an RDF value here, found '$c'" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: expected an RDF value here, found '$c'", + $this->line, + $this->column ); } } /** * Parses a quoted string, optionally followed by a language tag or datatype. - * @param string $quote The type of quote to use (either ' or ") * @ignore */ - protected function parseQuotedLiteral($quote) + protected function parseQuotedLiteral() { - $label = $this->parseQuotedString($quote); + $label = $this->parseQuotedString(); // Check for presence of a language tag or datatype $c = $this->peek(); @@ -517,20 +568,35 @@ protected function parseQuotedLiteral($quote) $lang = ''; $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading language" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading language", + $this->line, + $this->column ); } elseif (!self::isLanguageStartChar($c)) { - throw new EasyRdf_Exception( - "Turtle Parse Error: expected a letter, found '$c'" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: expected a letter, found '$c'", + $this->line, + $this->column ); } $lang .= $c; $c = $this->read(); - while (self::isLanguageChar($c)) { - $lang .= $c; + while (!self::isWhitespace($c)) { + if ($c == '.' || $c == ';' || $c == ',' || $c == ')' || $c == ']' || $c == -1) { + break; + } + if (self::isLanguageChar($c)) { + $lang .= $c; + } else { + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: illegal language tag char: '$c'", + $this->line, + $this->column + ); + } $c = $this->read(); } @@ -545,7 +611,7 @@ protected function parseQuotedLiteral($quote) $this->read(); // next character should be another '^' - $this->verifyCharacter($this->read(), "^"); + $this->verifyCharacterOrFail($this->read(), "^"); // Read datatype $datatype = $this->parseValue(); @@ -556,8 +622,10 @@ protected function parseQuotedLiteral($quote) 'datatype' => $datatype['value'] ); } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: illegal datatype value: $datatype" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: illegal datatype type: " . $datatype['type'], + $this->line, + $this->column ); } } else { @@ -570,29 +638,30 @@ protected function parseQuotedLiteral($quote) /** * Parses a quoted string, which is either a "normal string" or a """long string""". - * @param string $quote The type of quote to use (either ' or ") * @ignore */ - protected function parseQuotedString($quote) + protected function parseQuotedString() { $result = null; + $c1 = $this->read(); + // First character should be ' or " - $this->verifyCharacter($this->read(), $quote); + $this->verifyCharacterOrFail($c1, "\"\'"); // Check for long-string, which starts and ends with three double quotes $c2 = $this->read(); $c3 = $this->read(); - if ($c2 == $quote && $c3 == $quote) { + if ($c2 == $c1 && $c3 == $c1) { // Long string - $result = $this->parseLongString($quote); + $result = $this->parseLongString($c2); } else { // Normal string $this->unread($c3); $this->unread($c2); - $result = $this->parseString($quote); + $result = $this->parseString($c1); } // Unescape any escape sequences @@ -600,23 +669,25 @@ protected function parseQuotedString($quote) } /** - * Parses a "normal string". This method assumes that the first double quote + * Parses a "normal string". This method requires that the opening character * has already been parsed. - * @param string $quote The type of quote to use (either ' or ") + * @param string $closingCharacter The type of quote to use (either ' or ") * @ignore */ - protected function parseString($quote) + protected function parseString($closingCharacter) { $str = ''; while (true) { $c = $this->read(); - if ($c == $quote) { + if ($c == $closingCharacter) { break; } elseif ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading string" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading string", + $this->line, + $this->column ); } @@ -626,8 +697,10 @@ protected function parseString($quote) // This escapes the next character, which might be a ' or a " $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading string" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading string", + $this->line, + $this->column ); } $str .= $c; @@ -638,12 +711,12 @@ protected function parseString($quote) } /** - * Parses a """long string""". This method assumes that the first three - * double quotes have already been parsed. - * @param string $quote The type of quote to use (either ' or ") + * Parses a """long string""". This method requires that the first three + * characters have already been parsed. + * @param string $closingCharacter The type of quote to use (either ' or ") * @ignore */ - protected function parseLongString($quote) + protected function parseLongString($closingCharacter) { $str = ''; $doubleQuoteCount = 0; @@ -652,10 +725,12 @@ protected function parseLongString($quote) $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading long string" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading long string", + $this->line, + $this->column ); - } elseif ($c == $quote) { + } elseif ($c == $closingCharacter) { $doubleQuoteCount++; } else { $doubleQuoteCount = 0; @@ -667,15 +742,17 @@ protected function parseLongString($quote) // This escapes the next character, which might be a ' or " $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading long string" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading long string", + $this->line, + $this->column ); } $str .= $c; } } - return substr($str, 0, -3); + return mb_substr($str, 0, -3); } /** @@ -701,29 +778,39 @@ protected function parseNumber() } if ($c == '.' || $c == 'e' || $c == 'E') { - // We're parsing a decimal or a double - $datatype = EasyRdf_Namespace::get('xsd').'decimal'; - // read optional fractional digits if ($c == '.') { - $value .= $c; - $c = $this->read(); - while (ctype_digit($c)) { + + if (self::isWhitespace($this->peek())) { + // We're parsing an integer that did not have a space before the + // period to end the statement + } else { $value .= $c; $c = $this->read(); - } - - if (strlen($value) == 1) { - // We've only parsed a '.' - throw new EasyRdf_Exception( - "Turtle Parse Error: object for statement missing" - ); + while (ctype_digit($c)) { + $value .= $c; + $c = $this->read(); + } + + if (mb_strlen($value) == 1) { + // We've only parsed a '.' + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: object for statement missing", + $this->line, + $this->column + ); + } + + // We're parsing a decimal or a double + $datatype = EasyRdf_Namespace::get('xsd').'decimal'; } } else { - if (strlen($value) == 0) { + if (mb_strlen($value) == 0) { // We've only parsed an 'e' or 'E' - throw new EasyRdf_Exception( - "Turtle Parse Error: object for statement missing" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: object for statement missing", + $this->line, + $this->column ); } } @@ -740,8 +827,10 @@ protected function parseNumber() } if (!ctype_digit($c)) { - throw new EasyRdf_Exception( - "Turtle Parse Error: Exponent value missing" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: exponent value missing", + $this->line, + $this->column ); } @@ -775,7 +864,7 @@ protected function parseURI() $uri = ''; // First character should be '<' - $this->verifyCharacter($this->read(), "<"); + $this->verifyCharacterOrFail($this->read(), "<"); // Read up to the next '>' character while (true) { @@ -784,8 +873,10 @@ protected function parseURI() if ($c == '>') { break; } elseif ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading URI" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading URI", + $this->line, + $this->column ); } @@ -795,8 +886,10 @@ protected function parseURI() // This escapes the next character, which might be a '>' $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading URI" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading URI", + $this->line, + $this->column ); } $uri .= $c; @@ -822,13 +915,17 @@ protected function parseQNameOrBoolean() // First character should be a ':' or a letter $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while readying value" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while readying value", + $this->line, + $this->column ); } if ($c != ':' && !self::isPrefixStartChar($c)) { - throw new EasyRdf_Exception( - "Turtle Parse Error: expected a ':' or a letter, found '$c'" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: expected a ':' or a letter, found '$c'", + $this->line, + $this->column ); } @@ -836,10 +933,13 @@ protected function parseQNameOrBoolean() if ($c == ':') { // qname using default namespace - $namespace = $this->namespaces[""]; - if ($namespace == null) { - throw new EasyRdf_Exception( - "Turtle Parse Error: default namespace used but not defined" + if (isset($this->namespaces[''])) { + $namespace = $this->namespaces['']; + } else { + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: default namespace used but not defined", + $this->line, + $this->column ); } } else { @@ -865,13 +965,15 @@ protected function parseQNameOrBoolean() } } - $this->verifyCharacter($c, ":"); + $this->verifyCharacterOrFail($c, ":"); if (isset($this->namespaces[$prefix])) { $namespace = $this->namespaces[$prefix]; } else { - throw new EasyRdf_Exception( - "Turtle Parse Error: namespace prefix '$prefix' used but not defined" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: namespace prefix '$prefix' used but not defined", + $this->line, + $this->column ); } } @@ -880,11 +982,19 @@ protected function parseQNameOrBoolean() $localName = ''; $c = $this->read(); if (self::isNameStartChar($c)) { - $localName .= $c; + if ($c == '\\') { + $localName .= $this->readLocalEscapedChar(); + } else { + $localName .= $c; + } $c = $this->read(); while (self::isNameChar($c)) { - $localName .= $c; + if ($c == '\\') { + $localName .= $this->readLocalEscapedChar(); + } else { + $localName .= $c; + } $c = $this->read(); } } @@ -899,6 +1009,21 @@ protected function parseQNameOrBoolean() ); } + protected function readLocalEscapedChar() + { + $c = $this->read(); + + if (self::isLocalEscapedChar($c)) { + return $c; + } else { + throw new EasyRdf_Parser_Exception( + "found '" . $c . "', expected one of: " . implode(', ', self::$localEscapedChars), + $this->line, + $this->column + ); + } + } + /** * Parses a blank node ID, e.g: _:node1 * @ignore @@ -906,18 +1031,22 @@ protected function parseQNameOrBoolean() protected function parseNodeID() { // Node ID should start with "_:" - $this->verifyCharacter($this->read(), "_"); - $this->verifyCharacter($this->read(), ":"); + $this->verifyCharacterOrFail($this->read(), "_"); + $this->verifyCharacterOrFail($this->read(), ":"); // Read the node ID $c = $this->read(); if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file while reading node id" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file while reading node id", + $this->line, + $this->column ); } elseif (!self::isNameStartChar($c)) { - throw new EasyRdf_Exception( - "Turtle Parse Error: expected a letter, found '$c'" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: expected a letter, found '$c'", + $this->line, + $this->column ); } @@ -952,11 +1081,13 @@ protected function resolve($uri) * exception if this is not the case. * @ignore */ - protected function verifyCharacter($c, $expected) + protected function verifyCharacterOrFail($c, $expected) { if ($c == -1) { - throw new EasyRdf_Exception( - "Turtle Parse Error: unexpected end of file" + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: unexpected end of file", + $this->line, + $this->column ); } elseif (strpbrk($c, $expected) === false) { $msg = 'expected '; @@ -968,7 +1099,11 @@ protected function verifyCharacter($c, $expected) } $msg .= ", found '$c'"; - throw new EasyRdf_Exception("Turtle Parse Error: $msg"); + throw new EasyRdf_Parser_Exception( + "Turtle Parse Error: $msg", + $this->line, + $this->column + ); } } @@ -981,7 +1116,7 @@ protected function skipWSC() $c = $this->read(); while (self::isWhitespace($c) || $c == '#') { if ($c == '#') { - $this->skipLine(); + $this->processComment(); } $c = $this->read(); @@ -995,10 +1130,12 @@ protected function skipWSC() * Consumes characters from reader until the first EOL has been read. * @ignore */ - protected function skipLine() + protected function processComment() { + $comment = ''; $c = $this->read(); while ($c != -1 && $c != "\r" && $c != "\n") { + $comment .= $c; $c = $this->read(); } @@ -1019,9 +1156,16 @@ protected function skipLine() */ protected function read() { - if ($this->pos < $this->len) { - $c = $this->data[$this->pos]; - $this->pos++; + if (!empty($this->data)) { + $c = mb_substr($this->data, 0, 1); + // Keep tracks of which line we are on (0A = Line Feed) + if ($c == "\x0A") { + $this->line += 1; + $this->column = 1; + } else { + $this->column += 1; + } + $this->data = mb_substr($this->data, 1); return $c; } else { return -1; @@ -1035,8 +1179,8 @@ protected function read() */ protected function peek() { - if ($this->pos < $this->len) { - return $this->data[$this->pos]; + if (!empty($this->data)) { + return mb_substr($this->data, 0, 1); } else { return -1; } @@ -1047,13 +1191,20 @@ protected function peek() * Steps back, restoring the previous character read() to the input buffer * @ignore */ - protected function unread() + protected function unread($c) { - if ($this->pos > 0) { - $this->pos--; - } else { - throw new EasyRdf_Exception("Turtle Parse Error: unread error"); - } + # FIXME: deal with unreading new lines + $this->column -= mb_strlen($c); + $this->data = $c . $this->data; + } + + /** @ignore */ + protected function createBNode() + { + return array( + 'type' => 'bnode', + 'value' => $this->graph->newBNodeId() + ); } /** @@ -1063,7 +1214,7 @@ protected function unread() public static function isWhitespace($c) { // Whitespace character are space, tab, newline and carriage return: - return $c == " " || $c == "\t" || $c == "\r" || $c == "\n"; + return $c == "\x20" || $c == "\x09" || $c == "\x0A" || $c == "\x0D"; } /** @ignore */ @@ -1090,7 +1241,13 @@ public static function isPrefixStartChar($c) /** @ignore */ public static function isNameStartChar($c) { - return $c == '_' || self::isPrefixStartChar($c); + return + $c == '\\' || + $c == '_' || + $c == ':' || + $c == '%' || + ctype_digit($c) || + self::isPrefixStartChar($c); } /** @ignore */ @@ -1099,17 +1256,37 @@ public static function isNameChar($c) $o = ord($c); return self::isNameStartChar($c) || + $o >= 0x30 && $o <= 0x39 || # 0-9 $c == '-' || - $o >= 0x30 && $o <= 0x39 || # numeric $o == 0x00B7 || $o >= 0x0300 && $o <= 0x036F || $o >= 0x203F && $o <= 0x2040; } + /** @ignore */ + private static $localEscapedChars = array( + '_', '~', '.', '-', '!', '$', '&', '\'', '(', ')', + '*', '+', ',', ';', '=', '/', '?', '#', '@', '%' + ); + + /** @ignore */ + public static function isLocalEscapedChar($c) + { + return in_array($c, self::$localEscapedChars); + } + /** @ignore */ public static function isPrefixChar($c) { - return self::isNameChar($c); + $o = ord($c); + return + $c == '_' || + $o >= 0x30 && $o <= 0x39 || # 0-9 + self::isPrefixStartChar($c) || + $c == '-' || + $o == 0x00B7 || + $c >= 0x0300 && $c <= 0x036F || + $c >= 0x203F && $c <= 0x2040; } /** @ignore */ @@ -1117,8 +1294,8 @@ public static function isLanguageStartChar($c) { $o = ord($c); return - $o >= 0x41 && $o <= 0x5a || - $o >= 0x61 && $o <= 0x7a; + $o >= 0x41 && $o <= 0x5a || # A-Z + $o >= 0x61 && $o <= 0x7a; # a-z } /** @ignore */ @@ -1126,9 +1303,9 @@ public static function isLanguageChar($c) { $o = ord($c); return - $o >= 0x41 && $o <= 0x5a || # A-Z - $o >= 0x61 && $o <= 0x7a || # a-z - $o >= 0x30 && $o <= 0x39 || # 0-9 + $o >= 0x41 && $o <= 0x5a || # A-Z + $o >= 0x61 && $o <= 0x7a || # a-z + $o >= 0x30 && $o <= 0x39 || # 0-9 $c == '-'; } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Resource.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Resource.php index ee99fbc0b4dcdbc1afb8722059fd814b8eef8200..e5d1e91afd34ae13f6650dbb62e838f15642cf85 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Resource.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Resource.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,25 +31,24 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class that represents an RDF resource * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Resource { /** The URI for this resource */ - private $uri = null; + protected $uri = null; /** The Graph that this resource belongs to */ - private $graph = null; + protected $graph = null; /** Constructor @@ -80,6 +79,16 @@ public function __construct($uri, $graph = null) } } + /** + * Return the graph that this resource belongs to + * + * @return EasyRdf_Graph + */ + public function getGraph() + { + return $this->graph; + } + /** Returns the URI for the resource. * * @return string URI of this resource. @@ -93,7 +102,7 @@ public function getUri() * * @return bool True if this resource is a blank node. */ - public function isBnode() + public function isBNode() { if (substr($this->uri, 0, 2) == '_:') { return true; @@ -108,7 +117,7 @@ public function isBnode() * * @return string The identifer for the bnode */ - public function getNodeId() + public function getBNodeId() { if (substr($this->uri, 0, 2) == '_:') { return substr($this->uri, 2); @@ -181,6 +190,12 @@ public function htmlLink($text = null, $options = array()) $html = "<a"; foreach ($options as $key => $value) { + if (!preg_match('/^[-\w]+$/', $key)) { + throw new InvalidArgumentException( + "\$options should use valid attribute names as keys" + ); + } + $html .= " ".htmlspecialchars($key)."=\"". htmlspecialchars($value)."\""; } @@ -189,16 +204,16 @@ public function htmlLink($text = null, $options = array()) return $html; } - /** Returns the properties of the resource as an associative array + /** Returns the properties of the resource as an RDF/PHP associative array * * For example: * array('type' => 'uri', 'value' => 'http://www.example.com/') * * @return array The properties of the resource */ - public function toArray() + public function toRdfPhp() { - if ($this->isBnode()) { + if ($this->isBNode()) { return array('type' => 'bnode', 'value' => $this->uri); } else { return array('type' => 'uri', 'value' => $this->uri); @@ -207,13 +222,13 @@ public function toArray() /** Return pretty-print view of the resource * - * @param bool $html Set to true to format the dump using HTML + * @param string $format Either 'html' or 'text' * @param string $color The colour of the text * @return string */ - public function dumpValue($html = true, $color = 'blue') + public function dumpValue($format = 'html', $color = 'blue') { - return EasyRdf_Utils::dumpResourceValue($this, $html, $color); + return EasyRdf_Utils::dumpResourceValue($this, $format, $color); } /** Magic method to return URI of resource when casted to string @@ -438,10 +453,10 @@ public function allResources($property) * @param string $lang The language to filter by (e.g. en) * @return integer The number of values associated with the property */ - public function count($property, $type = null, $lang = null) + public function countValues($property, $type = null, $lang = null) { $this->checkHasGraph(); - return $this->graph->count($this->uri, $property, $type, $lang); + return $this->graph->countValues($this->uri, $property, $type, $lang); } /** Concatenate all values for a property into a string. @@ -619,13 +634,13 @@ public function label($lang = null) * This method is intended to be a debugging aid and will * print a resource and its properties. * - * @param bool $html Set to true to format the dump using HTML + * @param string $format Either 'html' or 'text' * @return string */ - public function dump($html = true) + public function dump($format = 'html') { $this->checkHasGraph(); - return $this->graph->dumpResource($this->uri, $html); + return $this->graph->dumpResource($this->uri, $format); } /** Magic method to get a property of a resource diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser.php index 19467faf7579bdb92adac88dbfa468cc0932003b..1c0acb84af9755d1489b5b25d435dda95da76117 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,22 +31,25 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Parent class for the EasyRdf serialiser * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser { protected $prefixes = array(); + public function __construct() + { + } + /** * Keep track of the prefixes used while serialising * @ignore @@ -63,19 +66,17 @@ protected function addPrefix($qname) */ protected function checkSerialiseParams(&$graph, &$format) { - if ($graph == null or !is_object($graph) or - get_class($graph) != 'EasyRdf_Graph') { + if (is_null($graph) or !is_object($graph) or !($graph instanceof EasyRdf_Graph)) { throw new InvalidArgumentException( "\$graph should be an EasyRdf_Graph object and cannot be null" ); } - if ($format == null or $format == '') { + if (is_null($format) or $format == '') { throw new InvalidArgumentException( "\$format cannot be null or empty" ); - } elseif (is_object($format) and - get_class($format) == 'EasyRdf_Format') { + } elseif (is_object($format) and ($format instanceof EasyRdf_Format)) { $format = $format->getName(); } elseif (!is_string($format)) { throw new InvalidArgumentException( @@ -96,7 +97,7 @@ protected function reversePropertyCount($resource) $count = count($properties); if ($count == 1) { $property = $properties[0]; - return $resource->count("^<$property>"); + return $resource->countValues("^<$property>"); } else { return $count; } @@ -106,7 +107,7 @@ protected function reversePropertyCount($resource) * Sub-classes must follow this protocol * @ignore */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { throw new EasyRdf_Exception( "This method should be overridden by sub-classes." diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Arc.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Arc.php index fc79eca1a84d97c0d893ee16826838f8f03514e0..31bd8b7c1f571956eda9ecb6f7c47693b60054d7 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Arc.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Arc.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to serialise RDF using the ARC2 library. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_Arc extends EasyRdf_Serialiser_RdfPhp @@ -65,11 +64,13 @@ public function __construct() /** * Serialise an EasyRdf_Graph into RDF format of choice. * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/GraphViz.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/GraphViz.php index 632f932729d9bdd7246a2c03776ba3a29e0e8950..2fd22dacdf47a8bed5e54877ae677b575f09aee4 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/GraphViz.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/GraphViz.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2012-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -44,7 +43,7 @@ * See http://www.graphviz.org/ for more information. * * @package EasyRdf - * @copyright Copyright (c) 2012 Nicholas J Humfrey + * @copyright Copyright (c) 2012-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_GraphViz extends EasyRdf_Serialiser @@ -185,7 +184,7 @@ public function getAttribute($name) protected function nodeName($entity) { if ($entity instanceof EasyRdf_Resource) { - if ($entity->isBnode()) { + if ($entity->isBNode()) { return "B".$entity->getUri(); } else { return "R".$entity->getUri(); @@ -367,11 +366,13 @@ public function renderImage($graph, $format = 'png') * * Supported output format names: dot, gif, png, svg * - * @param string $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Json.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Json.php index d2bc15ea699e780ee83a39da33e421aabc6e07f2..bc0ae7a41cffa1ece0a0c484e7e8852e6c0374b7 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Json.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Json.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * with no external dependancies. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_Json extends EasyRdf_Serialiser_RdfPhp @@ -51,11 +50,13 @@ class EasyRdf_Serialiser_Json extends EasyRdf_Serialiser_RdfPhp * * http://n2.talis.com/wiki/RDF_JSON_Specification * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception + * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd.php new file mode 100644 index 0000000000000000000000000000000000000000..4265773366633e999ce0e2d0515fc4b250db7941 --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd.php @@ -0,0 +1,42 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +if (PHP_MAJOR_VERSION > 5 or (PHP_MAJOR_VERSION == 5 and PHP_MINOR_VERSION >= 3)) { + require dirname(__FILE__).'/JsonLd_real.php'; +} else { + throw new LogicException("JSON-LD support requires PHP 5.3+"); +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd_real.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd_real.php new file mode 100644 index 0000000000000000000000000000000000000000..a744f0f08461835c1cd15527cc07638753aeff5d --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/JsonLd_real.php @@ -0,0 +1,135 @@ +<?php + +/** + * EasyRdf + * + * LICENSE + * + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package EasyRdf + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey + * @license http://www.opensource.org/licenses/bsd-license.php + */ + +/** + * Class to serialise an EasyRdf_Graph to JSON-LD + * + * @package EasyRdf + * @copyright Copyright (c) 2013 Alexey Zakhlestin + * @license http://www.opensource.org/licenses/bsd-license.php + */ +class EasyRdf_Serialiser_JsonLd extends EasyRdf_Serialiser +{ + public function __construct() + { + if (!class_exists('\ML\JsonLD\JsonLD')) { + throw new LogicException('Please install "ml/json-ld" dependency to use JSON-LD serialisation'); + } + + parent::__construct(); + } + + /** + * @param EasyRdf_Graph $graph + * @param string $format + * @param array $options + * @throws EasyRdf_Exception + * @return string + */ + public function serialise($graph, $format, array $options = array()) + { + parent::checkSerialiseParams($graph, $format); + + if ($format != 'jsonld') { + throw new EasyRdf_Exception(__CLASS__.' does not support: '.$format); + } + + + $ld_graph = new \ML\JsonLD\Graph(); + $nodes = array(); // cache for id-to-node association + + foreach ($graph->toRdfPhp() as $resource => $properties) { + if (array_key_exists($resource, $nodes)) { + $node = $nodes[$resource]; + } else { + $node = $ld_graph->createNode($resource); + $nodes[$resource] = $node; + } + + foreach ($properties as $property => $values) { + foreach ($values as $value) { + if ($value['type'] == 'bnode' or $value['type'] == 'uri') { + if (array_key_exists($value['value'], $nodes)) { + $_value = $nodes[$value['value']]; + } else { + $_value = $ld_graph->createNode($value['value']); + $nodes[$value['value']] = $_value; + } + } elseif ($value['type'] == 'literal') { + if (isset($value['lang'])) { + $_value = new \ML\JsonLD\LanguageTaggedString($value['value'], $value['lang']); + } elseif (isset($value['datatype'])) { + $_value = new \ML\JsonLD\TypedValue($value['value'], $value['datatype']); + } else { + $_value = $value['value']; + } + } else { + throw new EasyRdf_Exception( + "Unable to serialise object to JSON-LD: ".$value['type'] + ); + } + + if ($property == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { + $node->addType($_value); + } else { + $node->addPropertyValue($property, $_value); + } + } + } + } + + // OPTIONS + $use_native_types = !(isset($options['expand_native_types']) and $options['expand_native_types'] == true); + $should_compact = (isset($options['compact']) and $options['compact'] == true); + + // expanded form + $data = $ld_graph->toJsonLd($use_native_types); + + if ($should_compact) { + // compact form + $compact_context = isset($options['context']) ? $options['context'] : null; + $compact_options = array( + 'useNativeTypes' => $use_native_types, + 'base' => $graph->getUri() + ); + + $data = \ML\JsonLD\JsonLD::compact($data, $compact_context, $compact_options); + } + + return \ML\JsonLD\JsonLD::toString($data); + } +} diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php index 02577511e7933beea005cca4e03cecd27b5e59d5..d77a638ce5311db64efae84ab9b4e0aeed380003 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * with no external dependancies. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_Ntriples extends EasyRdf_Serialiser @@ -142,7 +141,7 @@ protected function escapedChar($c) /** * @ignore */ - protected function ntriplesResource($res) + protected function serialiseResource($res) { $escaped = $this->escapeString($res); if (substr($res, 0, 2) == '_:') { @@ -153,12 +152,23 @@ protected function ntriplesResource($res) } /** - * @ignore + * Serialise an RDF value into N-Triples + * + * The value can either be an array in RDF/PHP form, or + * an EasyRdf_Literal or EasyRdf_Resource object. + * + * @param array|object $value An associative array or an object + * @throws EasyRdf_Exception + * @return string The RDF value serialised to N-Triples */ - protected function ntriplesValue($value) + public function serialiseValue($value) { + if (is_object($value)) { + $value = $value->toRdfPhp(); + } + if ($value['type'] == 'uri' or $value['type'] == 'bnode') { - return $this->ntriplesResource($value['value']); + return $this->serialiseResource($value['value']); } elseif ($value['type'] == 'literal') { $escaped = $this->escapeString($value['value']); if (isset($value['lang'])) { @@ -172,7 +182,7 @@ protected function ntriplesValue($value) } } else { throw new EasyRdf_Exception( - "Unable to serialise object to ntriples: ".$value['type'] + "Unable to serialise object of type '".$value['type']."' to ntriples: " ); } } @@ -180,22 +190,24 @@ protected function ntriplesValue($value) /** * Serialise an EasyRdf_Graph into N-Triples * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception + * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); if ($format == 'ntriples') { $nt = ''; - foreach ($graph->toArray() as $resource => $properties) { + foreach ($graph->toRdfPhp() as $resource => $properties) { foreach ($properties as $property => $values) { foreach ($values as $value) { - $nt .= $this->ntriplesResource($resource)." "; + $nt .= $this->serialiseResource($resource)." "; $nt .= "<" . $this->escapeString($property) . "> "; - $nt .= $this->ntriplesValue($value)." .\n"; + $nt .= $this->serialiseValue($value)." .\n"; } } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php index a23b6c30ed37c3209d26137080ae540bb0570e49..ba42bc5e506481c1ea1236c5c798c836a5e40cff 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Rapper.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -43,7 +42,7 @@ * Note: the built-in N-Triples serialiser is used to pass data to Rapper. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_Rapper extends EasyRdf_Serialiser_Ntriples @@ -71,11 +70,12 @@ public function __construct($rapperCmd = 'rapper') /** * Serialise an EasyRdf_Graph to the RDF format of choice. * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfPhp.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfPhp.php index e6a864704b3509cda62249b5d96002b6e188f129..7ec80b031bcf274378ad4c159874e100ecb920a0 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfPhp.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfPhp.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -41,7 +40,7 @@ * with no external dependancies. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_RdfPhp extends EasyRdf_Serialiser @@ -51,11 +50,13 @@ class EasyRdf_Serialiser_RdfPhp extends EasyRdf_Serialiser * * http://n2.talis.com/wiki/RDF_PHP_Specification * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception + * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); @@ -65,7 +66,7 @@ public function serialise($graph, $format) ); } - // Graph is already stored an RDF/PHP resource-centric array internally within the EasyRdf_Graph object - return $graph->toArray(); + // Graph is already stored as RDF/PHP resource-centric array internally within the EasyRdf_Graph object + return $graph->toRdfPhp(); } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php index 1936d8f62dc68a0133a3277f6fc382f92410d6b5..d4485789aab392d056b63f8767b5362b7576fd5f 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php @@ -4,7 +4,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -30,9 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** @@ -40,7 +39,7 @@ * with no external dependancies. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_RdfXml extends EasyRdf_Serialiser @@ -65,7 +64,7 @@ protected function rdfxmlObject($property, $obj, $depth) $tag = "$indent<$property"; if ($obj->isBNode()) { if ($alreadyOutput or $rpcount > 1 or $pcount == 0) { - $tag .= " rdf:nodeID=\"".htmlspecialchars($obj->getNodeId()).'"'; + $tag .= " rdf:nodeID=\"".htmlspecialchars($obj->getBNodeId()).'"'; } } else { if ($alreadyOutput or $rpcount != 1 or $pcount == 0) { @@ -143,29 +142,35 @@ protected function rdfxmlResource($res, $showNodeId, $depth = 1) $xml = "\n$indent<$type"; if ($res->isBNode()) { if ($showNodeId) { - $xml .= ' rdf:nodeID="'.htmlspecialchars($res->getNodeId()).'"'; + $xml .= ' rdf:nodeID="'.htmlspecialchars($res->getBNodeId()).'"'; } } else { $xml .= ' rdf:about="'.htmlspecialchars($res->getUri()).'"'; } $xml .= ">\n"; - foreach ($properties as $property) { - $short = EasyRdf_Namespace::shorten($property, true); - if ($short) { - $this->addPrefix($short); - $objects = $res->all("<$property>"); - if ($short == 'rdf:type') { - array_shift($objects); - } - foreach ($objects as $object) { - $xml .= $this->rdfxmlObject($short, $object, $depth+1); + if ($res instanceof EasyRdf_Container) { + foreach ($res as $item) { + $xml .= $this->rdfxmlObject('rdf:li', $item, $depth+1); + } + } else { + foreach ($properties as $property) { + $short = EasyRdf_Namespace::shorten($property, true); + if ($short) { + $this->addPrefix($short); + $objects = $res->all("<$property>"); + if ($short == 'rdf:type') { + array_shift($objects); + } + foreach ($objects as $object) { + $xml .= $this->rdfxmlObject($short, $object, $depth+1); + } + } else { + throw new EasyRdf_Exception( + "It is not possible to serialse the property ". + "'$property' to RDF/XML." + ); } - } else { - throw new EasyRdf_Exception( - "It is not possible to serialse the property ". - "'$property' to RDF/XML." - ); } } $xml .= "$indent</$type>\n"; @@ -177,11 +182,13 @@ protected function rdfxmlResource($res, $showNodeId, $depth = 1) /** * Method to serialise an EasyRdf_Graph to RDF/XML * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception + * @return string The RDF in the new desired format. */ - public function serialise($graph, $format) + public function serialise($graph, $format, array $options = array()) { parent::checkSerialiseParams($graph, $format); @@ -198,8 +205,19 @@ public function serialise($graph, $format) $this->outputtedResources = array(); $xml = ''; + + // Serialise URIs first foreach ($graph->resources() as $resource) { - $xml .= $this->rdfxmlResource($resource, true, 1); + if (!$resource->isBnode()) { + $xml .= $this->rdfxmlResource($resource, true); + } + } + + // Serialise bnodes afterwards + foreach ($graph->resources() as $resource) { + if ($resource->isBnode()) { + $xml .= $this->rdfxmlResource($resource, true); + } } // iterate through namepsaces array prefix and output a string. diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php index dfc817d9b818f1d771604f81320a9e38ed828e99..0a89d38cd87a68ea980ee755e3d44c9d12cc1b87 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,19 +31,18 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to serialise an EasyRdf_Graph to Turtle * with no external dependancies. * - * http://www.dajobe.org/2004/01/turtle + * http://www.w3.org/TR/turtle/ * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Serialiser_Turtle extends EasyRdf_Serialiser @@ -51,28 +50,26 @@ class EasyRdf_Serialiser_Turtle extends EasyRdf_Serialiser private $outputtedBnodes = array(); /** - * @ignore + * Given a IRI string, escape and enclose in angle brackets. + * + * @param string $resourceIri + * @return string */ - protected function serialiseResource($resource) + public static function escapeIri($resourceIri) { - if ($resource->isBnode()) { - return $resource->getUri(); - } else { - $short = $resource->shorten(); - if ($short) { - $this->addPrefix($short); - return $short; - } else { - $uri = str_replace('>', '\\>', $resource); - return "<$resource>"; - } - } + $escapedIri = str_replace('>', '\\>', $resourceIri); + return "<$escapedIri>"; } /** - * @ignore + * Given a string, enclose in quotes and escape any quotes in the string. + * Strings containing tabs, linefeeds or carriage returns will be + * enclosed in three double quotes ("""). + * + * @param string $value + * @return string */ - protected function quotedString($value) + public static function quotedString($value) { if (preg_match("/[\t\n\r]/", $value)) { $escaped = str_replace(array('\\', '"""'), array('\\\\', '\\"""'), $value); @@ -84,41 +81,122 @@ protected function quotedString($value) } /** - * @ignore + * Given a an EasyRdf_Resource or URI, convert it into a string, suitable to + * be written to a Turtle document. URIs will be shortened into CURIES + * where possible. + * + * @param EasyRdf_Resource $resource The resource to convert to a Turtle string + * @param boolean $createNamespace If true, a new namespace may be created + * @return string + */ + public function serialiseResource($resource, $createNamespace = false) + { + if (is_object($resource)) { + if ($resource->isBNode()) { + return $resource->getUri(); + } else { + $resource = $resource->getUri(); + } + } + + $short = EasyRdf_Namespace::shorten($resource, $createNamespace); + if ($short) { + $this->addPrefix($short); + return $short; + } else { + return self::escapeIri($resource); + } + } + + /** + * Given an EasyRdf_Literal object, convert it into a string, suitable to + * be written to a Turtle document. Supports multiline literals and literals with + * datatypes or languages. + * + * @param EasyRdf_Literal $literal + * @return string + */ + public function serialiseLiteral($literal) + { + $value = strval($literal); + $quoted = self::quotedString($value); + + if ($datatype = $literal->getDatatypeUri()) { + if ($datatype == 'http://www.w3.org/2001/XMLSchema#integer') { + return sprintf('%d', $value); + } elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#decimal') { + return sprintf('%g', $value); + } elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#double') { + return sprintf('%e', $value); + } elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#boolean') { + return sprintf('%s', $value ? 'true' : 'false'); + } else { + $escaped = $this->serialiseResource($datatype, true); + return sprintf('%s^^%s', $quoted, $escaped); + } + } elseif ($lang = $literal->getLang()) { + return $quoted . '@' . $lang; + } else { + return $quoted; + } + } + + /** + * Convert an EasyRdf object into a string suitable to + * be written to a Turtle document. + * + * @param EasyRdf_Resource|EasyRdf_Literal $object + * @return string */ - protected function serialiseObject($object) + public function serialiseObject($object) { if ($object instanceof EasyRdf_Resource) { return $this->serialiseResource($object); + } elseif ($object instanceof EasyRdf_Literal) { + return $this->serialiseLiteral($object); } else { - $value = strval($object); - $quoted = $this->quotedString($value); - - if ($datatype = $object->getDatatypeUri()) { - $short = EasyRdf_Namespace::shorten($datatype, true); - if ($short) { - $this->addPrefix($short); - if ($short == 'xsd:integer') { - return sprintf('%d', $value); - } elseif ($short == 'xsd:decimal') { - return sprintf('%g', $value); - } elseif ($short == 'xsd:double') { - return sprintf('%e', $value); - } elseif ($short == 'xsd:boolean') { - return sprintf('%s', $value ? 'true' : 'false'); - } else { - return sprintf('%s^^%s', $quoted, $short); - } + throw new InvalidArgumentException( + "serialiseObject() requires \$object to be ". + "of type EasyRdf_Resource or EasyRdf_Literal" + ); + } + } + + + /** + * Protected method to serialise a RDF collection + * @ignore + */ + protected function serialiseCollection($node, $indent) + { + $turtle = '('; + $count = 0; + while ($node) { + if ($id = $node->getBNodeId()) { + $this->outputtedBnodes[$id] = true; + } + + $value = $node->get('rdf:first'); + $node = $node->get('rdf:rest'); + if ($node and $node->hasProperty('rdf:first')) { + $count++; + } + + if ($value !== null) { + $serialised = $this->serialiseObject($value); + if ($count) { + $turtle .= "\n$indent $serialised"; } else { - $datatypeUri = str_replace('>', '\\>', $datatype); - return sprintf('%s^^<%s>', $quoted, $datatypeUri); + $turtle .= " ".$serialised; } - } elseif ($lang = $object->getLang()) { - return $quoted . '@' . $lang; - } else { - return $quoted; } } + if ($count) { + $turtle .= "\n$indent)"; + } else { + $turtle .= " )"; + } + return $turtle; } /** @@ -137,16 +215,10 @@ protected function serialiseProperties($res, $depth = 1) $pCount = 0; foreach ($properties as $property) { - $short = EasyRdf_Namespace::shorten($property, true); - if ($short) { - if ($short == 'rdf:type') { - $pStr = 'a'; - } else { - $this->addPrefix($short); - $pStr = $short; - } + if ($property === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') { + $pStr = 'a'; } else { - $pStr = '<'.str_replace('>', '\\>', $property).'>'; + $pStr = $this->serialiseResource($property, true); } if ($pCount) { @@ -161,8 +233,10 @@ protected function serialiseProperties($res, $depth = 1) $turtle .= ','; } - if ($object instanceof EasyRdf_Resource and $object->isBnode()) { - $id = $object->getNodeId(); + if ($object instanceof EasyRdf_Collection) { + $turtle .= ' ' . $this->serialiseCollection($object, $indent); + } elseif ($object instanceof EasyRdf_Resource and $object->isBNode()) { + $id = $object->getBNodeId(); $rpcount = $this->reversePropertyCount($object); if ($rpcount <= 1 and !isset($this->outputtedBnodes[$id])) { // Nested unlabelled Blank Node @@ -208,41 +282,33 @@ protected function serialisePrefixes() } /** - * Serialise an EasyRdf_Graph to Turtle. - * - * @param object EasyRdf_Graph $graph An EasyRdf_Graph object. - * @param string $format The name of the format to convert to. - * @return string The RDF in the new desired format. + * @ignore */ - public function serialise($graph, $format) + protected function serialiseSubjects($graph, $filterType) { - parent::checkSerialiseParams($graph, $format); - - if ($format != 'turtle' and $format != 'n3') { - throw new EasyRdf_Exception( - "EasyRdf_Serialiser_Turtle does not support: $format" - ); - } - - $this->prefixes = array(); - $this->outputtedBnodes = array(); - $turtle = ''; foreach ($graph->resources() as $resource) { + /** @var $resource EasyRdf_Resource */ // If the resource has no properties - don't serialise it $properties = $resource->propertyUris(); if (count($properties) == 0) { continue; } - if ($resource->isBnode()) { - $id = $resource->getNodeId(); - $rpcount = $this->reversePropertyCount($resource); + // Is this node of the right type? + $thisType = $resource->isBNode() ? 'bnode' : 'uri'; + if ($thisType != $filterType) { + continue; + } + + if ($thisType == 'bnode') { + $id = $resource->getBNodeId(); if (isset($this->outputtedBnodes[$id])) { // Already been serialised continue; } else { $this->outputtedBnodes[$id] = true; + $rpcount = $this->reversePropertyCount($resource); if ($rpcount == 0) { $turtle .= '[]'; } else { @@ -256,6 +322,34 @@ public function serialise($graph, $format) $turtle .= $this->serialiseProperties($resource); $turtle .= "\n"; } + return $turtle; + } + + /** + * Serialise an EasyRdf_Graph to Turtle. + * + * @param EasyRdf_Graph $graph An EasyRdf_Graph object. + * @param string $format The name of the format to convert to. + * @param array $options + * @throws EasyRdf_Exception + * @return string The RDF in the new desired format. + */ + public function serialise($graph, $format, array $options = array()) + { + parent::checkSerialiseParams($graph, $format); + + if ($format != 'turtle' and $format != 'n3') { + throw new EasyRdf_Exception( + "EasyRdf_Serialiser_Turtle does not support: $format" + ); + } + + $this->prefixes = array(); + $this->outputtedBnodes = array(); + + $turtle = ''; + $turtle .= $this->serialiseSubjects($graph, 'uri'); + $turtle .= $this->serialiseSubjects($graph, 'bnode'); if (count($this->prefixes)) { return $this->serialisePrefixes() . "\n" . $turtle; diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php index 35eca3da72319e3ca31064c89649700c0ed83fcc..2cf9ad55808dec1a3e8c9f504634405404f7d362 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,22 +31,24 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class for making SPARQL queries using the SPARQL 1.1 Protocol * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Sparql_Client { - /** The address of the SPARQL Endpoint */ - private $uri = null; + /** The query/read address of the SPARQL Endpoint */ + private $queryUri = null; + + /** The update/write address of the SPARQL Endpoint */ + private $updateUri = null; /** Configuration settings */ private $config = array(); @@ -54,20 +56,47 @@ class EasyRdf_Sparql_Client /** Create a new SPARQL endpoint client * - * @param string $uri The address of the SPARQL Endpoint + * If the query and update endpoints are the same, then you + * only need to give a single URI. + * + * @param string $queryUri The address of the SPARQL Query Endpoint + * @param string $updateUri Optional address of the SPARQL Update Endpoint + */ + public function __construct($queryUri, $updateUri = null) + { + $this->queryUri = $queryUri; + if ($updateUri) { + $this->updateUri = $updateUri; + } else { + $this->updateUri = $queryUri; + } + } + + /** Get the URI of the SPARQL query endpoint + * + * @return string The query URI of the SPARQL endpoint */ - public function __construct($uri) + public function getQueryUri() { - $this->uri = $uri; + return $this->queryUri; } - /** Get the URI of the SPARQL endpoint + /** Get the URI of the SPARQL update endpoint * - * @return string The URI of the SPARQL endpoint + * @return string The query URI of the SPARQL endpoint + */ + public function getUpdateUri() + { + return $this->updateUri; + } + + /** + * @depredated + * @ignore */ public function getUri() { - return $this->uri; + return $this->queryUri; } /** Make a query to the SPARQL endpoint @@ -83,7 +112,119 @@ public function getUri() */ public function query($query) { - # Add namespaces to the queryString + return $this->request('query', $query); + } + + /** Count the number of triples in a SPARQL 1.1 endpoint + * + * Performs a SELECT query to estriblish the total number of triples. + * + * Counts total number of triples by default but a conditional triple pattern + * can be given to count of a subset of all triples. + * + * @param string $condition Triple-pattern condition for the count query + * @return integer The number of triples + */ + public function countTriples($condition = '?s ?p ?o') + { + // SELECT (COUNT(*) AS ?count) + // WHERE { + // {?s ?p ?o} + // UNION + // {GRAPH ?g {?s ?p ?o}} + // } + $result = $this->query('SELECT (COUNT(*) AS ?count) {'.$condition.'}'); + return $result[0]->count->getValue(); + } + + /** Get a list of named graphs from a SPARQL 1.1 endpoint + * + * Performs a SELECT query to get a list of the named graphs + * + * @param string $limit Optional limit to the number of results + * @return array Array of EasyRdf_Resource objects for each named graph + */ + public function listNamedGraphs($limit = null) + { + $query = "SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}"; + if (!is_null($limit)) { + $query .= " LIMIT ".(int)$limit; + } + $result = $this->query($query); + + // Convert the result object into an array of resources + $graphs = array(); + foreach ($result as $row) { + array_push($graphs, $row->g); + } + return $graphs; + } + + /** Make an update request to the SPARQL endpoint + * + * Successful responses will return the HTTP response object + * + * Unsuccessful responses will throw an exception + * + * @param string $query The update query string to be executed + * @return object EasyRdf_Http_Response HTTP response + */ + public function update($query) + { + return $this->request('update', $query); + } + + public function insert($data, $graphUri = null) + { + #$this->updateData('INSET', + $query = 'INSERT DATA {'; + if ($graphUri) { + $query .= "GRAPH <$graphUri> {"; + } + $query .= $this->convertToTriples($data); + if ($graphUri) { + $query .= "}"; + } + $query .= '}'; + return $this->update($query); + } + + protected function updateData($operation, $data, $graphUri = null) + { + $query = "$operation DATA {"; + if ($graphUri) { + $query .= "GRAPH <$graphUri> {"; + } + $query .= $this->convertToTriples($data); + if ($graphUri) { + $query .= "}"; + } + $query .= '}'; + return $this->update($query); + } + + public function clear($graphUri, $silent = false) + { + $query = "CLEAR"; + if ($silent) { + $query .= " SILENT"; + } + if (preg_match("/^all|named|default$/i", $graphUri)) { + $query .= " $graphUri"; + } else { + $query .= " GRAPH <$graphUri>"; + } + return $this->update($query); + } + + /* + * Internal function to make an HTTP request to SPARQL endpoint + * + * @ignore + */ + protected function request($type, $query) + { + // Check for undefined prefixes $prefixes = ''; foreach (EasyRdf_Namespace::namespaces() as $prefix => $uri) { if (strpos($query, "$prefix:") !== false and @@ -94,9 +235,8 @@ public function query($query) $client = EasyRdf_Http::getDefaultHttpClient(); $client->resetParameters(); - $client->setUri($this->uri); - $client->setMethod('GET'); + // Tell the server which response formats we can parse $accept = EasyRdf_Format::getHttpAcceptHeader( array( 'application/sparql-results+json' => 1.0, @@ -104,17 +244,40 @@ public function query($query) ) ); $client->setHeaders('Accept', $accept); - $client->setParameterGet('query', $prefixes . $query); + + if ($type == 'update') { + $client->setMethod('POST'); + $client->setUri($this->updateUri); + $client->setRawData($prefixes . $query); + $client->setHeaders('Content-Type', 'application/sparql-update'); + } elseif ($type == 'query') { + // Use GET if the query is less than 2kB + // 2046 = 2kB minus 1 for '?' and 1 for NULL-terminated string on server + $encodedQuery = 'query='.urlencode($prefixes . $query); + if (strlen($encodedQuery) + strlen($this->queryUri) <= 2046) { + $client->setMethod('GET'); + $client->setUri($this->queryUri.'?'.$encodedQuery); + } else { + // Fall back to POST instead (which is un-cacheable) + $client->setMethod('POST'); + $client->setUri($this->queryUri); + $client->setRawData($encodedQuery); + $client->setHeaders('Content-Type', 'application/x-www-form-urlencoded'); + } + } $response = $client->request(); - if ($response->isSuccessful()) { + if ($response->getStatus() == 204) { + // No content + return $response; + } elseif ($response->isSuccessful()) { list($type, $params) = EasyRdf_Utils::parseMimeType( $response->getHeader('Content-Type') ); if (strpos($type, 'application/sparql-results') === 0) { return new EasyRdf_Sparql_Result($response->getBody(), $type); } else { - return new EasyRdf_Graph($this->uri, $response->getBody(), $type); + return new EasyRdf_Graph($this->queryUri, $response->getBody(), $type); } } else { throw new EasyRdf_Exception( @@ -123,12 +286,17 @@ public function query($query) } } - /** Magic method to return URI of the SPARQL endpoint when casted to string - * - * @return string The URI of the SPARQL endpoint - */ - public function __toString() + protected function convertToTriples($data) { - return $this->uri == null ? '' : $this->uri; + if (is_string($data)) { + return $data; + } elseif (is_object($data) and $data instanceof EasyRdf_Graph) { + # FIXME: insert Turtle when there is a way of seperateing out the prefixes + return $data->serialise('ntriples'); + } else { + throw new EasyRdf_Exception( + "Don't know how to convert to triples for SPARQL query: ".$response->getBody() + ); + } } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php index 6bc7f62aae526459fc58dbada7d85722c96729c3..22001e9f356577bcba10965aa0b329aaac6ed6c1 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class for returned for SPARQL SELECT and ASK query responses. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Sparql_Result extends ArrayIterator @@ -152,13 +151,13 @@ public function getFields() * This method is intended to be a debugging aid and will * return a pretty-print view of the query result. * - * @param bool $html Set to true to format the dump using HTML + * @param string $format Either 'text' or 'html' */ - public function dump($html = true) + public function dump($format = 'html') { if ($this->type == 'bindings') { $result = ''; - if ($html) { + if ($format == 'html') { $result .= "<table class='sparql-results' style='border-collapse:collapse'>"; $result .= "<tr>"; foreach ($this->fields as $field) { @@ -170,9 +169,13 @@ public function dump($html = true) foreach ($this as $row) { $result .= "<tr>"; foreach ($this->fields as $field) { - $result .= "<td style='border:solid 1px #000;padding:4px;". - "vertical-align:top'>". - $row->$field->dumpValue($html)."</td>"; + if (isset($row->$field)) { + $result .= "<td style='border:solid 1px #000;padding:4px;". + "vertical-align:top'>". + $row->$field->dumpValue($format)."</td>"; + } else { + $result .= "<td> </td>"; + } } $result .= "</tr>"; } @@ -188,7 +191,7 @@ public function dump($html = true) foreach ($this as $row) { $textRow = array(); foreach ($row as $k => $v) { - $textRow[$k] = $v->dumpValue(false); + $textRow[$k] = $v->dumpValue('text'); $width = strlen($textRow[$k]); if ($colWidths[$k] < $width) { $colWidths[$k] = $width; @@ -224,7 +227,7 @@ public function dump($html = true) return $result; } elseif ($this->type == 'boolean') { $str = ($this->boolean ? 'true' : 'false'); - if ($html) { + if ($format == 'html') { return "<p>Result: <span style='font-weight:bold'>$str</span></p>"; } else { return "Result: $str"; @@ -375,7 +378,7 @@ public function __toString() if ($this->type == 'boolean') { return $this->boolean ? 'true' : 'false'; } else { - return $this->dump(false); + return $this->dump('text'); } } } diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/TypeMapper.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/TypeMapper.php index b2deaf074993ab392fe92436089c827155249700..81404d2737cd2bb74216b8db649e71e9ff36bccd 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/TypeMapper.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/TypeMapper.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,16 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ /** * Class to map between RDF Types and PHP Classes * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_TypeMapper @@ -114,3 +113,13 @@ public static function delete($type) } } } + + +/* + Register default set of mapped types +*/ + +EasyRdf_TypeMapper::set('rdf:Alt', 'EasyRdf_Container'); +EasyRdf_TypeMapper::set('rdf:Bag', 'EasyRdf_Container'); +EasyRdf_TypeMapper::set('rdf:List', 'EasyRdf_Collection'); +EasyRdf_TypeMapper::set('rdf:Seq', 'EasyRdf_Container'); diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php index a48686b7cf581d0dd7275df116695584d5f34275..1c2d7dde620ffa41fe2b084f35a0d4a4944af9f4 100644 --- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php +++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php @@ -5,7 +5,7 @@ * * LICENSE * - * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved. + * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -31,9 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package EasyRdf - * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php - * @version $Id$ */ @@ -41,7 +40,7 @@ * Class containing static utility functions * * @package EasyRdf - * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey + * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey * @license http://www.opensource.org/licenses/bsd-license.php */ class EasyRdf_Utils @@ -112,13 +111,19 @@ public static function removeFragmentFromUri($uri) * EasyRdf_Graph and EasyRdf_Sparql_Result to format a resource * for display. * - * @param mixed $resource An EasyRdf_Resource object or an associative array - * @param bool $html Set to true to format the dump using HTML - * @param string $color The colour of the text + * @param mixed $resource An EasyRdf_Resource object or an associative array + * @param string $format Either 'html' or 'text' + * @param string $color The colour of the text * @return string */ - public static function dumpResourceValue($resource, $html = true, $color = 'blue') + public static function dumpResourceValue($resource, $format = 'html', $color = 'blue') { + if (!preg_match('/^#?[-\w]+$/', $color)) { + throw new InvalidArgumentException( + "\$color must be a legal color code or name" + ); + } + if (is_object($resource)) { $resource = strval($resource); } elseif (is_array($resource)) { @@ -126,8 +131,8 @@ public static function dumpResourceValue($resource, $html = true, $color = 'blue } $short = EasyRdf_Namespace::shorten($resource); - if ($html) { - $escaped = htmlentities($resource); + if ($format == 'html') { + $escaped = htmlentities($resource, ENT_QUOTES); if (substr($resource, 0, 2) == '_:') { $href = '#' . $escaped; } else { @@ -153,15 +158,21 @@ public static function dumpResourceValue($resource, $html = true, $color = 'blue * EasyRdf_Graph and EasyRdf_Sparql_Result to format a literal * for display. * - * @param mixed $literal An EasyRdf_Literal object or an associative array - * @param bool $html Set to true to format the dump using HTML - * @param string $color The colour of the text + * @param mixed $literal An EasyRdf_Literal object or an associative array + * @param string $format Either 'html' or 'text' + * @param string $color The colour of the text * @return string */ - public static function dumpLiteralValue($literal, $html = true, $color = 'black') + public static function dumpLiteralValue($literal, $format = 'html', $color = 'black') { + if (!preg_match('/^#?[-\w]+$/', $color)) { + throw new InvalidArgumentException( + "\$color must be a legal color code or name" + ); + } + if (is_object($literal)) { - $literal = $literal->toArray(); + $literal = $literal->toRdfPhp(); } elseif (!is_array($literal)) { $literal = array('value' => $literal); } @@ -171,11 +182,15 @@ public static function dumpLiteralValue($literal, $html = true, $color = 'black' $text .= '@' . $literal['lang']; } if (isset($literal['datatype'])) { - $datatype = EasyRdf_Namespace::shorten($literal['datatype']); - $text .= "^^$datatype"; + $short = EasyRdf_Namespace::shorten($literal['datatype']); + if ($short) { + $text .= "^^$short"; + } else { + $text .= "^^<".$literal['datatype'].">"; + } } - if ($html) { + if ($format == 'html') { return "<span style='color:$color'>". htmlentities($text, ENT_COMPAT, "UTF-8"). "</span>"; diff --git a/core/vendor/easyrdf/easyrdf/scripts/copyright_updater.php b/core/vendor/easyrdf/easyrdf/scripts/copyright_updater.php new file mode 100644 index 0000000000000000000000000000000000000000..557356b1be0d86032d9e284057b678dafb1fec0f --- /dev/null +++ b/core/vendor/easyrdf/easyrdf/scripts/copyright_updater.php @@ -0,0 +1,64 @@ +<?php + +$ROOT = realpath(__DIR__ . '/..'); + +function process_file($path) { + $year = date('Y', filemtime($path)); + $contents = file_get_contents($path); + + $copy_statements = 0; + $output = ''; + foreach (preg_split("/[\r\n]/", $contents) as $line) { + if (preg_match("/^(.+)Copyright\s+\(c\)\s+(\d+)-?(\d*) (Nicholas.+)$/", $line, $m)) { + $copy_statements++; + + if ($m[2] != $year and $m[3] != $year) { + // Change the line + $line = "$m[1]Copyright (c) $m[2]-$year $m[4]"; + } + } + + // Remove trailing whitespace + $line = rtrim($line); + $output .= "$line\n"; + } + + // Remove surplus line endings + while (substr($output, -2) == "\n\n") { + $output = substr($output, 0, -1); + } + + if ($copy_statements == 0) { + print "Warning: $path does not contain any copyright statements\n"; + } else { + file_put_contents($path, $output); + } +} + + +function process_directory($path) { + $dir = opendir($path); + + while ($file = readdir($dir)) { + if (substr($file, 0, 1) == '.') { + continue; + } + + $filepath = $path . '/' . $file; + if (is_dir($filepath)) { + process_directory($filepath); + } elseif (is_file($filepath)) { + if (substr($file, -4) == '.php') { + process_file($filepath); + } + } else { + print "Unknown type: $filepath\n"; + } + } + + closedir($dir); +} + +process_directory($ROOT . '/examples'); +process_directory($ROOT . '/lib'); +process_directory($ROOT . '/test');