├── .editorconfig ├── .gitignore ├── .php_cs ├── CONTRIBUTORS ├── LICENSE ├── Makefile ├── README.md ├── composer.json ├── resources ├── codesniffer-ruleset.xml ├── phpunit-results.xsl ├── sami-config.php └── str.replace.function.xsl ├── scripts ├── run-tests.sh ├── setup-components.sh ├── tag-subpackage-repos.sh ├── travis │ ├── README.md │ ├── install-extensions.sh │ ├── install-services.sh │ └── virtuoso-sparql-permission.sql └── update-subpackage-repos.sh └── src └── Saft ├── Addition ├── ARC2 │ ├── .coveralls.yml │ ├── .gitignore │ ├── .travis.yml │ ├── Store │ │ ├── ARC2.php │ │ └── NativeARC2Importer.php │ ├── Test │ │ ├── Store │ │ │ ├── ARC2Test.php │ │ │ └── NativeARC2ImporterTest.php │ │ ├── bootstrap-travis.php │ │ ├── bootstrap.php │ │ └── resources │ │ │ └── example-resources.n3 │ ├── composer.json │ ├── phpunit.xml │ ├── test-config-travis.yml │ └── test-config.yml ├── EasyRdf │ ├── .gitignore │ ├── Data │ │ ├── ParserEasyRdf.php │ │ ├── ParserFactoryEasyRdf.php │ │ ├── SerializerEasyRdf.php │ │ └── SerializerFactoryEasyRdf.php │ ├── Test │ │ ├── ParserEasyRdfTest.php │ │ ├── ParserFactoryEasyRdfTest.php │ │ ├── SerializerEasyRdfTest.php │ │ ├── SerializerFactoryEasyRdfTest.php │ │ └── bootstrap.php │ ├── composer.json │ └── phpunit.xml ├── HttpStore │ ├── .gitignore │ ├── README.md │ ├── Store │ │ └── Http.php │ ├── Test │ │ ├── Integration │ │ │ └── HttpTest.php │ │ ├── Unit │ │ │ └── HttpTest.php │ │ └── bootstrap.php │ ├── composer.json │ ├── phpunit.xml │ └── test-config.yml ├── Virtuoso │ ├── .coveralls.yml │ ├── .gitignore │ ├── .travis.yml │ ├── README.md │ ├── Store │ │ └── Virtuoso.php │ ├── Test │ │ ├── Integration │ │ │ └── VirtuosoTest.php │ │ └── bootstrap.php │ ├── composer.json │ ├── phpunit.xml │ ├── scripts │ │ ├── README.md │ │ ├── install-extensions.sh │ │ ├── install-virtuoso.sh │ │ └── virtuoso-sparql-permission.sql │ └── test-config.yml └── hardf │ ├── .coveralls.yml │ ├── .gitignore │ ├── .travis.yml │ ├── Data │ ├── ParserFactoryHardf.php │ └── ParserHardf.php │ ├── Test │ ├── ParserFactoryHardfTest.php │ ├── ParserHardfTest.php │ ├── bootstrap.php │ └── resources │ │ └── guessFormat-regression1.ttl │ ├── composer.json │ └── phpunit.xml ├── Data ├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── Parser.php ├── ParserFactory.php ├── RDFXMLParser.php ├── README.md ├── Serializer.php ├── SerializerFactory.php ├── Test │ ├── AbstractParserFactoryTest.php │ ├── AbstractParserTest.php │ ├── AbstractSerializerFactoryTest.php │ ├── AbstractSerializerTest.php │ ├── Integration │ │ └── RDFXMLParserTest.php │ └── bootstrap.php ├── composer.json ├── phpunit.xml └── resources │ ├── dbpedia-leipzig-part.nq │ ├── dbpedia-leipzig-part.nt │ ├── dbpedia-leipzig-part.rdf │ └── example.ttl ├── Rdf ├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── AbstractBlankNode.php ├── AbstractLiteral.php ├── AbstractNamedNode.php ├── AbstractStatement.php ├── AnyPatternImpl.php ├── ArrayStatementIteratorImpl.php ├── BlankNode.php ├── BlankNodeImpl.php ├── CommonNamespaces.php ├── Literal.php ├── LiteralImpl.php ├── LiteralPatternImpl.php ├── NamedNode.php ├── NamedNodeImpl.php ├── Node.php ├── NodeFactory.php ├── NodeFactoryImpl.php ├── README.md ├── RdfHelpers.php ├── Statement.php ├── StatementFactory.php ├── StatementFactoryImpl.php ├── StatementImpl.php ├── StatementIterator.php ├── StatementIteratorFactory.php ├── StatementIteratorFactoryImpl.php ├── Test │ ├── AbstractBlankNodeTest.php │ ├── AbstractLiteralTest.php │ ├── AbstractNodeFactoryTest.php │ ├── AbstractStatementIteratorFactoryTest.php │ ├── AbstractStatementIteratorTest.php │ ├── AbstractStatementTest.php │ ├── AnyPatternImplTest.php │ ├── ArrayStatementIteratorImplTest.php │ ├── BlankNodeImplTest.php │ ├── CommonNamespacesTest.php │ ├── LiteralImplTest.php │ ├── LiteralPatternImplTest.php │ ├── NamedNodeAbstractTest.php │ ├── NamedNodeImplTest.php │ ├── NodeFactoryImplTest.php │ ├── RdfHelpersTest.php │ ├── RdfHelpersTestActiveCommonNamespaces.php │ ├── RegexMatchConstraint.php │ ├── StatementImplTest.php │ ├── StatementIteratorFactoryImplTest.php │ ├── TestCase.php │ ├── bootstrap.php │ └── resources │ │ └── guessFormat-regression1.ttl ├── composer.json └── phpunit.xml ├── Sparql ├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── Query │ ├── AbstractQuery.php │ ├── AskQueryImpl.php │ ├── ConstructQueryImpl.php │ ├── DescribeQueryImpl.php │ ├── GraphQueryImpl.php │ ├── Query.php │ ├── QueryFactory.php │ ├── QueryFactoryImpl.php │ ├── QueryUtils.php │ ├── SelectQueryImpl.php │ └── UpdateQueryImpl.php ├── README.md ├── Result │ ├── EmptyResultImpl.php │ ├── Result.php │ ├── ResultFactory.php │ ├── ResultFactoryImpl.php │ ├── SetResult.php │ ├── SetResultImpl.php │ ├── StatementSetResultImpl.php │ ├── ValueResult.php │ └── ValueResultImpl.php ├── Test │ ├── Query │ │ ├── AbstractQueryChild.php │ │ ├── AbstractQueryFactoryTest.php │ │ ├── AbstractQueryUnitTest.php │ │ ├── AskQueryImplTest.php │ │ ├── DescribeQueryImplTest.php │ │ ├── GraphQueryImplTest.php │ │ ├── QueryFactoryImplTest.php │ │ ├── SelectQueryImplTest.php │ │ └── UpdateQueryImplTest.php │ ├── Result │ │ ├── EmptyResultImplTest.php │ │ ├── SetResultAbstractTest.php │ │ ├── SetResultImplTest.php │ │ ├── StatementSetResultAbstractTest.php │ │ ├── StatementSetResultImplTest.php │ │ ├── ValueResultAbstractTest.php │ │ └── ValueResultImplTest.php │ └── bootstrap.php ├── composer.json └── phpunit.xml └── Store ├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── AbstractSparqlStore.php ├── AbstractTriplePatternStore.php ├── BasicTriplePatternStore.php ├── ChainableStore.php ├── README.md ├── Store.php ├── Test ├── AbstractSparqlStoreTest.php ├── AbstractStoreTest.php ├── AbstractTriplePatternStoreTest.php └── bootstrap.php ├── composer.json └── phpunit.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /test-config.yml 2 | /gen 3 | /tmp 4 | 5 | # composer specific 6 | composer.lock 7 | composer.phar 8 | /vendor 9 | 10 | # PHPstorm specific 11 | .idea 12 | 13 | # Eclipse specific 14 | .project 15 | .settings 16 | .buildpath 17 | /.php_cs.cache 18 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | and 8 | - Nico Seifert 9 | 10 | EOF; 11 | 12 | return PhpCsFixer\Config::create() 13 | ->setRiskyAllowed(false) 14 | ->setRules( 15 | [ 16 | '@Symfony' => true, 17 | 'array_syntax' => ['syntax' => 'short'], 18 | ] 19 | ) 20 | ->setFinder( 21 | PhpCsFixer\Finder::create() 22 | ->files() 23 | ->in(__DIR__ . '/src') 24 | ->name('*.php') 25 | ); 26 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Konrad Abicht 2 | Natanael Arndt 3 | Viktor Befort 4 | Oliver Skawronek 5 | Philipp Frischmuth 6 | Lars Eidam 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Konrad Abicht, Natanael Arndt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | PHPCS = ./vendor/bin/phpcs 12 | PHPCBF = ./vendor/bin/phpcbf 13 | SAMI = ./vendor/bin/sami.php 14 | XSLTPROC = xsltproc 15 | 16 | PHPCS-RULES = resources/codesniffer-ruleset.xml 17 | SAMI-CONFIG = resources/sami-config.php 18 | 19 | default: 20 | @echo "" 21 | @echo "Saft - CLI" 22 | @echo "" 23 | @echo "You can execute:" 24 | @echo "- make apidoc - Update API doc." 25 | @echo "- make cs - Fixes coding standard issues." 26 | @echo "- make clean - Remove temporary folders and vendor folder." 27 | @echo "- make commit - Runs some quality checks before call git commit." 28 | @echo "- make remove-subpackage-branches - Removes subpackage branches." 29 | @echo "- make remove-subpackage-remotes - Removes subpackage remotes." 30 | @echo "- make setup-subpackage-remotes - Setup subpackage remotes." 31 | @echo "- make test - Run all test suites." 32 | @echo "- make tag-subpackage-repos - Adds a new tag to all subpackage repos." 33 | @echo "- make update-subpackage-repos - Splits commits and add related to appropriate Saft components." 34 | @echo "" 35 | 36 | apidoc: 37 | $(SAMI) update -n -v --force $(SAMI-CONFIG) 38 | 39 | cs: 40 | vendor/bin/php-cs-fixer fix 41 | 42 | clean: 43 | rm -r ./gen ./tmp ./vendor 44 | 45 | commit: 46 | make codebeautifier 47 | make codesniffer 48 | git-cola 49 | 50 | # Remove all subpackages branches 51 | remove-subpackage-branches: 52 | git branch -D saft.arc2 53 | git branch -D saft.data 54 | git branch -D saft.easyrdf 55 | git branch -D saft.erfurt 56 | git branch -D saft.hardf 57 | git branch -D saft.querycache 58 | git branch -D saft.rdf 59 | git branch -D saft.redland 60 | git branch -D saft.sparql 61 | git branch -D saft.store 62 | git branch -D saft.store.http 63 | git branch -D saft.store.virtuoso 64 | git branch -D saft.test 65 | 66 | # Remove all remotes for Saft's subpackages. 67 | remove-subpackage-remotes: 68 | git remote rm saft.arc2 69 | git remote rm saft.data 70 | git remote rm saft.easyrdf 71 | git remote rm saft.erfurt 72 | git remote rm saft.hardf 73 | git remote rm saft.querycache 74 | git remote rm saft.rdf 75 | git remote rm saft.redland 76 | git remote rm saft.sparql 77 | git remote rm saft.store 78 | git remote rm saft.store.http 79 | git remote rm saft.store.virtuoso 80 | git remote rm saft.test 81 | 82 | setup: 83 | ./scripts/setup-components.sh 84 | 85 | # Setup all remotes subpackages 86 | setup-subpackage-remotes: 87 | git remote add saft.arc2 git@github.com:SaftIng/Saft.arc2 88 | git remote add saft.data git@github.com:SaftIng/Saft.data 89 | git remote add saft.easyrdf git@github.com:SaftIng/Saft.easyrdf 90 | git remote add saft.erfurt git@github.com:SaftIng/Saft.erfurt 91 | git remote add saft.hardf git@github.com:SaftIng/Saft.hardf 92 | git remote add saft.querycache git@github.com:SaftIng/Saft.querycache 93 | git remote add saft.rdf git@github.com:SaftIng/Saft.rdf 94 | git remote add saft.redland git@github.com:SaftIng/Saft.redland 95 | git remote add saft.sparql git@github.com:SaftIng/Saft.sparql 96 | git remote add saft.store git@github.com:SaftIng/Saft.store 97 | git remote add saft.store.http git@github.com:SaftIng/Saft.store.http 98 | git remote add saft.store.virtuoso git@github.com:SaftIng/Saft.store.virtuoso 99 | git remote add saft.test git@github.com:SaftIng/Saft.test 100 | 101 | tag-subpackage-repos: 102 | ./scripts/tag-subpackage-repos.sh $(TAG) 103 | 104 | test: 105 | ./scripts/run-tests.sh 106 | 107 | update-subpackage-repos: 108 | ./scripts/update-subpackage-repos.sh 109 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft", 3 | "type": "library", 4 | "description": "Saft library provides tools and an infrastructure to build Semantic Web and Linked Data applications.", 5 | "keywords": ["Saft", "Linked Data", "Semantic Web", "RDF", "Triple Store", "Parser", "Serializer", "QueryCache"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | } 21 | ], 22 | "replace": { 23 | "saft/saft-arc2": "self.version", 24 | "saft/saft-data": "self.version", 25 | "saft/saft-easyrdf": "self.version", 26 | "saft/saft-rdf": "self.version", 27 | "saft/saft-sparql": "self.version", 28 | "saft/saft-store": "self.version", 29 | "saft/saft-store-http": "self.version", 30 | "saft/saft-store-virtuoso": "self.version", 31 | "saft/saft-test": "self.version" 32 | }, 33 | "require": { 34 | "php": ">=5.6", 35 | "easyrdf/easyrdf": "0.9.*", 36 | "php-curl-class/php-curl-class": "4.*", 37 | "sabre/xml": "1.*", 38 | "semsol/arc2": "2.*", 39 | "symfony/yaml": "2.*" 40 | }, 41 | "require-dev": { 42 | "friendsofphp/php-cs-fixer": "*", 43 | "mockery/mockery": "0.9.*", 44 | "phpunit/phpunit": "4.8.*", 45 | "sami/sami": "3.2.*" 46 | }, 47 | "autoload": { 48 | "psr-4": { 49 | "Saft\\": ["src/Saft/"] 50 | } 51 | }, 52 | "prefer-stable": true 53 | } 54 | -------------------------------------------------------------------------------- /resources/codesniffer-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Saft Coding Standard uses PSR-1 and PSR-2 with some additions. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 3 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 10 31 | 32 | 33 | 10 34 | 35 | 36 | 10 37 | 38 | 39 | 40 | 45 | 46 | -------------------------------------------------------------------------------- /resources/sami-config.php: -------------------------------------------------------------------------------- 1 | files() 9 | ->name('*.php') 10 | ->in($root . DIRECTORY_SEPARATOR .'src') 11 | ; 12 | 13 | return new Sami($iterator, array( 14 | 'title' => 'Saft API Documentation', 15 | 'theme' => 'default', 16 | 'build_dir' => $root . DIRECTORY_SEPARATOR .'gen'. DIRECTORY_SEPARATOR .'apidoc', 17 | 'cache_dir' => $root . DIRECTORY_SEPARATOR .'tmp'. DIRECTORY_SEPARATOR .'samicache', 18 | 'include_parent_data' => true, 19 | 'default_opened_level' => 1, 20 | )); 21 | -------------------------------------------------------------------------------- /scripts/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | typeset -A components 6 | # core packages 7 | components[data]=src/Saft/Data 8 | components[rdf]=src/Saft/Rdf 9 | components[sparql]=src/Saft/Sparql 10 | components[store]=src/Saft/Store 11 | 12 | # additions 13 | components[arc2]=src/Saft/Addition/ARC2 14 | components[easyrdf]=src/Saft/Addition/EasyRdf 15 | components[hardf]=src/Saft/Addition/hardf 16 | # TODO components[httpstore]=src/Saft/Addition/HttpStore 17 | components[virtuoso]=src/Saft/Addition/Virtuoso 18 | 19 | for i in "${!components[@]}" 20 | do 21 | echo "" 22 | echo "############################" 23 | echo "Run test suite for ${components[$i]}" 24 | echo "############################" 25 | echo "" 26 | cd "$DIR/../${components[$i]}" && vendor/bin/phpunit 27 | 28 | # let the program sleep so that the developer can recognize the result 29 | sleep 1s 30 | done 31 | -------------------------------------------------------------------------------- /scripts/setup-components.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | typeset -A components 6 | # core packages 7 | components[data]=src/Saft/Data 8 | components[rdf]=src/Saft/Rdf 9 | components[sparql]=src/Saft/Sparql 10 | components[store]=src/Saft/Store 11 | 12 | # additions 13 | components[arc2]=src/Saft/Addition/ARC2 14 | components[easyrdf]=src/Saft/Addition/EasyRdf 15 | components[hardf]=src/Saft/Addition/hardf 16 | components[httpstore]=src/Saft/Addition/HttpStore 17 | components[virtuoso]=src/Saft/Addition/Virtuoso 18 | 19 | for i in "${!components[@]}" 20 | do 21 | echo "" 22 | echo "##################################" 23 | echo "Run composer update for ${components[$i]}" 24 | echo "##################################" 25 | echo "" 26 | cd "$DIR/../${components[$i]}" && composer update 27 | done 28 | -------------------------------------------------------------------------------- /scripts/tag-subpackage-repos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Important: You need to run "make setup-subtrees" once before to ensure 4 | 5 | newTag=$1 6 | 7 | if [ -z "$newTag" ]; then 8 | echo "Please provide a tag such as 0.1.42 as first parameter." 9 | exit 1 10 | fi 11 | 12 | typeset -A repos 13 | # core packages 14 | repos[saft.data]=src/Saft/Data 15 | repos[saft.rdf]=src/Saft/Rdf 16 | repos[saft.sparql]=src/Saft/Sparql 17 | repos[saft.store]=src/Saft/Store 18 | 19 | # additional packages 20 | repos[saft.arc2]=src/Saft/Addition/ARC2 21 | repos[saft.hardf]=src/Saft/Addition/hardf 22 | repos[saft.easyrdf]=src/Saft/Addition/EasyRdf 23 | repos[saft.store.http]=src/Saft/Addition/HttpStore 24 | repos[saft.store.virtuoso]=src/Saft/Addition/Virtuoso 25 | 26 | for i in "${!repos[@]}" 27 | do 28 | # Access to: 29 | # $i = branch name 30 | # ${repos[$i]} = folder path 31 | 32 | # avoid that tags getting used for the wrong repository 33 | git tag -l | xargs git tag -d 34 | 35 | # put subfolder related changes into its own branch 36 | git subtree split --prefix=${repos[$i]} -b $i 37 | 38 | # tag that branch with the given tag 39 | git tag -a $newTag -m "add version tag $newTag" $i 40 | 41 | # push latest state to related remote with tags 42 | git push -f $i $i:master --tags 43 | done 44 | -------------------------------------------------------------------------------- /scripts/travis/README.md: -------------------------------------------------------------------------------- 1 | - `install-services.sh` to handle the install of additional services 2 | 3 | ## SPARQL services 4 | 5 | This file and scripts are taken form the SemanticMediaWiki repo and only selected files where copied for running tests with virtuoso. 6 | It is taken as of commit 721a63d3a73400300f73e0a088196a6ed0fe5afd from https://github.com/SemanticMediaWiki/SemanticMediaWiki. 7 | The unsupported services are marked with *Endabled* "No". 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
EndabledServiceConnectorQueryEndPointUpdateEndPointDataEndpointDefaultGraphComments
NoFuseki (mem)1Fusekihttp://localhost:3030/db/queryhttp://localhost:3030/db/update''''fuseki-server --update --port=3030 --mem /db
NoFuseki (memTDB)Fusekihttp://localhost:3030/db/queryhttp://localhost:3030/db/update''http://example.org/myFusekiGraphfuseki-server --update --port=3030 --memTDB --set tdb:unionDefaultGraph=true /db
YesVirtuoso opensourceVirtuosohttp://localhost:8890/sparqlhttp://localhost:8890/sparql''http://example.org/myVirtuosoGraphsudo apt-get install virtuoso-opensource
No4store24storehttp://localhost:8088/sparql/http://localhost:8088/update/''http://example.org/myFourGraphapt-get install 4store
NoSesameCustomhttp://localhost:8080/openrdf-sesame/repositories/test-smwhttp://localhost:8080/openrdf-sesame/repositories/test-smw/statements''`test-smw` is specifed as native in-memory store
72 | 73 | 1 When running integration tests with [Jena Fuseki][fuseki] it is suggested that the `in-memory` option is used to avoid potential loss of production data during test execution. 74 | 75 | 2 Currently, Travis-CI doesn't support `4Store` (1.1.4-2) as service but the following configuration has been sucessfully tested with the available test suite. ([issue #110](https://github.com/garlik/4store/issues/110) ) 76 | 77 | [fuseki]: https://jena.apache.org/ 78 | [virtuoso]: https://github.com/openlink/virtuoso-opensource 79 | [4store]: https://github.com/garlik/4store 80 | -------------------------------------------------------------------------------- /scripts/travis/install-extensions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo $TRAVIS_PHP_VERSION 4 | 5 | # skip hhvm 6 | if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then 7 | exit 0 8 | fi 9 | 10 | # get build dependencies 11 | sudo apt-get install -y unixODBC-dev 12 | 13 | PHPVERSION=$( php -v | head -n1 | sed "s|^PHP \([0-9][0-9\.]*\).*$|\1|" | tr -d '\n' ) 14 | 15 | ls ~/.phpenv/versions/ 16 | echo "PHPVERSION: " $PHPVERSION 17 | echo "LOADED CONFIG: " `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 18 | 19 | # get php sources 20 | wget https://github.com/php/php-src/archive/php-$PHPVERSION.tar.gz 21 | ls 22 | tar -xzf php-$PHPVERSION.tar.gz 23 | 24 | # build odbc extension 25 | cd php-src-php-$PHPVERSION/ext/odbc/ 26 | phpize 27 | # use fix from https://github.com/docker-library/php/issues/103 28 | sed -ri 's@^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$@#&@g' configure 29 | ./configure --with-unixODBC=shared,/usr 30 | make 31 | make install 32 | 33 | # enable odbc 34 | echo "extension=odbc.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 35 | 36 | # build pdo_odbc 37 | cd ../pdo_odbc/ 38 | phpize 39 | ./configure --with-pdo-odbc=unixODBC,/usr 40 | make 41 | make install 42 | 43 | #enable pdo_odbc 44 | echo "extension=pdo_odbc.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 45 | php -m 46 | -------------------------------------------------------------------------------- /scripts/travis/virtuoso-sparql-permission.sql: -------------------------------------------------------------------------------- 1 | GRANT EXECUTE ON DB.DBA.SPARQL_INSERT_DICT_CONTENT TO "SPARQL"; 2 | GRANT EXECUTE ON DB.DBA.SPARQL_DELETE_DICT_CONTENT TO "SPARQL"; 3 | GRANT EXECUTE ON SPARQL_DELETE_DICT_CONTENT to "SPARQL"; 4 | GRANT EXECUTE ON SPARQL_DELETE_DICT_CONTENT to SPARQL_UPDATE; 5 | GRANT SPARQL_UPDATE to "SPARQL"; 6 | GRANT SPARQL_SPONGE to "SPARQL"; -------------------------------------------------------------------------------- /scripts/update-subpackage-repos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Important: You need to run "make setup-subtrees" once before to ensure 4 | 5 | typeset -A repos 6 | # core packages 7 | repos[saft.data]=src/Saft/Data 8 | repos[saft.rdf]=src/Saft/Rdf 9 | repos[saft.sparql]=src/Saft/Sparql 10 | repos[saft.store]=src/Saft/Store 11 | 12 | # additional packages 13 | repos[saft.arc2]=src/Saft/Addition/ARC2 14 | repos[saft.easyrdf]=src/Saft/Addition/EasyRdf 15 | repos[saft.hardf]=src/Saft/Addition/hardf 16 | repos[saft.store.http]=src/Saft/Addition/HttpStore 17 | repos[saft.store.virtuoso]=src/Saft/Addition/Virtuoso 18 | 19 | for i in "${!repos[@]}" 20 | do 21 | # Access to: 22 | # $i = branch name 23 | # ${repos[$i]} = folder path 24 | 25 | echo "" 26 | echo "Update master branch for ${repos[$i]}" 27 | 28 | # avoid that tags getting used for the wrong repository 29 | git tag -l | xargs git tag -d 30 | 31 | # put subfolder related changes into its own branch 32 | git subtree split --prefix=${repos[$i]} -b $i 33 | 34 | # push latest state to related remote with tags 35 | git push -f $i $i:master 36 | done 37 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | gen/ 3 | vendor/ 4 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | dist: trusty 13 | 14 | addons: 15 | apt: 16 | packages: 17 | - mysql-server-5.6 18 | - mysql-client-core-5.6 19 | - mysql-client-5.6 20 | 21 | php: 22 | - '5.6' 23 | - '7.0' 24 | - '7.1' 25 | - '7.2' 26 | - nightly 27 | 28 | matrix: 29 | fast_finish: true 30 | include: 31 | - php: hhvm 32 | allow_failures: 33 | - php: hhvm 34 | 35 | cache: 36 | directories: 37 | - $HOME/.composer/cache 38 | 39 | sudo: true 40 | 41 | before_install: 42 | - mysql -e 'CREATE DATABASE IF NOT EXISTS saft;' 43 | - travis_retry composer install --dev --no-interaction --ignore-platform-reqs 44 | # Install coveralls.phar 45 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 46 | - chmod +x coveralls.phar 47 | - php coveralls.phar --version 48 | 49 | script: vendor/bin/phpunit --bootstrap Test/bootstrap-travis.php --coverage-clover gen/coverage/clover.xml 50 | 51 | after_success: 52 | # Submit coverage report to Coveralls servers, see .coveralls.yml 53 | - travis_retry php coveralls.phar -v 54 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/Store/NativeARC2Importer.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\ARC2\Store; 14 | 15 | /** 16 | * This class aims to provide a direct way to read a file and import its content 17 | * into an ARC2 instance. 18 | */ 19 | class NativeARC2Importer 20 | { 21 | /** 22 | * @var \ARC2_Store 23 | */ 24 | protected $store; 25 | 26 | /** 27 | * @param \ARC2_Store $store 28 | */ 29 | public function __construct(\ARC2_Store $store) 30 | { 31 | $this->store = $store; 32 | } 33 | 34 | /** 35 | * @param string $fileName 36 | * @param string $graphUri 37 | */ 38 | public function importN3FileIntoGraph($fileName, $graphUri) 39 | { 40 | $file = new \SplFileObject($fileName); 41 | 42 | $batch = 1000; 43 | $counter = 0; 44 | $chunk = ''; 45 | $j = 0; 46 | 47 | // Loop until we reach the end of the file. 48 | while (!$file->eof()) { 49 | $chunk .= $file->fgets(); 50 | 51 | if ($counter > $batch) { 52 | $this->store->query('INSERT INTO <'.$graphUri.'> {'.$chunk.'}'); 53 | 54 | $chunk = ''; 55 | $counter = 0; 56 | ++$j; 57 | } 58 | 59 | ++$counter; 60 | } 61 | 62 | // if there is something not inserted yet 63 | if (0 < $counter) { 64 | $this->store->query('INSERT INTO <'.$graphUri.'> {'.$chunk.'}'); 65 | } 66 | 67 | // Unset the file to call __destruct(), closing the file handle. 68 | $file = null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/Test/Store/NativeARC2ImporterTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\ARC2\Test\Store; 14 | 15 | use Saft\Addition\ARC2\Store\NativeARC2Importer; 16 | use Saft\Rdf\Test\TestCase; 17 | 18 | class NativeHardfToARC2ImporterTest extends TestCase 19 | { 20 | protected $arc2Store; 21 | 22 | public function setUp() 23 | { 24 | parent::setUp(); 25 | 26 | if (defined('IN_TRAVIS')) { 27 | $this->loadTestConfiguration(__DIR__.'/../../test-config-travis.yml'); 28 | } else { 29 | $this->loadTestConfiguration(__DIR__.'/../../test-config.yml'); 30 | } 31 | 32 | $this->arc2Store = \ARC2::getStore([ 33 | 'db_host' => $this->configuration['arc2Config']['host'], 34 | 'db_name' => $this->configuration['arc2Config']['database'], 35 | 'db_user' => $this->configuration['arc2Config']['username'], 36 | 'db_pwd' => $this->configuration['arc2Config']['password'], 37 | 'store_name' => 'saft_', 38 | ]); 39 | 40 | if (!$this->arc2Store->isSetUp()) { 41 | $this->arc2Store->setUp(); 42 | } 43 | 44 | $this->fixture = new NativeARC2Importer($this->arc2Store); 45 | } 46 | 47 | /* 48 | * Tests for importN3FileIntoGraph 49 | */ 50 | 51 | public function testImportN3FileIntoGraph() 52 | { 53 | $this->arc2Store->query('DELETE FROM <'.$this->testGraph.'>'); 54 | $res = $this->arc2Store->query('SELECT * FROM <'.$this->testGraph.'> WHERE { ?s ?p ?o. } '); 55 | $this->assertEquals(0, count($res['result']['rows'])); 56 | 57 | $this->fixture->importN3FileIntoGraph( 58 | __DIR__.'/../resources/example-resources.n3', 59 | $this->testGraph->getUri() 60 | ); 61 | 62 | $res = $this->arc2Store->query('SELECT * FROM <'.$this->testGraph.'> WHERE { ?s ?p ?o. } '); 63 | $this->assertEquals(442, count($res['result']['rows'])); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/Test/bootstrap-travis.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require 'bootstrap.php'; 14 | 15 | define('IN_TRAVIS', true); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-arc2", 3 | "type": "library", 4 | "description": "Adapter to integrate ARC2 RDF store into Saft.", 5 | "keywords": ["Saft", "Triple Store", "ARC2", "RDF", "MySQL", "SPARQL"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.6", 24 | "semsol/arc2": "2.3.*", 25 | "sabre/uri": "1.*", 26 | "saft/saft-store": ">=1.0" 27 | }, 28 | "require-dev": { 29 | "phpunit/phpunit": "4.8.*", 30 | "doctrine/instantiator": "1.0.*" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Saft\\Addition\\ARC2\\": "." 35 | } 36 | }, 37 | "prefer-stable": true 38 | } 39 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/test-config-travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | # 12 | # This file contains a list with different configurations for test cases which rely on store. 13 | # 14 | # Feel free to copy it to test-config.yml and adapt. You can reuse existing configurations or you can use your own. 15 | 16 | arc2Config: &arc2Config 17 | username: "root" 18 | password: "" 19 | host: "127.0.0.1" 20 | database: "saft" 21 | table-prefix: "saft" 22 | -------------------------------------------------------------------------------- /src/Saft/Addition/ARC2/test-config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | # 12 | # This file contains a list with different configurations for test cases which rely on store. 13 | # 14 | # Feel free to copy it to test-config.yml and adapt. You can reuse existing configurations or you can use your own. 15 | 16 | arc2Config: &arc2Config 17 | username: "root" 18 | password: "Pass123" 19 | host: "sqldb" 20 | database: "saft" 21 | table-prefix: "saft" 22 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | /gen 3 | /vendor 4 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Data/ParserFactoryEasyRdf.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Data; 14 | 15 | use Saft\Data\ParserFactory; 16 | use Saft\Rdf\NodeFactory; 17 | use Saft\Rdf\RdfHelpers; 18 | use Saft\Rdf\StatementFactory; 19 | use Saft\Rdf\StatementIteratorFactory; 20 | 21 | class ParserFactoryEasyRdf implements ParserFactory 22 | { 23 | /** 24 | * @var array 25 | */ 26 | protected $serializationMap; 27 | 28 | protected $nodeFactory; 29 | 30 | protected $rdfHelpers; 31 | 32 | protected $statementFactory; 33 | 34 | protected $statementIteratorFactory; 35 | 36 | public function __construct( 37 | NodeFactory $nodeFactory, 38 | StatementFactory $statementFactory, 39 | StatementIteratorFactory $statementIteratorFactory, 40 | RdfHelpers $rdfHelpers 41 | ) { 42 | /* 43 | * Map of serializations. It maps the Saft term on according the EasyRdf format. 44 | */ 45 | $this->serializationMap = [ 46 | 'n-triples' => 'ntriples', 47 | 'rdf-json' => 'json', 48 | 'rdf-xml' => 'rdfxml', 49 | 'rdfa' => 'rdfa', 50 | 'turtle' => 'turtle', 51 | ]; 52 | 53 | $this->nodeFactory = $nodeFactory; 54 | $this->RdfHelpers = $rdfHelpers; 55 | $this->statementFactory = $statementFactory; 56 | $this->statementIteratorFactory = $statementIteratorFactory; 57 | } 58 | 59 | /** 60 | * Creates a Parser instance for a given serialization, if available. 61 | * 62 | * @param string $serialization The serialization you need a parser for. In case it is not 63 | * available, an exception will be thrown. 64 | * 65 | * @return Parser suitable parser for the requested serialization 66 | * 67 | * @throws \Exception if parser for requested serialization is not available 68 | */ 69 | public function createParserFor($serialization) 70 | { 71 | if (!in_array($serialization, $this->getSupportedSerializations())) { 72 | throw new \Exception( 73 | 'Requested serialization '.$serialization.' is not available in: '. 74 | implode(', ', $this->getSupportedSerializations()) 75 | ); 76 | } 77 | 78 | return new ParserEasyRdf( 79 | $this->nodeFactory, 80 | $this->statementFactory, 81 | $this->statementIteratorFactory, 82 | $this->RdfHelpers, 83 | $serialization 84 | ); 85 | } 86 | 87 | /** 88 | * Returns an array which contains supported serializations. 89 | * 90 | * @return array array of supported serializations which are understood by this parser 91 | */ 92 | public function getSupportedSerializations() 93 | { 94 | return array_keys($this->serializationMap); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Data/SerializerFactoryEasyRdf.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Data; 14 | 15 | use Saft\Data\SerializerFactory; 16 | 17 | class SerializerFactoryEasyRdf implements SerializerFactory 18 | { 19 | /** 20 | * Creates a Serializer instance for a given serialization, if available. 21 | * 22 | * @param string $serialization The serialization you need a serializer for. In case it is not available, 23 | * an exception will be thrown. 24 | * 25 | * @return Parser suitable serializer for the requested serialization 26 | * 27 | * @throws \Exception if serializer for requested serialization is not available 28 | */ 29 | public function createSerializerFor($serialization) 30 | { 31 | $serializer = new SerializerEasyRdf($serialization); 32 | 33 | if (in_array($serialization, $serializer->getSupportedSerializations())) { 34 | return $serializer; 35 | } else { 36 | throw new \Exception( 37 | 'No serializer for requested serialization available: '.$serialization.'. '. 38 | 'Supported serializations are: '.implode(', ', $this->getSupportedSerializations()) 39 | ); 40 | } 41 | } 42 | 43 | /** 44 | * Returns a list of all supported serialization types. 45 | * 46 | * @return array array of supported serialization types which can be used by this serializer 47 | */ 48 | public function getSupportedSerializations() 49 | { 50 | return ['n-triples', 'rdf-json', 'rdf-xml', 'rdfa', 'turtle']; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Test/ParserEasyRdfTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Test; 14 | 15 | use Saft\Addition\EasyRdf\Data\ParserFactoryEasyRdf; 16 | use Saft\Data\Test\AbstractParserTest; 17 | use Saft\Rdf\NodeFactoryImpl; 18 | use Saft\Rdf\RdfHelpers; 19 | use Saft\Rdf\StatementFactoryImpl; 20 | use Saft\Rdf\StatementIteratorFactoryImpl; 21 | 22 | class ParserEasyRdfTest extends AbstractParserTest 23 | { 24 | protected $factory; 25 | 26 | public function __construct() 27 | { 28 | $this->factory = new ParserFactoryEasyRdf( 29 | new NodeFactoryImpl(), 30 | new StatementFactoryImpl(), 31 | new StatementIteratorFactoryImpl(), 32 | new RdfHelpers() 33 | ); 34 | } 35 | 36 | /** 37 | * @return Parser 38 | */ 39 | protected function newInstance($serialization) 40 | { 41 | return $this->factory->createParserFor($serialization); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Test/ParserFactoryEasyRdfTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Test; 14 | 15 | use Saft\Addition\EasyRdf\Data\ParserFactoryEasyRdf; 16 | use Saft\Data\Test\AbstractParserFactoryTest; 17 | use Saft\Rdf\NodeFactoryImpl; 18 | use Saft\Rdf\RdfHelpers; 19 | use Saft\Rdf\StatementFactoryImpl; 20 | use Saft\Rdf\StatementIteratorFactoryImpl; 21 | 22 | class ParserFactoryEasyRdfTest extends AbstractParserFactoryTest 23 | { 24 | /** 25 | * This list represents all serializations that are supported by the Parsers behind the ParserFactory 26 | * class to test. 27 | * 28 | * @var array 29 | */ 30 | protected $availableSerializations = [ 31 | 'n-triples', 32 | 'rdf-json', 33 | 'rdf-xml', 34 | 'rdfa', 35 | 'turtle', 36 | ]; 37 | 38 | /** 39 | * @return ParserFactory 40 | */ 41 | protected function newInstance() 42 | { 43 | return new ParserFactoryEasyRdf( 44 | new NodeFactoryImpl(), 45 | new StatementFactoryImpl(), 46 | new StatementIteratorFactoryImpl(), 47 | new RdfHelpers() 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Test/SerializerEasyRdfTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Test; 14 | 15 | use Saft\Addition\EasyRdf\Data\SerializerEasyRdf; 16 | use Saft\Data\Test\AbstractSerializerTest; 17 | 18 | class SerializerEasyRdfTest extends AbstractSerializerTest 19 | { 20 | /** 21 | * @param string $serialization 22 | * 23 | * @return Serializer 24 | */ 25 | protected function newInstance($serialization) 26 | { 27 | return new SerializerEasyRdf($serialization); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Test/SerializerFactoryEasyRdfTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\EasyRdf\Data\Test; 14 | 15 | use Saft\Addition\EasyRdf\Data\SerializerFactoryEasyRdf; 16 | use Saft\Data\Test\AbstractSerializerFactoryTest; 17 | 18 | class SerializerFactoryEasyRdfTest extends AbstractSerializerFactoryTest 19 | { 20 | /** 21 | * This list represents all serializations that are supported by the Serializers behind the ParserFactory 22 | * class to test. 23 | * 24 | * @var array 25 | */ 26 | protected $availableSerializations = [ 27 | 'n-triples', 28 | 'rdf-json', 29 | 'rdf-xml', 30 | 'rdfa', 31 | 'turtle', 32 | ]; 33 | 34 | /** 35 | * @return SerializerFactory 36 | */ 37 | protected function newInstance() 38 | { 39 | return new SerializerFactoryEasyRdf(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-easyrdf", 3 | "description": "", 4 | "keywords": ["EasyRdf", "Parser", "Serializer"], 5 | "homepage": "https://safting.github.io/", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Natanael Arndt", 10 | "homepage": "http://aksw.org/NatanaelArndt", 11 | "email": "arndtn@gmail.com", 12 | "role": "Developer" 13 | }, 14 | { 15 | "name": "Konrad Abicht", 16 | "homepage": "http://www.inspirito.de", 17 | "email": "hi@inspirito.de", 18 | "role": "Developer" 19 | } 20 | ], 21 | "require": { 22 | "php": ">=5.6", 23 | "easyrdf/easyrdf": "0.9.*", 24 | "saft/saft-data": ">=1.0" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "4.8.*" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Saft\\Addition\\EasyRdf\\": "." 32 | } 33 | }, 34 | "prefer-stable": true 35 | } 36 | -------------------------------------------------------------------------------- /src/Saft/Addition/EasyRdf/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | /gen 3 | /tmp 4 | /vendor 5 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/README.md: -------------------------------------------------------------------------------- 1 | # Saft.store.http 2 | 3 | [READ-ONLY] _Saft.store.http_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__ .'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-store-http", 3 | "type": "library", 4 | "description": "HTTP/REST store implementation.", 5 | "keywords": ["Saft", "REST", "HTTP", "Store", "RDF", "Triple Store"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.6", 24 | "php-curl-class/php-curl-class": "4.*", 25 | "saft/saft-store": ">=0.9" 26 | }, 27 | "require-dev": { 28 | "mockery/mockery": "0.9.*", 29 | "phpunit/phpunit": "4.8.*", 30 | "saft/saft-test": ">=0.9" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Saft\\Addition\\HttpStore\\": "." 35 | } 36 | }, 37 | "prefer-stable": true 38 | } 39 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Addition/HttpStore/test-config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | # 12 | # This file contains a list with different configurations for test cases which rely on store. 13 | # 14 | # Feel free to copy it to test-config.yml and adapt. You can reuse existing configurations or you can use your own. 15 | 16 | httpConfig: &httpConfig 17 | authUrl: "http://virtuoso:8890/sparql-auth" 18 | queryUrl: "http://virtuoso:8890/sparql" 19 | username: "dba" 20 | password: "dba" 21 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | /gen 3 | /vendor 4 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | dist: trusty 14 | 15 | php: 16 | - '5.6' 17 | - '7.0' 18 | - '7.1' 19 | - '7.2' 20 | - nightly 21 | 22 | env: 23 | - VIRTUOSO=7.2.4.2 24 | 25 | matrix: 26 | fast_finish: true 27 | include: 28 | - php: hhvm 29 | allow_failures: 30 | - php: nightly 31 | - php: hhvm 32 | 33 | cache: 34 | directories: 35 | - $HOME/.composer/cache 36 | - virtuoso-opensource 37 | 38 | sudo: true 39 | 40 | before_install: 41 | - bash ./scripts/install-extensions.sh 42 | - bash ./scripts/install-virtuoso.sh 43 | - travis_retry composer install --dev --no-interaction 44 | # Install coveralls.phar 45 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 46 | - chmod +x coveralls.phar 47 | - php coveralls.phar --version 48 | 49 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 50 | 51 | after_success: 52 | # Submit coverage report to Coveralls servers, see .coveralls.yml 53 | - travis_retry php coveralls.phar -v 54 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/README.md: -------------------------------------------------------------------------------- 1 | # Saft.store.virtuoso 2 | 3 | [READ-ONLY] _Saft.store.virtuoso_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-store-virtuoso", 3 | "type": "library", 4 | "description": "Virtuoso store implementation.", 5 | "keywords": ["Saft", "Triple Store", "Virtuoso", "RDF"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.6", 24 | "saft/saft-store": ">=1.0" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "4.8.*" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Saft\\Addition\\Virtuoso\\": "." 32 | } 33 | }, 34 | "prefer-stable": true 35 | } 36 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ./Store 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/scripts/README.md: -------------------------------------------------------------------------------- 1 | # Virtuso/scripts 2 | 3 | * `install-extensions.sh` - Installation of required PHP extensions 4 | * `install-virtuoso.sh` - Installation of required Virtuoso version 5 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/scripts/install-extensions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # This file is part of Saft. 5 | # 6 | # (c) Konrad Abicht 7 | # (c) Natanael Arndt 8 | # 9 | # For the full copyright and license information, please view the LICENSE 10 | # file that was distributed with this source code. 11 | # 12 | 13 | echo $TRAVIS_PHP_VERSION 14 | 15 | # skip hhvm 16 | if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then 17 | exit 0 18 | fi 19 | 20 | # get build dependencies 21 | sudo apt-get install -y unixODBC-dev 22 | 23 | PHPVERSION=$( php -v | head -n1 | sed "s|^PHP \([0-9][0-9\.]*\).*$|\1|" | tr -d '\n' ) 24 | 25 | ls ~/.phpenv/versions/ 26 | echo "PHPVERSION: " $PHPVERSION 27 | echo "LOADED CONFIG: " `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 28 | 29 | # get php sources 30 | wget https://github.com/php/php-src/archive/php-$PHPVERSION.tar.gz 31 | ls 32 | tar -xzf php-$PHPVERSION.tar.gz 33 | 34 | # build odbc extension 35 | cd php-src-php-$PHPVERSION/ext/odbc/ 36 | phpize 37 | # use fix from https://github.com/docker-library/php/issues/103 38 | sed -ri 's@^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$@#&@g' configure 39 | ./configure --with-unixODBC=shared,/usr 40 | make 41 | make install 42 | 43 | # enable odbc 44 | echo "extension=odbc.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 45 | 46 | # build pdo_odbc 47 | cd ../pdo_odbc/ 48 | phpize 49 | ./configure --with-pdo-odbc=unixODBC,/usr 50 | make 51 | make install 52 | 53 | #enable pdo_odbc 54 | echo "extension=pdo_odbc.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 55 | php -m 56 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/scripts/install-virtuoso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # This file is part of Saft. 5 | # 6 | # (c) Konrad Abicht 7 | # (c) Natanael Arndt 8 | # 9 | # For the full copyright and license information, please view the LICENSE 10 | # file that was distributed with this source code. 11 | # 12 | 13 | set -ex 14 | BASE_PATH=$(pwd) 15 | E_UNREACHABLE=86 16 | 17 | # skip hhvm 18 | if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then 19 | exit 0 20 | fi 21 | 22 | # We build all Virtuoso version from scratch 23 | if [[ "$VIRTUOSO" != "" ]] 24 | then 25 | sudo apt-get update -qq 26 | 27 | # 28 | # virtuoso 7.2.4.2 29 | # 30 | if [[ "$VIRTUOSO" == "7.2.4.2" ]] 31 | then 32 | sudo apt-get install libssl-dev -q 33 | sudo apt-get install autoconf automake bison flex gawk gperf libtool -q 34 | 35 | if [[ -f virtuoso-opensource/$VIRTUOSO/binsrc/virtuoso/virtuoso-t ]] 36 | then 37 | echo "use cached virtuoso-opensource" 38 | cd virtuoso-opensource/$VIRTUOSO 39 | else 40 | wget --no-check-certificate -q https://github.com/openlink/virtuoso-opensource/archive/v$VIRTUOSO.zip -O virtuoso-opensource.zip 41 | 42 | unzip -q virtuoso-opensource.zip 43 | rm -r virtuoso-opensource/$VIRTUOSO || true 44 | mv virtuoso-opensource-$VIRTUOSO virtuoso-opensource/$VIRTUOSO 45 | 46 | cd virtuoso-opensource/$VIRTUOSO 47 | ./autogen.sh 48 | 49 | ./configure --program-transform-name="s/isql/isql-v/" --with-readline --disable-all-vads |& tee #configure.log 50 | 51 | # Only output error and warnings 52 | make > /dev/null 53 | fi 54 | 55 | sudo make install 56 | 57 | sudo /usr/local/virtuoso-opensource/bin/virtuoso-t -f -c /usr/local/virtuoso-opensource/var/lib/virtuoso/db/virtuoso.ini & 58 | 59 | sleep 15 60 | 61 | sudo /usr/local/virtuoso-opensource/bin/isql-v 1111 dba dba $BASE_PATH/scripts/virtuoso-sparql-permission.sql 62 | fi 63 | 64 | # configure datasource name for ODBC connection 65 | echo "[VOS]" | sudo tee -a /etc/odbc.ini > /dev/null 66 | echo "Driver=/usr/local/virtuoso-opensource/lib/virtodbc.so" | sudo tee -a /etc/odbc.ini > /dev/null 67 | echo "Description=Virtuoso OpenSource Edition" | sudo tee -a /etc/odbc.ini > /dev/null 68 | echo "Address=localhost:1111" | sudo tee -a /etc/odbc.ini > /dev/null 69 | fi 70 | -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/scripts/virtuoso-sparql-permission.sql: -------------------------------------------------------------------------------- 1 | GRANT EXECUTE ON DB.DBA.SPARQL_INSERT_DICT_CONTENT TO "SPARQL"; 2 | GRANT EXECUTE ON DB.DBA.SPARQL_DELETE_DICT_CONTENT TO "SPARQL"; 3 | GRANT EXECUTE ON SPARQL_DELETE_DICT_CONTENT to "SPARQL"; 4 | GRANT EXECUTE ON SPARQL_DELETE_DICT_CONTENT to SPARQL_UPDATE; 5 | GRANT SPARQL_UPDATE to "SPARQL"; 6 | GRANT SPARQL_SPONGE to "SPARQL"; -------------------------------------------------------------------------------- /src/Saft/Addition/Virtuoso/test-config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | virtuosoConfig: &virtuosoConfig 12 | dsn: "VOS" 13 | username: "dba" 14 | password: "dba" 15 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /composer.lock 3 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | php: 14 | - '5.6' 15 | - '7.0' 16 | - '7.1' 17 | - '7.2' 18 | - nightly 19 | 20 | matrix: 21 | fast_finish: true 22 | include: 23 | - php: hhvm 24 | allow_failures: 25 | - php: hhvm 26 | 27 | cache: 28 | directories: 29 | - $HOME/.composer/cache 30 | 31 | sudo: true 32 | 33 | before_install: 34 | - composer require satooshi/php-coveralls:* 35 | - travis_retry composer install --dev --no-interaction 36 | # Install coveralls.phar 37 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 38 | - chmod +x coveralls.phar 39 | - php coveralls.phar --version 40 | 41 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 42 | 43 | after_success: 44 | # Submit coverage report to Coveralls servers, see .coveralls.yml 45 | - travis_retry php coveralls.phar -v 46 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/Data/ParserFactoryHardf.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\hardf\Data; 14 | 15 | use Saft\Data\ParserFactory; 16 | use Saft\Rdf\NodeFactory; 17 | use Saft\Rdf\RdfHelpers; 18 | use Saft\Rdf\StatementFactory; 19 | use Saft\Rdf\StatementIteratorFactory; 20 | 21 | class ParserFactoryHardf implements ParserFactory 22 | { 23 | /** 24 | * @var array 25 | */ 26 | protected $serializationMap; 27 | 28 | protected $nodeFactory; 29 | 30 | protected $rdfHelpers; 31 | 32 | protected $statementFactory; 33 | 34 | protected $statementIteratorFactory; 35 | 36 | public function __construct( 37 | NodeFactory $nodeFactory, 38 | StatementFactory $statementFactory, 39 | StatementIteratorFactory $statementIteratorFactory, 40 | RdfHelpers $rdfHelpers 41 | ) { 42 | /* 43 | * Map of serializations. It maps the Saft term on according the EasyRdf format. 44 | */ 45 | $this->serializationMap = [ 46 | 'n-triples' => 'n-triples', 47 | 'n-quads' => 'n-quads', 48 | 'turtle' => 'turtle', 49 | ]; 50 | 51 | $this->nodeFactory = $nodeFactory; 52 | $this->RdfHelpers = $rdfHelpers; 53 | $this->statementFactory = $statementFactory; 54 | $this->statementIteratorFactory = $statementIteratorFactory; 55 | } 56 | 57 | /** 58 | * Creates a Parser instance for a given serialization, if available. 59 | * 60 | * @param string $serialization The serialization you need a parser for. In case it is not 61 | * available, an exception will be thrown. 62 | * 63 | * @return Parser suitable parser for the requested serialization 64 | * 65 | * @throws \Exception if parser for requested serialization is not available 66 | */ 67 | public function createParserFor($serialization) 68 | { 69 | if (!in_array($serialization, $this->getSupportedSerializations())) { 70 | throw new \Exception( 71 | 'Requested serialization '.$serialization.' is not available in: '. 72 | implode(', ', $this->getSupportedSerializations()) 73 | ); 74 | } 75 | 76 | return new ParserHardf( 77 | $this->nodeFactory, 78 | $this->statementFactory, 79 | $this->statementIteratorFactory, 80 | $this->RdfHelpers, 81 | $serialization 82 | ); 83 | } 84 | 85 | /** 86 | * Returns an array which contains supported serializations. 87 | * 88 | * @return array array of supported serializations which are understood by this parser 89 | */ 90 | public function getSupportedSerializations() 91 | { 92 | return array_keys($this->serializationMap); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/Test/ParserFactoryHardfTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Addition\hardf\Test; 14 | 15 | use Saft\Addition\hardf\Data\ParserFactoryHardf; 16 | use Saft\Data\Test\AbstractParserFactoryTest; 17 | use Saft\Rdf\NodeFactoryImpl; 18 | use Saft\Rdf\RdfHelpers; 19 | use Saft\Rdf\StatementFactoryImpl; 20 | use Saft\Rdf\StatementIteratorFactoryImpl; 21 | 22 | class ParserFactoryHardfTest extends AbstractParserFactoryTest 23 | { 24 | /** 25 | * This list represents all serializations that are supported by the Parsers behind the ParserFactory 26 | * class to test. 27 | * 28 | * @var array 29 | */ 30 | protected $availableSerializations = [ 31 | 'n-triples', 32 | 'n-quads', 33 | 'turtle', 34 | ]; 35 | 36 | /** 37 | * @return ParserFactory 38 | */ 39 | protected function newInstance() 40 | { 41 | return new ParserFactoryHardf( 42 | new NodeFactoryImpl(), 43 | new StatementFactoryImpl(), 44 | new StatementIteratorFactoryImpl(), 45 | new RdfHelpers() 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-hardf", 3 | "type": "library", 4 | "description": "Adapter to integrate hardf library into Saft.", 5 | "keywords": ["RDF", "serialization", "parsing", "Saft"], 6 | "homepage": "https://github.com/SaftIng/Saft", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Konrad Abicht", 11 | "homepage": "http://www.inspirito.de", 12 | "email": "hi@inspirito.de", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.6", 18 | "pietercolpaert/hardf": "0.1.*", 19 | "saft/saft-data": ">=1.0", 20 | "saft/saft-rdf": ">=1.0" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "4.8.*" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Saft\\Addition\\hardf\\": "." 28 | } 29 | }, 30 | "prefer-stable": true 31 | } 32 | -------------------------------------------------------------------------------- /src/Saft/Addition/hardf/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Data/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Data/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | test-config.yml 3 | /gen 4 | /tmp 5 | /vendor 6 | -------------------------------------------------------------------------------- /src/Saft/Data/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | php: 14 | - '5.6' 15 | - '7.0' 16 | - '7.1' 17 | - '7.2' 18 | - nightly 19 | 20 | matrix: 21 | fast_finish: true 22 | include: 23 | - php: hhvm 24 | allow_failures: 25 | - php: hhvm 26 | 27 | cache: 28 | directories: 29 | - $HOME/.composer/cache 30 | 31 | sudo: true 32 | 33 | before_install: 34 | - travis_retry composer install --dev --no-interaction 35 | # Install coveralls.phar 36 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 37 | - chmod +x coveralls.phar 38 | - php coveralls.phar --version 39 | 40 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 41 | 42 | after_success: 43 | # Submit coverage report to Coveralls servers, see .coveralls.yml 44 | - travis_retry php coveralls.phar -v 45 | -------------------------------------------------------------------------------- /src/Saft/Data/Parser.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data; 14 | 15 | /** 16 | * The Parser interface describes what methods a RDF parser should provide. An instance of Parser must be initialized 17 | * with a certain serialization the parser is able to parse. That means, that you have to create different instances 18 | * of Parser for each serialization you need. 19 | * 20 | * @api 21 | * 22 | * @since 0.1 23 | */ 24 | interface Parser 25 | { 26 | /** 27 | * Parses a given string and returns an iterator containing Statement instances representing the 28 | * previously read data. 29 | * 30 | * @param string $inputString data string containing RDF serialized data 31 | * @param string $baseUri The base URI of the parsed content. If this URI is null the inputStreams URL 32 | * is taken as base URI. 33 | * 34 | * @return StatementIterator statementIterator instaince containing all the Statements parsed by the 35 | * parser to far 36 | * 37 | * @throws \Exception if the base URI $baseUri is no valid URI 38 | * 39 | * @api 40 | * 41 | * @since 0.1 42 | */ 43 | public function parseStringToIterator($inputString, $baseUri = null); 44 | 45 | /** 46 | * Parses a given stream and returns an iterator containing Statement instances representing the 47 | * previously read data. The stream parses the data not as a whole but in chunks. 48 | * 49 | * @param string $inputStream filename of the stream to parse which contains RDF serialized data 50 | * @param string $baseUri The base URI of the parsed content. If this URI is null, the inputStreams URL is taken 51 | * as base URI. (optional) 52 | * 53 | * @return StatementIterator a StatementIterator containing all the Statements parsed by the parser to far 54 | * 55 | * @throws \Exception if the base URI $baseUri is no valid URI 56 | * 57 | * @api 58 | * 59 | * @since 0.1 60 | */ 61 | public function parseStreamToIterator($inputStream, $baseUri = null); 62 | 63 | /** 64 | * Returns an array of prefixes which where found during the last parsing. Might also be any other prefix list 65 | * depending on the implementation. Might even be empty. 66 | * 67 | * @return array An associative array with a prefix mapping of the prefixes parsed so far. The key 68 | * will be the prefix, while the values contains the according namespace URI. 69 | * 70 | * @api 71 | * 72 | * @since 0.1 73 | */ 74 | public function getCurrentPrefixList(); 75 | } 76 | -------------------------------------------------------------------------------- /src/Saft/Data/ParserFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data; 14 | 15 | /** 16 | * The ParserFactory interface abstract the creation of Parser instances. It helps you to create a suitable parser 17 | * for a given serialization, if available. It also provides a list of supported serializations. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface ParserFactory 24 | { 25 | /** 26 | * Creates a Parser instance for a given format, if available. 27 | * 28 | * @param string $serialization the serialization you need a parser for 29 | * 30 | * @return Parser suitable parser for the requested format 31 | * 32 | * @throws \Exception if a parser for requested serialization is not available 33 | * 34 | * @api 35 | * 36 | * @since 0.1 37 | */ 38 | public function createParserFor($serialization); 39 | 40 | /** 41 | * Returns an array which contains supported serializations. 42 | * 43 | * @return array array of supported serializations which are understood by this parser 44 | * 45 | * @api 46 | * 47 | * @since 0.1 48 | */ 49 | public function getSupportedSerializations(); 50 | } 51 | -------------------------------------------------------------------------------- /src/Saft/Data/README.md: -------------------------------------------------------------------------------- 1 | # Saft.data 2 | 3 | [READ-ONLY] _Saft.data_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Data/Serializer.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data; 14 | 15 | use Saft\Rdf\StatementIterator; 16 | 17 | /** 18 | * The Serializer interface describes what methods a RDF serializer should provide. An instance of Serialzer must 19 | * be initialized with a certain serialization. That means, that you have to create different instances of Serializer 20 | * for each serialization you need. 21 | * 22 | * @api 23 | * 24 | * @since 0.1 25 | */ 26 | interface Serializer 27 | { 28 | /** 29 | * Set the prefixes which the serializer can/should use when generating the serialization. 30 | * Please keep in mind, that some serializations don't support prefixes at all or that some 31 | * implementations might ignore them. 32 | * 33 | * @param array $prefixes An associative array with a prefix mapping of the prefixes. The key 34 | * will be the prefix, while the values contains the according namespace URI. 35 | * 36 | * @api 37 | * 38 | * @since 0.1 39 | */ 40 | public function setPrefixes(array $prefixes); 41 | 42 | /** 43 | * Transforms the statements of a StatementIterator instance into a stream, a file for instance. 44 | * 45 | * @param StatementIterator $statements the StatementIterator containing all the Statements which 46 | * should be serialized by the serializer 47 | * @param string|resource $outputStream filename or file pointer to the stream to where the serialization 48 | * should be written 49 | * 50 | * @throws \Exception if unknown format was given 51 | * 52 | * @api 53 | * 54 | * @since 0.1 55 | */ 56 | public function serializeIteratorToStream(StatementIterator $statements, $outputStream); 57 | 58 | /** 59 | * Returns a list of all supported serialization types. 60 | * 61 | * @return array array of supported serialization types which can be used by this serializer 62 | * 63 | * @api 64 | * 65 | * @since 0.1 66 | */ 67 | public function getSupportedSerializations(); 68 | } 69 | -------------------------------------------------------------------------------- /src/Saft/Data/SerializerFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data; 14 | 15 | /** 16 | * The SerializerFactory interface abstract the creation of Serializer instances. It helps you to create a suitable 17 | * serializer for a given serialization, if available. It also provides a list of supported serializations. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface SerializerFactory 24 | { 25 | /** 26 | * Creates a Serializer instance for a given serialization, if available. 27 | * 28 | * @param string $serialization The serialization you need a serializer for. In case it is not available, 29 | * an exception will be thrown. 30 | * 31 | * @return Parser suitable serializer for the requested serialization 32 | * 33 | * @throws \Exception if serializer for requested serialization is not available 34 | * 35 | * @api 36 | * 37 | * @since 0.1 38 | */ 39 | public function createSerializerFor($serialization); 40 | 41 | /** 42 | * Returns a list of all supported serialization types. 43 | * 44 | * @return array array of supported serialization types 45 | * 46 | * @api 47 | * 48 | * @since 0.1 49 | */ 50 | public function getSupportedSerializations(); 51 | } 52 | -------------------------------------------------------------------------------- /src/Saft/Data/Test/AbstractParserFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data\Test; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | 17 | /** 18 | * @codeCoverageIgnore 19 | */ 20 | abstract class AbstractParserFactoryTest extends TestCase 21 | { 22 | /** 23 | * This list represents all serializations that are supported by the Parsers behind the ParserFactory 24 | * class to test. 25 | * 26 | * @var array 27 | */ 28 | protected $availableSerializations = []; 29 | 30 | /** 31 | * @return ParserFactory 32 | */ 33 | abstract protected function newInstance(); 34 | 35 | /* 36 | * Tests for createParserFor 37 | */ 38 | 39 | // simple test to go through all availableSerializations and check for each that an object 40 | // is returned by the ParserFactory instance. 41 | public function testCreateParserFor() 42 | { 43 | if (0 == count($this->availableSerializations)) { 44 | $this->markTestSkipped('Array $availableSerializations contains no entries.'); 45 | } 46 | 47 | $this->fixture = $this->newInstance(); 48 | 49 | foreach ($this->availableSerializations as $serialization) { 50 | $this->assertTrue(is_object($this->fixture->createParserFor($serialization))); 51 | } 52 | } 53 | 54 | public function testCreateParserForRequestInvalidSerialization() 55 | { 56 | // expected exception because invalid serialization was given 57 | $this->setExpectedException('\Exception'); 58 | 59 | $this->newInstance()->createParserFor('invalid serialization'); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Saft/Data/Test/AbstractSerializerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Data\Test; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | 17 | /** 18 | * @codeCoverageIgnore 19 | */ 20 | abstract class AbstractSerializerFactoryTest extends TestCase 21 | { 22 | /** 23 | * This list represents all serializations that are supported by the Serializers behind the ParserFactory 24 | * class to test. 25 | * 26 | * @var array 27 | */ 28 | protected $availableSerializations = []; 29 | 30 | /** 31 | * @return SerializerFactory 32 | */ 33 | abstract protected function newInstance(); 34 | 35 | /* 36 | * Tests for createSerializerFor 37 | */ 38 | 39 | // simple test to go through all availableSerializations and check for each that an object 40 | // is returned by the SerializerFactory instance. 41 | public function testCreateSerializerFor() 42 | { 43 | $this->fixture = $this->newInstance(); 44 | 45 | foreach ($this->fixture->getSupportedSerializations() as $serialization) { 46 | $this->assertTrue(is_object($this->fixture->createSerializerFor($serialization))); 47 | } 48 | } 49 | 50 | public function testCreateSerializerForRequestInvalidSerialization() 51 | { 52 | // expected exception because invalid serialization was given 53 | $this->setExpectedException('\Exception'); 54 | 55 | $this->newInstance()->createSerializerFor('invalid serialization'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Saft/Data/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Data/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-data", 3 | "description": "Data interface for parsind and serializing RDF data for the Saft library.", 4 | "keywords": ["Saft", "Linked Data", "Semantic Web", "RDF", "Parser", "Serializer"], 5 | "homepage": "https://safting.github.io/", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Natanael Arndt", 10 | "homepage": "http://aksw.org/NatanaelArndt", 11 | "email": "arndtn@gmail.com", 12 | "role": "Developer" 13 | }, 14 | { 15 | "name": "Konrad Abicht", 16 | "homepage": "http://www.inspirito.de", 17 | "email": "hi@inspirito.de", 18 | "role": "Developer" 19 | } 20 | ], 21 | "require": { 22 | "php": ">=5.6", 23 | "sabre/xml": "1.*", 24 | "saft/saft-rdf": ">=1.0" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "4.8.*" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Saft\\Data\\": "." 32 | } 33 | }, 34 | "prefer-stable": true 35 | } 36 | -------------------------------------------------------------------------------- /src/Saft/Data/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Data/resources/dbpedia-leipzig-part.nq: -------------------------------------------------------------------------------- 1 | "-2.2"^^ . 2 | "Oberb\u00FCrgermeister"@en . 3 | _:bnode . 4 | _:bnode . 5 | "Leipzig (/\u02C8la\u026Aps\u026A\u0261/; German: [\u02C8la\u026Apts\u026A\u00E7]) is the largest city in the federal state of Saxony, Germany. It has a population of 544,479 inhabitants (1,001,220 residents in the larger urban zone). Leipzig is located about 150 kilometers (93 miles) south of Berlin at the confluence of the White Elster, Pleisse, and Parthe rivers at the southerly end of the North German Plain.Leipzig has been a trade city since at least the time of the Holy Roman Empire. Some ' test.'"@en . 6 | -------------------------------------------------------------------------------- /src/Saft/Data/resources/dbpedia-leipzig-part.nt: -------------------------------------------------------------------------------- 1 | "-2.2"^^ . 2 | "Oberb\u00FCrgermeister"@en . 3 | _:bnode . 4 | _:bnode . 5 | "Leipzig (/\u02C8la\u026Aps\u026A\u0261/; German: [\u02C8la\u026Apts\u026A\u00E7]) is the largest city in the federal state of Saxony, Germany. It has a population of 544,479 inhabitants (1,001,220 residents in the larger urban zone). Leipzig is located about 150 kilometers (93 miles) south of Berlin at the confluence of the White Elster, Pleisse, and Parthe rivers at the southerly end of the North German Plain.Leipzig has been a trade city since at least the time of the Holy Roman Empire. Some ' test.'"@en . 6 | -------------------------------------------------------------------------------- /src/Saft/Data/resources/dbpedia-leipzig-part.rdf: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | Leipzig 19 | Leipzig 20 | Leipzig (/ˈlaɪpsɪɡ/; German: [ˈlaɪptsɪç]) is the largest city in the federal state of Saxony, Germany. It has a population of 544,479 inhabitants (1,001,220 residents in the larger urban zone). Leipzig is located about 150 kilometers (93 miles) south of Berlin at the confluence of the White Elster, Pleisse, and Parthe rivers at the southerly end of the North German Plain.Leipzig has been a trade city since at least the time of the Holy Roman Empire. 21 | 22 | 23 | 17955 24 | right 25 | 4.3 26 | -2 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Saft/Data/resources/example.ttl: -------------------------------------------------------------------------------- 1 | @base . 2 | @prefix rdfs: . 3 | @prefix ex: . 4 | 5 | <> a ex:Foo ; 6 | rdfs:label "RDFS label" . 7 | 8 | ex:Foobar a ex:Bar ; 9 | rdfs:label "RDFS label with language tag"@en ; 10 | rdfs:comment """ 11 | Multi line comment 12 | """ ; 13 | ex:component ex:geo, 14 | ex:time . 15 | 16 | ex:dataset rdfs:label "RDFS label with datatype"^^. 17 | -------------------------------------------------------------------------------- /src/Saft/Rdf/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Rdf/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | test-config.yml 3 | /gen 4 | /tmp 5 | /vendor 6 | -------------------------------------------------------------------------------- /src/Saft/Rdf/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | php: 14 | - '5.6' 15 | - '7.0' 16 | - '7.1' 17 | - '7.2' 18 | - nightly 19 | 20 | matrix: 21 | fast_finish: true 22 | include: 23 | - php: hhvm 24 | allow_failures: 25 | - php: hhvm 26 | 27 | cache: 28 | directories: 29 | - $HOME/.composer/cache 30 | 31 | sudo: true 32 | 33 | before_install: 34 | - travis_retry composer install --dev --no-interaction 35 | # Install coveralls.phar 36 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 37 | - chmod +x coveralls.phar 38 | - php coveralls.phar --version 39 | 40 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 41 | 42 | after_success: 43 | # Submit coverage report to Coveralls servers, see .coveralls.yml 44 | - travis_retry php coveralls.phar -v 45 | -------------------------------------------------------------------------------- /src/Saft/Rdf/AbstractBlankNode.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * @api 17 | * 18 | * @since 0.1 19 | */ 20 | abstract class AbstractBlankNode implements BlankNode 21 | { 22 | /** 23 | * Check if a given instance of Node is equal to this instance. 24 | * 25 | * @param Node $toCompare node instance to check against 26 | * 27 | * @return bool true, if both instances are semantically equal, false otherwise 28 | * 29 | * @api 30 | * 31 | * @since 0.1 32 | */ 33 | public function equals(Node $toCompare) 34 | { 35 | if ($toCompare instanceof BlankNode) { 36 | return $this->getBlankId() === $toCompare->getBlankId(); 37 | } 38 | 39 | return false; 40 | } 41 | 42 | /** 43 | * Returns true, if this pattern matches the given node. This method is the same as equals for concrete nodes 44 | * and is overwritten for pattern/variable nodes. 45 | * 46 | * @param Node $toMatch Node instance to apply the pattern on 47 | * 48 | * @return bool true, if this pattern matches the node, false otherwise 49 | * 50 | * @api 51 | * 52 | * @since 0.1 53 | */ 54 | public function matches(Node $toMatch) 55 | { 56 | return $this->equals($toMatch); 57 | } 58 | 59 | /** 60 | * Checks if this instance is concrete, which means it does not contain pattern. 61 | * 62 | * @return bool true, if this instance is concrete, false otherwise 63 | * 64 | * @api 65 | * 66 | * @since 0.1 67 | */ 68 | public function isConcrete() 69 | { 70 | return true; 71 | } 72 | 73 | /** 74 | * Checks if this instance is a literal. 75 | * 76 | * @return bool true, if it is a literal, false otherwise 77 | * 78 | * @api 79 | * 80 | * @since 0.1 81 | */ 82 | public function isLiteral() 83 | { 84 | return false; 85 | } 86 | 87 | /** 88 | * Checks if this instance is a named node. 89 | * 90 | * @return bool true, if it is a named node, false otherwise 91 | * 92 | * @api 93 | * 94 | * @since 0.1 95 | */ 96 | public function isNamed() 97 | { 98 | return false; 99 | } 100 | 101 | /** 102 | * Checks if this instance is a blank node. 103 | * 104 | * @return bool true, if this instance is a blank node, false otherwise 105 | * 106 | * @api 107 | * 108 | * @since 0.1 109 | */ 110 | public function isBlank() 111 | { 112 | return true; 113 | } 114 | 115 | /** 116 | * Checks if this instance is a pattern. It can either be a pattern or concrete. 117 | * 118 | * @return bool true, if this instance is a pattern, false otherwise 119 | * 120 | * @api 121 | * 122 | * @since 0.1 123 | */ 124 | public function isPattern() 125 | { 126 | return false; 127 | } 128 | 129 | /** 130 | * Transform this Node instance to a n-quads string, if possible. 131 | * 132 | * @return string N-quads string representation of this instance 133 | * 134 | * @api 135 | * 136 | * @since 0.1 137 | */ 138 | public function toNQuads() 139 | { 140 | return '_:'.$this->getBlankId(); 141 | } 142 | 143 | /** 144 | * This method is ment for getting some kind of human readable string 145 | * representation of the current node. 146 | * 147 | * @return string a human readable string representation of the node 148 | * 149 | * @api 150 | * 151 | * @since 0.1 152 | */ 153 | public function __toString() 154 | { 155 | return $this->toNQuads(); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/Saft/Rdf/AbstractNamedNode.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * @api 17 | * 18 | * @since 0.1 19 | */ 20 | abstract class AbstractNamedNode implements NamedNode 21 | { 22 | /** 23 | * This method is ment for getting some kind of human readable string 24 | * representation of the current node. It returns the URI of this instance. 25 | * 26 | * @return string the stored URI 27 | * 28 | * @api 29 | * 30 | * @since 0.1 31 | */ 32 | public function __toString() 33 | { 34 | return $this->getUri(); 35 | } 36 | 37 | /** 38 | * Check if a given instance of Node is equal to this instance. 39 | * 40 | * @param Node $toCompare node instance to check against 41 | * 42 | * @return bool true, if both instances are semantically equal, false otherwise 43 | * 44 | * @api 45 | * 46 | * @since 0.1 47 | */ 48 | public function equals(Node $toCompare) 49 | { 50 | // It only compares URIs, everything else will be quit with false. 51 | if ($toCompare->isNamed()) { 52 | return $this->getUri() == $toCompare->getUri(); 53 | } 54 | 55 | return false; 56 | } 57 | 58 | /** 59 | * Returns true, if this pattern matches the given node. This method is the same as equals for concrete nodes 60 | * and is overwritten for pattern/variable nodes. 61 | * 62 | * @param Node $toMatch Node instance to apply the pattern on 63 | * 64 | * @return bool true, if this pattern matches the node, false otherwise 65 | * 66 | * @api 67 | * 68 | * @since 0.1 69 | */ 70 | public function matches(Node $toMatch) 71 | { 72 | return $this->equals($toMatch); 73 | } 74 | 75 | /** 76 | * Checks if this instance is concrete, which means it does not contain pattern. 77 | * 78 | * @return bool true, if this instance is concrete, false otherwise 79 | * 80 | * @api 81 | * 82 | * @since 0.1 83 | */ 84 | public function isConcrete() 85 | { 86 | return true; 87 | } 88 | 89 | /** 90 | * Checks if this instance is a literal. 91 | * 92 | * @return bool true, if it is a literal, false otherwise 93 | * 94 | * @api 95 | * 96 | * @since 0.1 97 | */ 98 | public function isLiteral() 99 | { 100 | return false; 101 | } 102 | 103 | /** 104 | * Checks if this instance is a named node. 105 | * 106 | * @return bool true, if it is a named node, false otherwise 107 | * 108 | * @api 109 | * 110 | * @since 0.1 111 | */ 112 | public function isNamed() 113 | { 114 | return true; 115 | } 116 | 117 | /** 118 | * Checks if this instance is a blank node. 119 | * 120 | * @return bool true, if this instance is a blank node, false otherwise 121 | * 122 | * @api 123 | * 124 | * @since 0.1 125 | */ 126 | public function isBlank() 127 | { 128 | return false; 129 | } 130 | 131 | /** 132 | * Checks if this instance is a pattern. It can either be a pattern or concrete. 133 | * 134 | * @return bool true, if this instance is a pattern, false otherwise 135 | * 136 | * @api 137 | * 138 | * @since 0.1 139 | */ 140 | public function isPattern() 141 | { 142 | return false; 143 | } 144 | 145 | /** 146 | * Transform this Node instance to a n-quads string, if possible. 147 | * 148 | * @return string N-quads string representation of this instance 149 | * 150 | * @api 151 | * 152 | * @since 0.1 153 | */ 154 | public function toNQuads() 155 | { 156 | return '<'.$this->getUri().'>'; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/Saft/Rdf/AnyPatternImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * This interface represents a pattern, in some contexts also a variable. Its purpose is to act as some kind of 17 | * a placeholder, if you dont want to specify a RDF term. 18 | * 19 | * It is useful in SPARQL queries, to be used as a variable: SELECT ?s WHERE { ?s ?p ?o } 20 | */ 21 | class AnyPatternImpl implements Node 22 | { 23 | /** 24 | * Checks if this instance is a blank node. 25 | * 26 | * @return bool true, if this instance is a blank node, false otherwise 27 | */ 28 | public function isBlank() 29 | { 30 | return false; 31 | } 32 | 33 | /** 34 | * Checks if this instance is concrete, which means it does not contain pattern. 35 | * 36 | * @return bool true, if this instance is concrete, false otherwise 37 | */ 38 | public function isConcrete() 39 | { 40 | return false; 41 | } 42 | 43 | /** 44 | * Checks if this instance is a literal. 45 | * 46 | * @return bool true, if it is a literal, false otherwise 47 | */ 48 | public function isLiteral() 49 | { 50 | return false; 51 | } 52 | 53 | /** 54 | * Checks if this instance is a named node. 55 | * 56 | * @return bool true, if it is a named node, false otherwise 57 | */ 58 | public function isNamed() 59 | { 60 | return false; 61 | } 62 | 63 | /** 64 | * Checks if this instance is a pattern. It can either be a pattern or concrete. 65 | * 66 | * @return bool true, if this instance is a pattern, false otherwise 67 | */ 68 | public function isPattern() 69 | { 70 | return true; 71 | } 72 | 73 | /** 74 | * Check if a given instance of Node is equal to this instance. 75 | * 76 | * @param Node $toCompare node instance to check against 77 | * 78 | * @return bool true, if both instances are semantically equal, false otherwise 79 | */ 80 | public function equals(Node $toCompare) 81 | { 82 | // Only compare, if given instance is an AnyPattern too 83 | return $toCompare instanceof AnyPatternImpl; 84 | } 85 | 86 | /** 87 | * Returns always true, because a pattern is like a placeholder and can be anything. 88 | * 89 | * @param Node $toMatch Node instance to apply the pattern on 90 | * 91 | * @return bool always true 92 | */ 93 | public function matches(Node $toMatch) 94 | { 95 | return true; 96 | } 97 | 98 | /** 99 | * This method is ment for getting some kind of human readable string 100 | * representation of the current node. 101 | * 102 | * @return string a human readable string representation of the node 103 | */ 104 | public function __toString() 105 | { 106 | return 'ANY'; 107 | } 108 | 109 | /** 110 | * Transform this Node instance to a n-quads string, if possible. 111 | * 112 | * @return string N-quads string representation of this instance 113 | * 114 | * @throws \Exception if no n-quads representation is available 115 | */ 116 | public function toNQuads() 117 | { 118 | throw new \Exception('The AnyPattern is not valid in NQuads'); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/Saft/Rdf/ArrayStatementIteratorImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class ArrayStatementIteratorImpl implements StatementIterator 16 | { 17 | /** 18 | * @var \ArrayIterator over the statements array 19 | */ 20 | protected $arrayIterator; 21 | 22 | /** 23 | * @param array $statements array of instances of Statement 24 | * 25 | * @throws \Exception if $statements does contain at least one non-Statement instance 26 | */ 27 | public function __construct(array $statements) 28 | { 29 | $checkedStatements = []; 30 | 31 | // check that each entry of the array is of type Statement 32 | foreach ($statements as $statement) { 33 | if (false === $statement instanceof Statement) { 34 | throw new \Exception('Parameter $statements must contain Statement instances.'); 35 | } 36 | 37 | // check for statement doublings 38 | if ($statement->isConcrete()) { 39 | $hash = $statement->toNQuads(); 40 | } else { 41 | $hash = (string) $statement->getSubject() 42 | .(string) $statement->getPredicate() 43 | .(string) $statement->getObject(); 44 | } 45 | if (isset($checkedStatements[$hash])) { 46 | // we already have that statement, go to the next one 47 | } else { 48 | $checkedStatements[$hash] = $statement; 49 | } 50 | } 51 | 52 | $this->arrayIterator = new \ArrayIterator(array_values($checkedStatements)); 53 | } 54 | 55 | /** 56 | * @return Statement 57 | */ 58 | public function current() 59 | { 60 | return $this->arrayIterator->current(); 61 | } 62 | 63 | /** 64 | * @return int position in the statements array 65 | */ 66 | public function key() 67 | { 68 | return $this->arrayIterator->key(); 69 | } 70 | 71 | /** 72 | * Any returned value is ignored. 73 | */ 74 | public function next() 75 | { 76 | $this->arrayIterator->next(); 77 | } 78 | 79 | /** 80 | * @return bool 81 | */ 82 | public function valid() 83 | { 84 | return $this->arrayIterator->valid(); 85 | } 86 | 87 | public function rewind() 88 | { 89 | $this->arrayIterator->rewind(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Saft/Rdf/BlankNode.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * This interface is common for blank nodes according to RDF 1.1 17 | * {@url http://www.w3.org/TR/rdf11-concepts/#section-blank-nodes}. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface BlankNode extends Node 24 | { 25 | /** 26 | * Returns the blank ID of this blank node. 27 | * 28 | * @return string blank ID 29 | * 30 | * @api 31 | * 32 | * @since 0.1 33 | */ 34 | public function getBlankId(); 35 | } 36 | -------------------------------------------------------------------------------- /src/Saft/Rdf/BlankNodeImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class BlankNodeImpl extends AbstractBlankNode 16 | { 17 | protected $blankId; 18 | 19 | /* 20 | * @param string $blankId 21 | */ 22 | public function __construct($blankId) 23 | { 24 | if (is_string($blankId)) { 25 | $this->blankId = $blankId; 26 | } else { 27 | throw new \Exception('Blank nodes have to have a string as $blankId.'); 28 | } 29 | } 30 | 31 | public function getBlankId() 32 | { 33 | return $this->blankId; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Literal.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * This interface is common for literals according to RDF 1.1 17 | * {@url http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal}. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface Literal extends Node 24 | { 25 | /** 26 | * Get the value of the Literal in its string representations. 27 | * 28 | * @return string the value of the Literal 29 | * 30 | * @api 31 | * 32 | * @since 0.1 33 | */ 34 | public function getValue(); 35 | 36 | /** 37 | * Get the datatype URI of the Literal (this is always set according to the 38 | * standard). 39 | * 40 | * @return Node the datatype of the Literal 41 | * 42 | * @api 43 | * 44 | * @since 0.1 45 | */ 46 | public function getDatatype(); 47 | 48 | /** 49 | * Get the language tag of this Literal or null of the Literal has no 50 | * language tag. 51 | * 52 | * @return string|null language tag or null, if none is given 53 | * 54 | * @api 55 | * 56 | * @since 0.1 57 | */ 58 | public function getLanguage(); 59 | } 60 | -------------------------------------------------------------------------------- /src/Saft/Rdf/LiteralImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class LiteralImpl extends AbstractLiteral 16 | { 17 | /** 18 | * @var string 19 | */ 20 | protected static $xsdString = 'http://www.w3.org/2001/XMLSchema#string'; 21 | 22 | /** 23 | * @var string 24 | */ 25 | protected static $rdfLangString = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString'; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $value; 31 | 32 | /** 33 | * @var Node 34 | */ 35 | protected $datatype = null; 36 | 37 | /** 38 | * @var string 39 | */ 40 | protected $lang = null; 41 | 42 | /** 43 | * @param string $value The Literal value 44 | * @param NamedNode $datatype The datatype of the Literal (respectively defaults to xsd:string or rdf:langString) 45 | * @param string $lang The language tag of the Literal (optional) 46 | */ 47 | public function __construct($value, NamedNode $datatype = null, $lang = null) 48 | { 49 | if ($value === null) { 50 | throw new \Exception('Literal value can\'t be null. Please use AnyPattern if you need a variable.'); 51 | } elseif (!is_string($value)) { 52 | throw new \Exception('The literal value has to be of type string'); 53 | } 54 | 55 | $this->value = $value; 56 | 57 | if ($lang !== null) { 58 | $this->lang = (string) $lang; 59 | } 60 | 61 | if ( 62 | $lang !== null && 63 | $lang !== '' && 64 | $datatype !== null && 65 | $datatype->isNamed() && 66 | $datatype->getUri() !== self::$rdfLangString 67 | ) { 68 | throw new \Exception('Language tagged Literals must have <'.self::$rdfLangString.'> datatype.'); 69 | } 70 | 71 | if ( 72 | ($lang === null || $lang == '') && 73 | $datatype !== null && 74 | $datatype->isNamed() && 75 | $datatype->getUri() === self::$rdfLangString 76 | ) { 77 | throw new \Exception('No or empty Language Tag for Literals with <'.self::$rdfLangString.'> datatype.'); 78 | } 79 | 80 | if ($datatype !== null) { 81 | $this->datatype = $datatype; 82 | } elseif ($lang !== null) { 83 | $this->datatype = new NamedNodeImpl(self::$rdfLangString); 84 | } else { 85 | $this->datatype = new NamedNodeImpl(self::$xsdString); 86 | } 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function getValue() 93 | { 94 | return $this->value; 95 | } 96 | 97 | /** 98 | * Get the datatype of the Literal. It can be one of the XML Schema datatypes (XSD) or anything else. If the URI is 99 | * needed it can be retrieved by calling ->getDatatype()->getUri(). 100 | * 101 | * An overview about all XML Schema datatypes: {@url http://www.w3.org/TR/xmlschema-2/#built-in-datatypes} 102 | * 103 | * @return Node the datatype of the Literal as named node 104 | */ 105 | public function getDatatype() 106 | { 107 | return $this->datatype; 108 | } 109 | 110 | /** 111 | * @return string|null 112 | */ 113 | public function getLanguage() 114 | { 115 | return $this->lang; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Saft/Rdf/LiteralPatternImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * This is a specific variable node, which is meant to match certain constructs of literal nodes by specifying 17 | * parts of the literal. 18 | * see also {@url http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#matchingRDFLiterals}. 19 | */ 20 | class LiteralPatternImpl implements Node 21 | { 22 | protected $value; 23 | protected $datatype; 24 | protected $language; 25 | 26 | /** 27 | * @param string $value The Literal value 28 | * @param Node $datatype The datatype of the Literal (respectively defaults to xsd:string or rdf:langString) 29 | * @param string $lang The language tag of the Literal (optional) 30 | */ 31 | public function __construct($value, $datatype, $language = null) 32 | { 33 | $this->value = $value; 34 | $this->datatype = $datatype; 35 | 36 | if (null !== $language) { 37 | $this->language = $language; 38 | } 39 | } 40 | 41 | /** 42 | * @return bool 43 | */ 44 | public function isBlank() 45 | { 46 | return false; 47 | } 48 | 49 | /** 50 | * @return bool 51 | */ 52 | public function isConcrete() 53 | { 54 | return false; 55 | } 56 | 57 | /** 58 | * @return bool 59 | */ 60 | public function isLiteral() 61 | { 62 | return false; 63 | } 64 | 65 | /** 66 | * @return bool 67 | */ 68 | public function isNamed() 69 | { 70 | return false; 71 | } 72 | 73 | /** 74 | * @return bool 75 | */ 76 | public function isPattern() 77 | { 78 | return true; 79 | } 80 | 81 | /** 82 | * @param Node $toCompare 83 | * 84 | * @return bool true if this instance and $toCompare match with value, datatype and language, 85 | * false otherwise 86 | */ 87 | public function equals(Node $toCompare) 88 | { 89 | // TODO to be done 90 | // Only compare, if given instance is a literalpattern too 91 | if ($toCompare instanceof LiteralPatternImpl) { 92 | return $this->getValue() === $toCompare->getValue() 93 | && $this->getDatatype() === $toCompare->getDatatype() 94 | && $this->getLanguage() === $toCompare->getLanguage(); 95 | } 96 | 97 | return false; 98 | } 99 | 100 | public function getValue() 101 | { 102 | return $this->value; 103 | } 104 | 105 | public function getDatatype() 106 | { 107 | return $this->datatype; 108 | } 109 | 110 | public function getLanguage() 111 | { 112 | return $this->language; 113 | } 114 | 115 | /** 116 | * A literal matches only another literal if its value, datatype and language are equal. 117 | * 118 | * @param Node $toMatch Node instance to apply the pattern on 119 | * 120 | * @return bool true, if this pattern matches the node, false otherwise 121 | * 122 | * @todo check if that could be deleted 123 | */ 124 | public function matches(Node $toMatch) 125 | { 126 | if ($toMatch->isConcrete()) { 127 | if ($toMatch instanceof Literal) { 128 | return $this->getValue() === $toMatch->getValue() 129 | && $this->getDatatype() === $toMatch->getDatatype() 130 | && $this->getLanguage() === $toMatch->getLanguage(); 131 | } 132 | 133 | return false; 134 | } else { 135 | throw new \Exception('The node to match has to be a concrete node'); 136 | } 137 | } 138 | 139 | /** 140 | * Returns a string description of the literal pattern representation. 141 | */ 142 | public function __toString() 143 | { 144 | // TODO to be done 145 | return 'LITERALPATTERN'; 146 | } 147 | 148 | public function toNQuads() 149 | { 150 | throw new \Exception('The LiteralPattern is not valid in NQuads'); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/Saft/Rdf/NamedNode.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * This interface is common for named nodes according to RDF 1.1 17 | * {@url http://www.w3.org/TR/rdf11-concepts/#section-IRIs}. 18 | * 19 | * @api 20 | * @api 21 | * 22 | * @since 0.1 23 | */ 24 | interface NamedNode extends Node 25 | { 26 | /** 27 | * Returns the URI of the node. 28 | * 29 | * @return string URI of the node 30 | * 31 | * @api 32 | * 33 | * @since 0.1 34 | */ 35 | public function getUri(); 36 | } 37 | -------------------------------------------------------------------------------- /src/Saft/Rdf/NamedNodeImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class NamedNodeImpl extends AbstractNamedNode 16 | { 17 | /** 18 | * @var string 19 | */ 20 | protected $uri; 21 | 22 | /** 23 | * @param string $uri the URI of the node 24 | * 25 | * @throws \Exception if parameter $value is not a valid URI 26 | */ 27 | public function __construct($uri) 28 | { 29 | if (null == $uri || false == is_string($uri) || false == $this->simpleCheckURI($uri)) { 30 | throw new \Exception('Parameter $uri is not a valid URI: '.$uri); 31 | } 32 | 33 | $this->uri = $uri; 34 | } 35 | 36 | /** 37 | * @return string URI of the node 38 | */ 39 | public function getUri() 40 | { 41 | return $this->uri; 42 | } 43 | 44 | /** 45 | * Checks the general syntax of a given URI. Protocol-specific syntaxes are not checked. Instead, only 46 | * characters disallowed an all URIs lead to a rejection of the check. Use this function, if you need a 47 | * basic check and if performance is an issuse. In case you need a more precise check, that function is 48 | * not recommended. 49 | * 50 | * @param string $string string to check if its a URI or not 51 | * 52 | * @return bool true if given string is a valid URI, false otherwise 53 | */ 54 | protected function simpleCheckURI($string) 55 | { 56 | $regEx = '/^([a-z]{2,}:[^\s]*)$/'; 57 | 58 | return 1 === preg_match($regEx, (string) $string); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Node.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * @api 17 | * 18 | * @since 0.1 19 | */ 20 | interface Node 21 | { 22 | /** 23 | * Checks if this instance is a literal. 24 | * 25 | * @return bool true, if it is a literal, false otherwise 26 | * 27 | * @api 28 | * 29 | * @since 0.1 30 | */ 31 | public function isLiteral(); 32 | 33 | /** 34 | * Checks if this instance is a named node. 35 | * 36 | * @return bool true, if it is a named node, false otherwise 37 | * 38 | * @api 39 | * 40 | * @since 0.1 41 | */ 42 | public function isNamed(); 43 | 44 | /** 45 | * Checks if this instance is a blank node. 46 | * 47 | * @return bool true, if this instance is a blank node, false otherwise 48 | * 49 | * @api 50 | * 51 | * @since 0.1 52 | */ 53 | public function isBlank(); 54 | 55 | /** 56 | * Checks if this instance is concrete, which means it does not contain pattern. 57 | * 58 | * @return bool true, if this instance is concrete, false otherwise 59 | * 60 | * @api 61 | * 62 | * @since 0.1 63 | */ 64 | public function isConcrete(); 65 | 66 | /** 67 | * Checks if this instance is a pattern. It can either be a pattern or concrete. 68 | * 69 | * @return bool true, if this instance is a pattern, false otherwise 70 | * 71 | * @api 72 | * 73 | * @since 0.1 74 | */ 75 | public function isPattern(); 76 | 77 | /** 78 | * Transform this Node instance to a n-quads string, if possible. 79 | * 80 | * @return string N-quads string representation of this instance 81 | * 82 | * @throws \Exception if no n-quads representation is available 83 | * 84 | * @api 85 | * 86 | * @since 0.1 87 | */ 88 | public function toNQuads(); 89 | 90 | /** 91 | * This method is ment for getting some kind of human readable string 92 | * representation of the current node. There is no definite syntax, but it 93 | * should contain the the URI for NamedNodes and the value for Literals. 94 | * 95 | * @return string a human readable string representation of the node 96 | * 97 | * @api 98 | * 99 | * @since 0.1 100 | */ 101 | public function __toString(); 102 | 103 | /** 104 | * Check if a given instance of Node is equal to this instance. 105 | * 106 | * @param Node $toCompare node instance to check against 107 | * 108 | * @return bool true, if both instances are semantically equal, false otherwise 109 | * 110 | * @api 111 | * 112 | * @since 0.1 113 | */ 114 | public function equals(Node $toCompare); 115 | 116 | /** 117 | * Returns true, if this pattern matches the given node. This method is the same as equals for concrete nodes 118 | * and is overwritten for pattern/variable nodes. 119 | * 120 | * @param Node $toMatch node instance to apply the pattern on 121 | * 122 | * @return bool true, if this pattern matches the node, false otherwise 123 | * 124 | * @api 125 | * 126 | * @since 0.1 127 | */ 128 | public function matches(Node $toMatch); 129 | } 130 | -------------------------------------------------------------------------------- /src/Saft/Rdf/NodeFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * The NodeFactory interface abstracts the creating of new instances of RDF nodes by hiding different implementation 17 | * details. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface NodeFactory 24 | { 25 | /** 26 | * Create a new RDF literal node instance. Details how to create such an instance may differ between different 27 | * implementations of the NodeFactory. 28 | * 29 | * @param string $value The value of the literal 30 | * @param string|Node $datatype The datatype of the literal (NamedNode, optional) 31 | * @param string $lang The language tag of the literal (optional) 32 | * 33 | * @return Literal instance of Literal 34 | * 35 | * @api 36 | * 37 | * @since 0.1 38 | */ 39 | public function createLiteral($value, $datatype = null, $lang = null); 40 | 41 | /** 42 | * Create a new RDF named node. Details how to create such an instance may differ between different 43 | * implementations of the NodeFactory. 44 | * 45 | * @param string $uri The URI of the named node 46 | * 47 | * @return NamedNode instance of NamedNode 48 | * 49 | * @api 50 | * 51 | * @since 0.1 52 | */ 53 | public function createNamedNode($uri); 54 | 55 | /** 56 | * Create a new RDF blank node. Details how to create such an instance may differ between different 57 | * implementations of the NodeFactory. 58 | * 59 | * @param string $blankId The identifier for the blank node 60 | * 61 | * @return BlankNode instance of BlankNode 62 | * 63 | * @api 64 | * 65 | * @since 0.1 66 | */ 67 | public function createBlankNode($blankId); 68 | 69 | /** 70 | * Create a new pattern node, which matches any RDF Node instance. 71 | * 72 | * @return Node instance of Node, which acts like an AnyPattern 73 | * 74 | * @api 75 | * 76 | * @since 0.1 77 | */ 78 | public function createAnyPattern(); 79 | 80 | /** 81 | * Creates an RDF Node based on a n-triples/n-quads node string. 82 | * 83 | * @param string $string N-triples/n-quads node string to use 84 | * 85 | * @return Node Node instance, which type must be one of the following: NamedNode, BlankNode, Literal 86 | * 87 | * @throws \Exception if no node could be created e.g. because of a syntax error in the node string 88 | * 89 | * @api 90 | * 91 | * @since 0.1 92 | */ 93 | public function createNodeFromNQuads($string); 94 | 95 | /** 96 | * Helper function, which is useful, if you have all the meta information about a Node and want to create 97 | * the according Node instance. 98 | * 99 | * @param string $value value of the node 100 | * @param string $type Can be uri, bnode, var or literal 101 | * @param string $datatype URI of the datatype (optional) 102 | * @param string $language Language tag (optional) 103 | * 104 | * @return Node Node instance, which type is one of: NamedNode, BlankNode, Literal, AnyPattern 105 | * 106 | * @throws \Exception if an unknown type was given 107 | * 108 | * @api 109 | * 110 | * @since 0.8 111 | */ 112 | public function createNodeInstanceFromNodeParameter($value, $type, $datatype = null, $language = null); 113 | } 114 | -------------------------------------------------------------------------------- /src/Saft/Rdf/README.md: -------------------------------------------------------------------------------- 1 | # Saft.rdf 2 | 3 | [READ-ONLY] _Saft.rdf_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * The StatementFactory interface abstracts the creating of new instances of RDF statements by hiding different 17 | * implementation details. 18 | * 19 | * @api 20 | * 21 | * @since 0.1 22 | */ 23 | interface StatementFactory 24 | { 25 | /** 26 | * Creates a new statement, either a 3-tuple or 4-tuple. 27 | * 28 | * @param Node $subject subject of the statement 29 | * @param Node $predicate predicate of the statement 30 | * @param Node $object object of the statement 31 | * @param Node $graph Graph of the statement. (optional) 32 | * 33 | * @return Statement instance of Statement 34 | * 35 | * @api 36 | * 37 | * @since 0.1 38 | */ 39 | public function createStatement(Node $subject, Node $predicate, Node $object, Node $graph = null); 40 | } 41 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementFactoryImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class StatementFactoryImpl implements StatementFactory 16 | { 17 | public function createStatement(Node $subject, Node $predicate, Node $object, Node $graph = null) 18 | { 19 | return new StatementImpl($subject, $predicate, $object, $graph); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class StatementImpl extends AbstractStatement 16 | { 17 | /** 18 | * @var Node 19 | */ 20 | protected $subject; 21 | 22 | /** 23 | * @var Node 24 | */ 25 | protected $predicate; 26 | 27 | /** 28 | * @var Node 29 | */ 30 | protected $object; 31 | 32 | /** 33 | * @var Node 34 | */ 35 | protected $graph; 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param Node $subject 41 | * @param Node $predicate 42 | * @param Node $object 43 | * @param Node $graph 44 | */ 45 | public function __construct(Node $subject, Node $predicate, Node $object, Node $graph = null) 46 | { 47 | $this->subject = $subject; 48 | $this->predicate = $predicate; 49 | $this->object = $object; 50 | 51 | if (null !== $graph) { 52 | $this->graph = $graph; 53 | } 54 | } 55 | 56 | /** 57 | * @return NamedNode 58 | */ 59 | public function getGraph() 60 | { 61 | return $this->graph; 62 | } 63 | 64 | /** 65 | * @return NamedNode|BlankNode 66 | */ 67 | public function getSubject() 68 | { 69 | return $this->subject; 70 | } 71 | 72 | /** 73 | * @return NamedNode 74 | */ 75 | public function getPredicate() 76 | { 77 | return $this->predicate; 78 | } 79 | 80 | /** 81 | * @return Node 82 | */ 83 | public function getObject() 84 | { 85 | return $this->object; 86 | } 87 | 88 | /** 89 | * @return bool 90 | */ 91 | public function isQuad() 92 | { 93 | return null !== $this->graph; 94 | } 95 | 96 | /** 97 | * @return bool 98 | */ 99 | public function isTriple() 100 | { 101 | return null === $this->graph; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementIterator.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * The StatementIterator interface extends the \Iterator interface by restricting it to Statements. 17 | * 18 | * @api 19 | * 20 | * @since 0.1 21 | */ 22 | interface StatementIterator extends \Iterator 23 | { 24 | /** 25 | * Get current Statement instance. 26 | * 27 | * @return Statement 28 | * 29 | * @api 30 | * 31 | * @since 0.1 32 | */ 33 | public function current(); 34 | 35 | /** 36 | * Get key of current Statement. 37 | * 38 | * @return scalar may not be meaningful, but must be distinct 39 | * 40 | * @api 41 | * 42 | * @since 0.1 43 | */ 44 | public function key(); 45 | 46 | /** 47 | * Go to the next Statement instance. Any returned value is ignored. 48 | * 49 | * @api 50 | * 51 | * @since 0.1 52 | */ 53 | public function next(); 54 | 55 | /** 56 | * Reset this iterator. Be aware, it may not be implemented! 57 | * 58 | * @api 59 | * 60 | * @since 0.1 61 | */ 62 | public function rewind(); 63 | 64 | /** 65 | * Checks if the current Statement is valid. 66 | * 67 | * @return bool 68 | * 69 | * @api 70 | * 71 | * @since 0.1 72 | */ 73 | public function valid(); 74 | } 75 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementIteratorFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | /** 16 | * The StatementIteratorFactory abstracts the creation of StatementIterators. 17 | * 18 | * @api 19 | * 20 | * @since 0.1 21 | */ 22 | interface StatementIteratorFactory 23 | { 24 | /** 25 | * Creates a StatementIterator instance which uses an array to manage their entities. 26 | * 27 | * @param array|\Iterator $statements list of statements, represented by an array or instance which 28 | * implements \Iterator interface 29 | * 30 | * @return StatementIterator 31 | * 32 | * @api 33 | * 34 | * @since 0.1 35 | */ 36 | public function createStatementIteratorFromArray(array $statements); 37 | } 38 | -------------------------------------------------------------------------------- /src/Saft/Rdf/StatementIteratorFactoryImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf; 14 | 15 | class StatementIteratorFactoryImpl implements StatementIteratorFactory 16 | { 17 | /** 18 | * Creates a StatementIterator instance which uses an array to manage their entities. 19 | * 20 | * @param array|\Iterator $statements list of statements, represented by an array or instance 21 | * which implements \Iterator interface 22 | * 23 | * @return StatementIterator 24 | */ 25 | public function createStatementIteratorFromArray(array $statements) 26 | { 27 | return new ArrayStatementIteratorImpl($statements); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/AbstractBlankNodeTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\LiteralImpl; 16 | 17 | abstract class BlankNodeAbstractTest extends TestCase 18 | { 19 | /** 20 | * An abstract method which returns new instances of BlankNode. 21 | */ 22 | abstract public function newInstance($blankId); 23 | 24 | /* 25 | * Tests for equals 26 | */ 27 | 28 | public function testEquals2EqualBlankNodeInstances() 29 | { 30 | $instanceA = $this->newInstance('foo'); 31 | $instanceB = $this->newInstance('foo'); 32 | 33 | $this->assertTrue($instanceA->equals($instanceB)); 34 | } 35 | 36 | public function testEquals2UnequalBlankNodeInstances() 37 | { 38 | $instanceA = $this->newInstance('foo'); 39 | $instanceB = $this->newInstance('bar'); 40 | 41 | $this->assertFalse($instanceA->equals($instanceB)); 42 | } 43 | 44 | public function testEqualsCheckBlankNodeAndLiteral() 45 | { 46 | $instanceA = $this->newInstance('foo'); 47 | $instanceB = new LiteralImpl('foo'); 48 | 49 | $this->assertFalse($instanceA->equals($instanceB)); 50 | } 51 | 52 | /* 53 | * Tests for isBlank 54 | */ 55 | 56 | public function testIsBlank() 57 | { 58 | $this->assertTrue($this->newInstance('foo')->isBlank()); 59 | } 60 | 61 | /* 62 | * Tests for isConcrete 63 | */ 64 | 65 | public function testIsConcrete() 66 | { 67 | $this->assertTrue($this->newInstance('foo')->isConcrete()); 68 | } 69 | 70 | /* 71 | * Tests for isLiteral 72 | */ 73 | 74 | public function testIsLiteral() 75 | { 76 | $this->assertFalse($this->newInstance('foo')->isLiteral()); 77 | } 78 | 79 | /* 80 | * Tests for isNamed 81 | */ 82 | 83 | public function testIsNamed() 84 | { 85 | $this->assertFalse($this->newInstance('foo')->isNamed()); 86 | } 87 | 88 | /* 89 | * Tests for isPattern 90 | */ 91 | 92 | public function testIsPattern() 93 | { 94 | $this->assertFalse($this->newInstance('foo')->isPattern()); 95 | } 96 | 97 | /* 98 | * Tests for matches 99 | */ 100 | 101 | public function testMatches() 102 | { 103 | $fixtureA = $this->newInstance('foo'); 104 | $fixtureB = $this->newInstance('foo'); 105 | $fixtureC = $this->newInstance('bar'); 106 | 107 | $this->assertTrue($fixtureA->matches($fixtureB)); 108 | $this->assertFalse($fixtureA->matches($fixtureC)); 109 | } 110 | 111 | /* 112 | * Tests for toNQuads 113 | */ 114 | 115 | public function testToNQuads() 116 | { 117 | $this->assertEquals('_:foo', $this->newInstance('foo')->toNQuads()); 118 | } 119 | 120 | /* 121 | * Tests for __toString 122 | */ 123 | 124 | public function testToString() 125 | { 126 | $this->assertEquals('_:foo', $this->newInstance('foo')->__toString()); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/AbstractStatementIteratorFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\StatementIteratorFactory; 16 | 17 | abstract class AbstractStatementIteratorFactoryTest extends TestCase 18 | { 19 | /** 20 | * @return StatementIteratorFactory 21 | */ 22 | abstract public function newInstance(); 23 | 24 | /* 25 | * Tests createStatementIteratorFromArray 26 | */ 27 | 28 | public function testCreateStatementIteratorFromArrayArrayGiven() 29 | { 30 | $this->fixture = $this->newInstance(); 31 | $parameter = []; 32 | 33 | $this->assertClassOfInstanceImplements( 34 | $this->fixture->createStatementIteratorFromArray($parameter), 35 | 'Saft\Rdf\StatementIterator' 36 | ); 37 | } 38 | 39 | public function testCreateStatementIteratorFromArrayInvalidParameterGiven() 40 | { 41 | $this->setExpectedException('\Exception'); 42 | 43 | $parameter = ['invalid parameter']; 44 | $this->newInstance()->createStatementIteratorFromArray($parameter); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/AbstractStatementIteratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\AnyPatternImpl; 16 | use Saft\Rdf\LiteralImpl; 17 | use Saft\Rdf\NamedNodeImpl; 18 | use Saft\Rdf\NodeFactoryImpl; 19 | use Saft\Rdf\StatementImpl; 20 | 21 | abstract class AbstractStatementIteratorTest extends TestCase 22 | { 23 | /** 24 | * @param array $statements 25 | * 26 | * @return StatementIterator 27 | */ 28 | abstract public function createInstanceWithArray(array $statements); 29 | 30 | /* 31 | * Tests for constructor 32 | */ 33 | 34 | public function testConstructorValidList() 35 | { 36 | // empty array must be fine 37 | $this->fixture = $this->createInstanceWithArray([]); 38 | $this->assertClassOfInstanceImplements($this->fixture, 'Saft\Rdf\StatementIterator'); 39 | $this->assertCountStatementIterator(0, $this->fixture); 40 | 41 | // array with Statement instance must be fine 42 | $this->fixture = $this->createInstanceWithArray( 43 | [new StatementImpl(new AnyPatternImpl(), new AnyPatternImpl(), new AnyPatternImpl())] 44 | ); 45 | $this->assertCountStatementIterator(1, $this->fixture); 46 | } 47 | 48 | public function testConstructorInvalidList() 49 | { 50 | // expect exception, because array contains non-Statement instance 51 | $this->setExpectedException('\Exception'); 52 | 53 | $this->fixture = $this->createInstanceWithArray([1]); 54 | } 55 | 56 | /* 57 | * Tests for count 58 | */ 59 | 60 | public function testCountAssertionSome() 61 | { 62 | $nodeFactory = new NodeFactoryImpl(); 63 | $rdfLangString = $nodeFactory->createNamedNode( 64 | 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString' 65 | ); 66 | $statements = [ 67 | new StatementImpl( 68 | new NamedNodeImpl('http://s/'), 69 | new NamedNodeImpl('http://p/'), 70 | new NamedNodeImpl('http://o/') 71 | ), 72 | new StatementImpl( 73 | new NamedNodeImpl('http://s/'), 74 | new NamedNodeImpl('http://p/'), 75 | new LiteralImpl('foobar', $rdfLangString, 'en') 76 | ), 77 | new StatementImpl( 78 | new NamedNodeImpl('http://s/'), 79 | new NamedNodeImpl('http://p/'), 80 | new LiteralImpl('42') 81 | ), ]; 82 | 83 | $iterator = $this->createInstanceWithArray($statements); 84 | 85 | $this->assertCountStatementIterator(3, $iterator); 86 | } 87 | 88 | public function testCountAssertionNone() 89 | { 90 | $statements = []; 91 | 92 | $iterator = $this->createInstanceWithArray($statements); 93 | 94 | $this->assertCountStatementIterator(0, $iterator); 95 | } 96 | 97 | /* 98 | * Tests iteration 99 | */ 100 | 101 | public function testIterationWithForeachLoop() 102 | { 103 | $nodeFactory = new NodeFactoryImpl(); 104 | $rdfLangString = $nodeFactory->createNamedNode( 105 | 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString' 106 | ); 107 | $statements = [ 108 | new StatementImpl( 109 | new NamedNodeImpl('http://s/'), 110 | new NamedNodeImpl('http://p/'), 111 | new NamedNodeImpl('http://o/') 112 | ), 113 | new StatementImpl( 114 | new NamedNodeImpl('http://s/'), 115 | new NamedNodeImpl('http://p/'), 116 | new LiteralImpl('foobar', $rdfLangString, 'en') 117 | ), 118 | new StatementImpl( 119 | new NamedNodeImpl('http://s/'), 120 | new NamedNodeImpl('http://p/'), 121 | new LiteralImpl('42') 122 | ), ]; 123 | 124 | $iterator = $this->createInstanceWithArray($statements); 125 | 126 | $this->assertTrue($iterator->valid()); 127 | 128 | $actual = []; 129 | foreach ($iterator as $key => $value) { 130 | $actual[] = $value; 131 | } 132 | 133 | $this->assertEqualsArrays($statements, $actual); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/AnyPatternImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\AnyPatternImpl; 16 | 17 | class AnyPatternImplTest extends TestCase 18 | { 19 | /** 20 | * An abstract method which returns new instances of BlankNode. 21 | */ 22 | public function newInstance() 23 | { 24 | return new AnyPatternImpl(); 25 | } 26 | 27 | final public function testIsBlank() 28 | { 29 | $fixtureA = $this->newInstance(); 30 | 31 | $this->assertFalse($fixtureA->isBlank()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/ArrayStatementIteratorImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\ArrayStatementIteratorImpl; 16 | 17 | class ArrayStatementIteratorImplTest extends AbstractStatementIteratorTest 18 | { 19 | public function createInstanceWithArray(array $statements) 20 | { 21 | return new ArrayStatementIteratorImpl($statements); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/BlankNodeImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\BlankNodeImpl; 16 | 17 | class BlankNodeImplTest extends BlankNodeAbstractTest 18 | { 19 | /** 20 | * {@inheritdoc} 21 | */ 22 | public function newInstance($id) 23 | { 24 | return new BlankNodeImpl($id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/CommonNamespacesTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\CommonNamespaces; 16 | 17 | class CommonNamespacesTest extends TestCase 18 | { 19 | public function setUp() 20 | { 21 | parent::setUp(); 22 | 23 | $this->fixture = new CommonNamespaces(); 24 | } 25 | 26 | /* 27 | * Tests for extendUri 28 | */ 29 | 30 | public function testExtendUri() 31 | { 32 | $this->fixture->add('foo', 'http://foo/'); 33 | 34 | $this->assertEquals('http://foo/bar', $this->fixture->extendUri('foo:bar')); 35 | } 36 | 37 | public function testExtendUriOverlappingPrefixes() 38 | { 39 | $this->fixture->add('foo', 'http://foo/'); 40 | $this->fixture->add('foo2', 'http://foo/baz/'); 41 | 42 | $this->assertEquals('http://foo/baz/bar', $this->fixture->extendUri('foo2:bar')); 43 | } 44 | 45 | public function testExtendUriOverlappingPrefixes2() 46 | { 47 | // it assumes 48 | // - ma => http://www.w3.org/ns/ma-ont# 49 | // - schema => http://schema.org/ 50 | // are known prefixes. 51 | 52 | $this->assertEquals('http://schema.org/foo', $this->fixture->extendUri('schema:foo')); 53 | } 54 | 55 | /* 56 | * Tests for getNamespaces 57 | */ 58 | 59 | public function testGetNamespaces() 60 | { 61 | $this->assertTrue(\is_array($this->fixture->getNamespaces())); 62 | $this->assertEquals(45, \count($this->fixture->getNamespaces())); 63 | } 64 | 65 | /* 66 | * Tests for getPrefix 67 | */ 68 | 69 | public function testGetPrefix() 70 | { 71 | $this->assertEquals('rdfs', $this->fixture->getPrefix('http://www.w3.org/2000/01/rdf-schema#')); 72 | $this->assertEquals(null, $this->fixture->getPrefix('http://not-there')); 73 | } 74 | 75 | /* 76 | * Tests for getUri 77 | */ 78 | 79 | public function testGetUri() 80 | { 81 | $this->assertEquals('http://www.w3.org/2000/01/rdf-schema#', $this->fixture->getUri('rdfs')); 82 | } 83 | 84 | /* 85 | * Tests for isShortenedUri 86 | */ 87 | 88 | public function testIsShortenedUri() 89 | { 90 | $this->assertTrue($this->fixture->isShortenedUri('rdfs:label')); 91 | 92 | $this->assertFalse($this->fixture->isShortenedUri('http://label')); 93 | } 94 | 95 | /* 96 | * Tests for shortenUri 97 | */ 98 | 99 | public function testShortenUri() 100 | { 101 | $this->fixture->add('foo', 'http://foo/'); 102 | 103 | $this->assertEquals('foo:bar', $this->fixture->shortenUri('http://foo/bar')); 104 | } 105 | 106 | // test that in case you have overlapping namespace URIs, the longest will be used 107 | // to avoid results like foo:bar/baz 108 | public function testShortenUriOverlappingPrefixes() 109 | { 110 | $this->fixture->add('foo', 'http://foo/'); 111 | $this->fixture->add('foo2', 'http://foo/baz/'); 112 | 113 | $this->assertEquals('foo2:bar', $this->fixture->shortenUri('http://foo/baz/bar')); 114 | } 115 | 116 | public function testShortenUriNothingFound() 117 | { 118 | $this->assertEquals('http://foo/bar', $this->fixture->shortenUri('http://foo/bar')); 119 | } 120 | 121 | public function testShortenUriTestCache() 122 | { 123 | // fresh 124 | $this->assertEquals([], $this->fixture->getCache()); 125 | $this->assertEquals('rdfs:label', $this->fixture->shortenUri('http://www.w3.org/2000/01/rdf-schema#label')); 126 | 127 | $this->assertEquals( 128 | [ 129 | 'getPrefix_http://www.w3.org/2000/01/rdf-schema#label' => 'rdfs:label' 130 | ], 131 | $this->fixture->getCache() 132 | ); 133 | 134 | // cache hits 135 | $this->assertEquals('rdfs:label', $this->fixture->shortenUri('http://www.w3.org/2000/01/rdf-schema#label')); 136 | $this->assertEquals('rdfs:label', $this->fixture->shortenUri('http://www.w3.org/2000/01/rdf-schema#label')); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/LiteralImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\LiteralImpl; 16 | use Saft\Rdf\Node; 17 | use Saft\Rdf\NodeFactoryImpl; 18 | 19 | class LiteralImplTest extends AbstractLiteralTest 20 | { 21 | /** 22 | * Return a new instance of LiteralImpl. 23 | */ 24 | public function newInstance($value, Node $datatype = null, $lang = null) 25 | { 26 | return new LiteralImpl($value, $datatype, $lang); 27 | } 28 | 29 | public function getNodeFactory() 30 | { 31 | return new NodeFactoryImpl(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/LiteralPatternImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\AnyPatternImpl; 16 | use Saft\Rdf\BlankNodeImpl; 17 | use Saft\Rdf\LiteralPatternImpl; 18 | use Saft\Rdf\LiteralImpl; 19 | 20 | class LiteralPatternImplTest extends TestCase 21 | { 22 | /* 23 | * Tests for equals 24 | */ 25 | 26 | public function testEquals2EqualInstances() 27 | { 28 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 29 | $instanceB = new LiteralPatternImpl('foo', $this->testGraph); 30 | 31 | $this->assertTrue($instanceA->equals($instanceB)); 32 | } 33 | 34 | public function testEquals2UnequalInstances() 35 | { 36 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 37 | $instanceB = new LiteralPatternImpl('bar', $this->testGraph); 38 | 39 | $this->assertFalse($instanceA->equals($instanceB)); 40 | } 41 | 42 | public function testEqualsCheckLiteralPatternAndLiteral() 43 | { 44 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 45 | $instanceB = new LiteralImpl('foo'); 46 | 47 | $this->assertFalse($instanceA->equals($instanceB)); 48 | } 49 | 50 | /* 51 | * Tests for isBlank 52 | */ 53 | 54 | public function testIsBlank() 55 | { 56 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 57 | $this->assertFalse($fixture->isBlank()); 58 | } 59 | 60 | /* 61 | * Tests for isConcrete 62 | */ 63 | 64 | public function testIsConcrete() 65 | { 66 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 67 | $this->assertFalse($fixture->isConcrete()); 68 | } 69 | 70 | /* 71 | * Tests for isLiteral 72 | */ 73 | 74 | public function testIsLiteral() 75 | { 76 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 77 | $this->assertFalse($fixture->isLiteral()); 78 | } 79 | 80 | /* 81 | * Tests for isNamed 82 | */ 83 | 84 | public function testIsNamed() 85 | { 86 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 87 | $this->assertFalse($fixture->isNamed()); 88 | } 89 | 90 | /* 91 | * Tests for isPattern 92 | */ 93 | 94 | public function testIsPattern() 95 | { 96 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 97 | $this->assertTrue($fixture->isPattern()); 98 | } 99 | 100 | /* 101 | * Tests for matches 102 | */ 103 | 104 | public function testMatches() 105 | { 106 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 107 | $instanceB = new LiteralImpl('foo', $this->testGraph); 108 | 109 | $this->assertTrue($instanceA->matches($instanceB)); 110 | } 111 | 112 | public function testMatchesCheckPartialMatchesAreNoMatches() 113 | { 114 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 115 | $instanceB = new LiteralImpl('foo'); 116 | 117 | $this->assertFalse($instanceA->matches($instanceB)); 118 | } 119 | 120 | public function testMatchesCheckDifferentTypes() 121 | { 122 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 123 | $instanceB = new BlankNodeImpl('foo'); 124 | 125 | $this->assertFalse($instanceA->matches($instanceB)); 126 | } 127 | 128 | public function testMatchesCheckNodeToBeConcrete() 129 | { 130 | $instanceA = new LiteralPatternImpl('foo', $this->testGraph); 131 | $instanceB = new AnyPatternImpl(); 132 | 133 | $this->setExpectedException('\Exception'); 134 | $instanceA->matches($instanceB); 135 | } 136 | 137 | /* 138 | * Tests for toNQuads 139 | */ 140 | 141 | public function testToNQuads() 142 | { 143 | $fixture = new LiteralPatternImpl('foo', $this->testGraph); 144 | 145 | // expect exception because LiteralPattern is not valid in NQuads 146 | $this->setExpectedException('\Exception'); 147 | $fixture->toNQuads(); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/NamedNodeAbstractTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | abstract class NamedNodeAbstractTest extends TestCase 16 | { 17 | /** 18 | * An abstract method which returns new instances of NamedNode. 19 | * 20 | * @todo The factory method approach could also be extended to use a factory object 21 | */ 22 | abstract public function newInstance($uri); 23 | 24 | public function testEquals() 25 | { 26 | $fixtureA = $this->newInstance('http://saft/test'); 27 | $fixtureB = $this->newInstance('http://saft/test'); 28 | $fixtureC = $this->newInstance('http://saft/testOther'); 29 | 30 | // TODO compare with literal, pattern, blanknode 31 | 32 | $this->assertTrue($fixtureA->equals($fixtureA)); 33 | $this->assertTrue($fixtureA->equals($fixtureB)); 34 | $this->assertFalse($fixtureA->equals($fixtureC)); 35 | } 36 | 37 | /* 38 | * Tests instantiation 39 | */ 40 | 41 | public function testInstanciationInvalidUri() 42 | { 43 | $this->setExpectedException('\Exception'); 44 | 45 | $this->newInstance('foo'); 46 | } 47 | 48 | public function testInstanciationNull() 49 | { 50 | // instanciation with null shouldn't be possible and has to lead to an exception 51 | $this->setExpectedException('\Exception'); 52 | 53 | $this->newInstance(null); 54 | } 55 | 56 | public function testInstanciationValidUri() 57 | { 58 | $fixture = $this->newInstance('http://saft/test'); 59 | $this->assertEquals('http://saft/test', $fixture->getUri()); 60 | } 61 | 62 | /* 63 | * Tests for isBlank 64 | */ 65 | 66 | public function testIsBlank() 67 | { 68 | $fixture = $this->newInstance('http://saft/test'); 69 | $this->assertFalse($fixture->isBlank()); 70 | } 71 | 72 | /* 73 | * Tests for isConcrete 74 | */ 75 | 76 | public function testIsConcrete() 77 | { 78 | $fixture = $this->newInstance('http://saft/test'); 79 | $this->assertTrue($fixture->isConcrete()); 80 | } 81 | 82 | /* 83 | * Tests for isLiteral 84 | */ 85 | 86 | public function testIsLiteral() 87 | { 88 | $fixture = $this->newInstance('http://saft/test'); 89 | $this->assertFalse($fixture->isLiteral()); 90 | } 91 | 92 | /* 93 | * Tests for isNamed 94 | */ 95 | 96 | public function testIsNamed() 97 | { 98 | $fixture = $this->newInstance('http://saft/test'); 99 | $this->assertTrue($fixture->isNamed()); 100 | } 101 | 102 | /* 103 | * Tests for isPattern 104 | */ 105 | 106 | public function testIsPattern() 107 | { 108 | $fixture = $this->newInstance('http://saft/test'); 109 | $this->assertFalse($fixture->isPattern()); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/NamedNodeImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\NamedNodeImpl; 16 | 17 | class NamedNodeImplTest extends NamedNodeAbstractTest 18 | { 19 | /** 20 | * Return a new instance of NamedNodeImpl. 21 | */ 22 | public function newInstance($uri) 23 | { 24 | return new NamedNodeImpl($uri); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/NodeFactoryImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\CommonNamespaces; 16 | use Saft\Rdf\NodeFactoryImpl; 17 | 18 | class NodeFactoryImplTest extends AbstractNodeFactoryTest 19 | { 20 | /** 21 | * An abstract method which returns new instances of NodeFactory. 22 | */ 23 | public function getFixture() 24 | { 25 | return new NodeFactoryImpl(new CommonNamespaces()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/RdfHelpersTestActiveCommonNamespaces.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\CommonNamespaces; 16 | use Saft\Rdf\RdfHelpers; 17 | 18 | class RdfHelpersTestActiveCommonNamespaces extends RdfHelpersTest 19 | { 20 | public function setUp() 21 | { 22 | parent::setUp(); 23 | 24 | $this->fixture = new RdfHelpers(new CommonNamespaces()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/RegexMatchConstraint.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | /** 16 | * That constraint tries to match a given regex on a given string. If the regex matches, the constraint is true, 17 | * false otherwise. 18 | */ 19 | class RegexMatchConstraint extends \PHPUnit_Framework_Constraint 20 | { 21 | protected $regex; 22 | 23 | public function __construct($regex) 24 | { 25 | parent::__construct(); 26 | 27 | $this->regex = $regex; 28 | } 29 | 30 | public function matches($toCheck) 31 | { 32 | return 1 == preg_match($this->regex, preg_replace('/\s+/', '', $toCheck)); 33 | } 34 | 35 | public function toString() 36 | { 37 | return 'matches the given Regex: '.$this->regex; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/StatementImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\AnyPatternImpl; 16 | use Saft\Rdf\BlankNodeImpl; 17 | use Saft\Rdf\LiteralImpl; 18 | use Saft\Rdf\NamedNodeImpl; 19 | use Saft\Rdf\StatementImpl; 20 | 21 | class StatementImplTest extends AbstractStatementTest 22 | { 23 | public function newAnyPatternInstance($value) 24 | { 25 | return new AnyPatternImpl($value); 26 | } 27 | 28 | public function newBlankNodeInstance($blankId) 29 | { 30 | return new BlankNodeImpl($blankId); 31 | } 32 | 33 | public function newInstance($subject, $predicate, $object, $graph = null) 34 | { 35 | return new StatementImpl($subject, $predicate, $object, $graph); 36 | } 37 | 38 | public function newLiteralInstance($value, $datatype = null, $lang = null) 39 | { 40 | return new LiteralImpl($value, $datatype, $lang); 41 | } 42 | 43 | public function newNamedNodeInstance($uri) 44 | { 45 | return new NamedNodeImpl($uri); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/StatementIteratorFactoryImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Rdf\Test; 14 | 15 | use Saft\Rdf\StatementIteratorFactoryImpl; 16 | 17 | class StatementIteratorFactoryImplTest extends AbstractStatementIteratorFactoryTest 18 | { 19 | /** 20 | * @return StatementIteratorFactory 21 | */ 22 | public function newInstance() 23 | { 24 | return new StatementIteratorFactoryImpl(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Saft/Rdf/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Rdf/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-rdf", 3 | "type": "library", 4 | "description": "RDF library from the Saft project.", 5 | "keywords": ["Saft", "Linked Data", "Semantic Web", "RDF", "Triples"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | }, 21 | { 22 | "name": "Viktor Befort", 23 | "email": "viktor.befort@stud.htwk-leipzig.de", 24 | "role": "Developer" 25 | } 26 | ], 27 | "require": { 28 | "php": ">=5.6" 29 | }, 30 | "require-dev": { 31 | "phpunit/phpunit": "4.8.*" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Saft\\Rdf\\": "." 36 | } 37 | }, 38 | "prefer-stable": true 39 | } 40 | -------------------------------------------------------------------------------- /src/Saft/Rdf/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Sparql/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Sparql/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | test-config.yml 3 | /gen 4 | /tmp 5 | /vendor 6 | -------------------------------------------------------------------------------- /src/Saft/Sparql/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | php: 14 | - '5.6' 15 | - '7.0' 16 | - '7.1' 17 | - '7.2' 18 | - nightly 19 | 20 | matrix: 21 | fast_finish: true 22 | include: 23 | - php: hhvm 24 | allow_failures: 25 | - php: hhvm 26 | 27 | cache: 28 | directories: 29 | - $HOME/.composer/cache 30 | 31 | sudo: true 32 | 33 | before_install: 34 | - travis_retry composer install --dev --no-interaction 35 | # Install coveralls.phar 36 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 37 | - chmod +x coveralls.phar 38 | - php coveralls.phar --version 39 | 40 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 41 | 42 | after_success: 43 | # Submit coverage report to Coveralls servers, see .coveralls.yml 44 | - travis_retry php coveralls.phar -v 45 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Query/ConstructQueryImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Query; 14 | 15 | use Saft\Rdf\RdfHelpers; 16 | 17 | /** 18 | * Represents an Construct query. 19 | */ 20 | class ConstructQueryImpl extends AbstractQuery 21 | { 22 | /** 23 | * Constructor. 24 | * 25 | * @param string optional $query SPARQL query string to initialize this instance 26 | * 27 | * @throws \Exception if no where part was found in query 28 | */ 29 | public function __construct($query = '', RdfHelpers $rdfHelpers) 30 | { 31 | parent::__construct($query, $rdfHelpers); 32 | 33 | if (null !== $this->query) { 34 | /* 35 | * Set where part 36 | */ 37 | $result = preg_match('/\{(.*)\}/s', $query, $match); 38 | if (false !== $result && true === isset($match[1])) { 39 | $this->queryParts['where'] = trim($match[1]); 40 | } else { 41 | throw new \Exception('No where part found in query: '.$query); 42 | } 43 | } 44 | } 45 | 46 | /** 47 | * Return parts of the query on which this instance based on. 48 | * 49 | * @return array $queryParts query parts; parts which have no elements will be unset 50 | */ 51 | public function getQueryParts() 52 | { 53 | // remove prefix information from query to be able to simply use extractGraphs on query string. 54 | $prefixlessQuery = preg_replace( 55 | '/PREFIX\s+([a-z0-9]+)\:\s*\<([a-z0-9\:\/\.\#\-]+)\>/', 56 | '', 57 | $this->getQuery() 58 | ); 59 | 60 | $this->queryParts['filter_pattern'] = $this->extractFilterPattern($this->queryParts['where']); 61 | $this->queryParts['graphs'] = $this->extractGraphs($prefixlessQuery); 62 | $this->queryParts['namespaces'] = $this->extractNamespacesFromQuery($this->queryParts['where']); 63 | $this->queryParts['prefixes'] = $this->extractPrefixesFromQuery($this->getQuery()); 64 | $this->queryParts['triple_pattern'] = $this->extractTriplePattern($this->queryParts['where']); 65 | $this->queryParts['variables'] = $this->extractVariablesFromQuery($this->getQuery()); 66 | 67 | $this->unsetEmptyValues($this->queryParts); 68 | 69 | return $this->queryParts; 70 | } 71 | 72 | /** 73 | * Represents it an ASK query? 74 | * 75 | * @return bool True 76 | */ 77 | public function isAskQuery() 78 | { 79 | return false; 80 | } 81 | 82 | /** 83 | * Represents it a CONSTRUCT query? 84 | * 85 | * @return bool False 86 | */ 87 | public function isConstructQuery() 88 | { 89 | return true; 90 | } 91 | 92 | /** 93 | * Represents it a Describe Query? 94 | * 95 | * @return bool False 96 | */ 97 | public function isDescribeQuery() 98 | { 99 | return false; 100 | } 101 | 102 | /** 103 | * Represents it a Graph Query? 104 | * 105 | * @return bool False 106 | */ 107 | public function isGraphQuery() 108 | { 109 | return false; 110 | } 111 | 112 | /** 113 | * Represents it a Select Query? 114 | * 115 | * @return bool False 116 | */ 117 | public function isSelectQuery() 118 | { 119 | return false; 120 | } 121 | 122 | /** 123 | * Represents it an Update Query? 124 | * 125 | * @return bool False 126 | */ 127 | public function isUpdateQuery() 128 | { 129 | return false; 130 | } 131 | 132 | public function __toString() 133 | { 134 | $prefixes = ''; 135 | foreach ($this->queryParts['prefixes'] as $prefix => $uri) { 136 | $prefixes .= 'PREFIX '.$prefix.': <'.$uri.'> '; 137 | } 138 | 139 | $graphUris = ''; 140 | foreach ($this->queryParts['graphs'] as $graphUri) { 141 | $graphUris .= ' FROM <'.$graphUri.'> '; 142 | } 143 | 144 | $query = $prefixes.' ASK '.$graphUris.' { '.$this->queryParts['where'].' }'; 145 | 146 | return $query; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Query/Query.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Query; 14 | 15 | interface Query 16 | { 17 | /** 18 | * @return string 19 | */ 20 | public function getQuery(); 21 | 22 | /** 23 | * @return array 24 | */ 25 | public function getQueryParts(); 26 | 27 | /** 28 | * Is instance of AskQuery? 29 | * 30 | * @return bool 31 | */ 32 | public function isAskQuery(); 33 | 34 | /** 35 | * Is instance of ConstructQuery? 36 | * 37 | * @return bool 38 | */ 39 | public function isConstructQuery(); 40 | 41 | /** 42 | * Is instance of DescribeQuery? 43 | * 44 | * @return bool 45 | */ 46 | public function isDescribeQuery(); 47 | 48 | /** 49 | * Is instance of GraphQuery? 50 | * 51 | * @return bool 52 | */ 53 | public function isGraphQuery(); 54 | 55 | /** 56 | * Is instance of SelectQuery? 57 | * 58 | * @return bool 59 | */ 60 | public function isSelectQuery(); 61 | 62 | /** 63 | * Is instance of UpdateQuery? 64 | * 65 | * @return bool 66 | */ 67 | public function isUpdateQuery(); 68 | } 69 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Query/QueryFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Query; 14 | 15 | interface QueryFactory 16 | { 17 | /** 18 | * Creates an instance of Query based on given query string. 19 | * 20 | * @param string $query SPARQL query string to use for class instantiation 21 | * 22 | * @return Query instance of Query 23 | */ 24 | public function createInstanceByQueryString($query); 25 | } 26 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Query/QueryFactoryImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Query; 14 | 15 | use Saft\Rdf\RdfHelpers; 16 | 17 | class QueryFactoryImpl implements QueryFactory 18 | { 19 | /** 20 | * @var RdfHelpers 21 | */ 22 | protected $rdfHelpers; 23 | 24 | public function __construct(RdfHelpers $rdfHelpers) 25 | { 26 | $this->rdfHelpers = $rdfHelpers; 27 | } 28 | 29 | /** 30 | * Creates an instance of Query based on given query string. 31 | * 32 | * @param string $query SPARQL query string to use for class instantiation 33 | * 34 | * @return Query instance of Query 35 | */ 36 | public function createInstanceByQueryString($query) 37 | { 38 | switch ($this->rdfHelpers->getQueryType($query)) { 39 | case 'askQuery': 40 | return new AskQueryImpl($query, $this->rdfHelpers); 41 | 42 | case 'constructQuery': 43 | return new ConstructQueryImpl($query, $this->rdfHelpers); 44 | 45 | case 'describeQuery': 46 | return new DescribeQueryImpl($query, $this->rdfHelpers); 47 | 48 | case 'graphQuery': 49 | return new GraphQueryImpl($query, $this->rdfHelpers); 50 | 51 | case 'selectQuery': 52 | return new SelectQueryImpl($query, $this->rdfHelpers); 53 | 54 | case 'updateQuery': 55 | return new UpdateQueryImpl($query, $this->rdfHelpers); 56 | 57 | default: 58 | throw new \Exception('Unknown query type: '.$query); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Query/QueryUtils.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Query; 14 | 15 | use Saft\Rdf\RdfHelpers; 16 | 17 | /** 18 | * @deprecated Use Saft/Rdf/RdfHelpers! 19 | */ 20 | class QueryUtils 21 | { 22 | protected $rdfHelpers; 23 | 24 | public function __construct() 25 | { 26 | $this->rdfHelpers = new RdfHelpers(); 27 | } 28 | 29 | /** 30 | * Get type for a given SPARQL query. 31 | * 32 | * @param string $query 33 | * 34 | * @return string Type, which is either askQuery, describeQuery, graphQuery, updateQuery or selectQuery 35 | * 36 | * @throws \Exception if unknown query type 37 | * 38 | * @deprecated Use Saft/Rdf/RdfHelpers! 39 | */ 40 | public function getQueryType($query) 41 | { 42 | return $this->rdfHelpers->getQueryType($query); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Saft/Sparql/README.md: -------------------------------------------------------------------------------- 1 | # Saft.sparql 2 | 3 | [READ-ONLY] _Saft.sparql_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/EmptyResultImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | /** 16 | * Represents an empty result, usually after an INSERT or UPDATE SPARQL query. 17 | */ 18 | class EmptyResultImpl implements Result 19 | { 20 | /** 21 | * @return array 22 | */ 23 | public function getVariables() 24 | { 25 | return []; 26 | } 27 | 28 | /** 29 | * @return bool True 30 | */ 31 | public function isEmptyResult() 32 | { 33 | return true; 34 | } 35 | 36 | /** 37 | * @return bool False 38 | */ 39 | public function isSetResult() 40 | { 41 | return false; 42 | } 43 | 44 | /** 45 | * @return bool False 46 | */ 47 | public function isStatementSetResult() 48 | { 49 | return false; 50 | } 51 | 52 | /** 53 | * @return bool False 54 | */ 55 | public function isValueResult() 56 | { 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/Result.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | /** 16 | * This class represents the result of a store operation, usually a SPARQL query. 17 | */ 18 | interface Result 19 | { 20 | /** 21 | * @return bool true, if this instance represents an empty result 22 | */ 23 | public function isEmptyResult(); 24 | 25 | /** 26 | * @return bool true, if this instance represents a set result, which is a list of associative arrays 27 | */ 28 | public function isSetResult(); 29 | 30 | /** 31 | * @return bool true, if this instance represents a statement set result, which is a list of statements 32 | */ 33 | public function isStatementSetResult(); 34 | 35 | /** 36 | * @return bool True, if this instance is a ValueResult 37 | */ 38 | public function isValueResult(); 39 | } 40 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/ResultFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | interface ResultFactory 16 | { 17 | /** 18 | * @return Result 19 | */ 20 | public function createEmptyResult(); 21 | 22 | /** 23 | * @param \Iterator|array|null $list optional 24 | * 25 | * @return SetResult 26 | */ 27 | public function createSetResult($list); 28 | 29 | /** 30 | * @param \Iterator|array|null $list optional 31 | * 32 | * @return SetResult 33 | */ 34 | public function createStatementResult($list); 35 | 36 | /** 37 | * @param mixed $scalar 38 | * 39 | * @return ValueResult 40 | */ 41 | public function createValueResult($scalar); 42 | } 43 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/ResultFactoryImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | class ResultFactoryImpl implements ResultFactory 16 | { 17 | /** 18 | * @return EmptyResult 19 | */ 20 | public function createEmptyResult() 21 | { 22 | return new EmptyResultImpl(); 23 | } 24 | 25 | /** 26 | * @param \Iterator|array|null $list optional, default is array() 27 | * 28 | * @return SetResult 29 | */ 30 | public function createSetResult($list = []) 31 | { 32 | return new SetResultImpl($list); 33 | } 34 | 35 | /** 36 | * @param \Iterator|array|null $list optional, default is array() 37 | * 38 | * @return SetResult 39 | */ 40 | public function createStatementResult($list = []) 41 | { 42 | return new StatementSetResultImpl($list); 43 | } 44 | 45 | /** 46 | * @param mixed $scalar 47 | * 48 | * @return ValueResult 49 | */ 50 | public function createValueResult($scalar) 51 | { 52 | return new ValueResultImpl($scalar); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/SetResult.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | /** 16 | * This class represents a result set. 17 | */ 18 | interface SetResult extends \Iterator, Result 19 | { 20 | /** 21 | * @return array 22 | */ 23 | public function getVariables(); 24 | 25 | /** 26 | * @param array $variables 27 | */ 28 | public function setVariables($variables); 29 | } 30 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/SetResultImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | /** 16 | * This class represents a result set. Each entry is an associative array with binding + according Node. 17 | */ 18 | class SetResultImpl extends \ArrayIterator implements SetResult 19 | { 20 | /** 21 | * Contains a list of variable names which were used in the SPARQL which let to this result. 22 | * 23 | * @var array 24 | */ 25 | protected $variables = []; 26 | 27 | /** 28 | * Constructor. 29 | * 30 | * @param object|array $array the array or object to be iterated on 31 | * @param int $flags Flags to control the behaviour of the ArrayIterator object. 32 | * See ArrayIterator::setFlags for more information: 33 | * http://php.net/manual/de/arrayiterator.setflags.php 34 | * 35 | * @throws \InvalidArgumentException if anything besides an array or an object is given 36 | */ 37 | public function __construct($array = [], $flags = 0) 38 | { 39 | parent::__construct($array, $flags); 40 | 41 | // check that each entry of $array is an array to 42 | foreach ($array as $entry) { 43 | if (false === is_array($entry)) { 44 | throw new \Exception('Parameter $array must only contain arrays.'); 45 | } 46 | } 47 | } 48 | 49 | /** 50 | * @return array 51 | */ 52 | public function getVariables() 53 | { 54 | return $this->variables; 55 | } 56 | 57 | /** 58 | * @return bool True 59 | */ 60 | public function isEmptyResult() 61 | { 62 | return false; 63 | } 64 | 65 | /** 66 | * @return bool True 67 | */ 68 | public function isSetResult() 69 | { 70 | return true; 71 | } 72 | 73 | /** 74 | * @return bool False 75 | */ 76 | public function isStatementSetResult() 77 | { 78 | return false; 79 | } 80 | 81 | /** 82 | * @return bool True 83 | */ 84 | public function isValueResult() 85 | { 86 | return false; 87 | } 88 | 89 | /** 90 | * @param array $variables 91 | */ 92 | public function setVariables($variables) 93 | { 94 | $this->variables = $variables; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/StatementSetResultImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | use Saft\Rdf\Statement; 16 | use Saft\Rdf\StatementIterator; 17 | 18 | /** 19 | * This class is a certain kind of SetResult, it only contains Statements. 20 | */ 21 | class StatementSetResultImpl extends SetResultImpl implements StatementIterator 22 | { 23 | /** 24 | * Constructor. 25 | * 26 | * @param object|array $array the array or object to be iterated on 27 | * @param int $flags Flags to control the behaviour of the ArrayIterator object. 28 | * See ArrayIterator::setFlags for more information: 29 | * http://php.net/manual/de/arrayiterator.setflags.php 30 | * 31 | * @throws \InvalidArgumentException if anything besides an array or an object is given 32 | */ 33 | public function __construct($array = [], $flags = 0) 34 | { 35 | // need this construction to be able to call the constructor of the parent class of SetResultImpl 36 | $parentClass = new \ReflectionClass($this); 37 | $parentClass = $parentClass->getParentClass()->getParentClass()->getName(); 38 | $parentClass::__construct($array, $flags); 39 | 40 | // check that each entry of $array is a Statement 41 | foreach ($array as $entry) { 42 | if (false === $entry instanceof Statement) { 43 | throw new \Exception('Parameter $array must only contain Statement instances.'); 44 | } 45 | } 46 | } 47 | 48 | /** 49 | * @return bool False 50 | */ 51 | public function isEmptyResult() 52 | { 53 | return false; 54 | } 55 | 56 | /** 57 | * @return bool False 58 | */ 59 | public function isSetResult() 60 | { 61 | return false; 62 | } 63 | 64 | /** 65 | * @return bool True 66 | */ 67 | public function isStatementSetResult() 68 | { 69 | return true; 70 | } 71 | 72 | /** 73 | * @return bool False 74 | */ 75 | public function isValueResult() 76 | { 77 | return false; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/ValueResult.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | interface ValueResult extends Result 16 | { 17 | /** 18 | * @return mixed 19 | */ 20 | public function getValue(); 21 | } 22 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Result/ValueResultImpl.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Result; 14 | 15 | class ValueResultImpl implements ValueResult 16 | { 17 | /** 18 | * @var scalar 19 | */ 20 | protected $value; 21 | 22 | /** 23 | * @param mixed $value Value of type scalar: int, string or float 24 | */ 25 | public function __construct($value) 26 | { 27 | if (!is_scalar($value)) { 28 | throw new \Exception('The fist argument of the constructor has to be a scalar.'); 29 | } 30 | 31 | $this->value = $value; 32 | } 33 | 34 | /** 35 | * @return mixed 36 | */ 37 | public function getValue() 38 | { 39 | return $this->value; 40 | } 41 | 42 | /** 43 | * @return bool False 44 | */ 45 | public function isEmptyResult() 46 | { 47 | return false; 48 | } 49 | 50 | /** 51 | * @return bool False 52 | */ 53 | public function isSetResult() 54 | { 55 | return false; 56 | } 57 | 58 | /** 59 | * @return bool False 60 | */ 61 | public function isStatementSetResult() 62 | { 63 | return false; 64 | } 65 | 66 | /** 67 | * @return bool True 68 | */ 69 | public function isValueResult() 70 | { 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Query/AbstractQueryChild.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Query; 14 | 15 | use Saft\Sparql\Query\AbstractQuery; 16 | 17 | /** 18 | * This class is a child of AbstractQuery and there for testing. We avoiding faulty abstract class 19 | * handling in PHPUnit that way. Problem was, that having an abstract class with constructor prevents you from mocking 20 | * it, because it was not possible to pass arguments to the constructor. 21 | */ 22 | class AbstractQueryChild extends AbstractQuery 23 | { 24 | /* 25 | * The following methods are only dummys to enable instantiation of the class. 26 | */ 27 | public function getQueryParts() 28 | { 29 | } 30 | 31 | public function isAskQuery() 32 | { 33 | } 34 | 35 | public function isConstructQuery() 36 | { 37 | } 38 | 39 | public function isDescribeQuery() 40 | { 41 | } 42 | 43 | public function isGraphQuery() 44 | { 45 | } 46 | 47 | public function isSelectQuery() 48 | { 49 | } 50 | 51 | public function isUpdateQuery() 52 | { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Query/QueryFactoryImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Query; 14 | 15 | use Saft\Rdf\RdfHelpers; 16 | use Saft\Sparql\Query\QueryFactoryImpl; 17 | 18 | class QueryFactoryImplTest extends AbstractQueryFactoryTest 19 | { 20 | /** 21 | * Returns subject to test. 22 | * 23 | * @return QueryFactory 24 | */ 25 | public function newInstance() 26 | { 27 | return new QueryFactoryImpl(new RdfHelpers()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/EmptyResultImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | use Saft\Sparql\Result\EmptyResultImpl; 17 | 18 | class EmptyResultImplTest extends TestCase 19 | { 20 | public function setUp() 21 | { 22 | parent::setUp(); 23 | 24 | $this->fixture = new EmptyResultImpl(); 25 | } 26 | 27 | /* 28 | * Tests for isEmptyResult 29 | */ 30 | 31 | public function testIsEmptyResult() 32 | { 33 | $this->assertTrue($this->fixture->isEmptyResult()); 34 | } 35 | 36 | /* 37 | * Tests for isSetResult 38 | */ 39 | 40 | public function testIsSetResult() 41 | { 42 | $this->assertFalse($this->fixture->isSetResult()); 43 | } 44 | 45 | /* 46 | * Tests for isStatementSetResult 47 | */ 48 | 49 | public function testIsStatementSetResult() 50 | { 51 | $this->assertFalse($this->fixture->isStatementSetResult()); 52 | } 53 | 54 | /* 55 | * Tests for isValueResult 56 | */ 57 | 58 | public function testIsValueResult() 59 | { 60 | $this->assertFalse($this->fixture->isValueResult()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/SetResultAbstractTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | use Saft\Sparql\Result\SetResult; 17 | 18 | abstract class SetResultAbstractTest extends TestCase 19 | { 20 | /** 21 | * @param \Iterator $list 22 | * 23 | * @return SetResult 24 | */ 25 | abstract public function newInstance($list); 26 | 27 | /* 28 | * Tests for isEmptyResult 29 | */ 30 | 31 | public function testIsEmptyResult() 32 | { 33 | $list = $this->getMockForAbstractClass('\Iterator'); 34 | $this->fixture = $this->newInstance($list); 35 | 36 | $this->assertFalse($this->fixture->isEmptyResult()); 37 | } 38 | 39 | /* 40 | * Tests for isSetResult 41 | */ 42 | 43 | public function testIsSetResult() 44 | { 45 | $list = $this->getMockForAbstractClass('\Iterator'); 46 | $this->fixture = $this->newInstance($list); 47 | 48 | $this->assertTrue($this->fixture->isSetResult()); 49 | } 50 | 51 | /* 52 | * Tests for isStatementSetResult 53 | */ 54 | 55 | public function testIsStatementSetResult() 56 | { 57 | $list = $this->getMockForAbstractClass('\Iterator'); 58 | $this->fixture = $this->newInstance($list); 59 | 60 | $this->assertFalse($this->fixture->isStatementSetResult()); 61 | } 62 | 63 | /* 64 | * Tests for isValueResult 65 | */ 66 | 67 | public function testIsValueResult() 68 | { 69 | $list = $this->getMockForAbstractClass('\Iterator'); 70 | $this->fixture = $this->newInstance($list); 71 | 72 | $this->assertFalse($this->fixture->isValueResult()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/SetResultImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Sparql\Result\SetResultImpl; 16 | 17 | class SetResultImplTest extends SetResultAbstractTest 18 | { 19 | /** 20 | * @param \Iterator $list 21 | * 22 | * @return SetResult 23 | */ 24 | public function newInstance($list) 25 | { 26 | return new SetResultImpl($list); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/StatementSetResultAbstractTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | 17 | abstract class StatementSetResultAbstractTest extends TestCase 18 | { 19 | /** 20 | * @return Result 21 | */ 22 | abstract public function newInstance($list); 23 | 24 | /* 25 | * Tests for isEmptyResult 26 | */ 27 | 28 | public function testIsEmptyResult() 29 | { 30 | $list = $this->getMockForAbstractClass('\Iterator'); 31 | $this->fixture = $this->newInstance($list); 32 | 33 | $this->assertFalse($this->fixture->isEmptyResult()); 34 | } 35 | 36 | /* 37 | * Tests for isSetResult 38 | */ 39 | 40 | public function testIsSetResult() 41 | { 42 | $list = $this->getMockForAbstractClass('\Iterator'); 43 | $this->fixture = $this->newInstance($list); 44 | 45 | $this->assertFalse($this->fixture->isSetResult()); 46 | } 47 | 48 | /* 49 | * Tests for isStatementSetResult 50 | */ 51 | 52 | public function testIsStatementSetResult() 53 | { 54 | $list = $this->getMockForAbstractClass('\Iterator'); 55 | $this->fixture = $this->newInstance($list); 56 | 57 | $this->assertTrue($this->fixture->isStatementSetResult()); 58 | } 59 | 60 | /* 61 | * Tests for isValueResult 62 | */ 63 | 64 | public function testIsValueResult() 65 | { 66 | $list = $this->getMockForAbstractClass('\Iterator'); 67 | $this->fixture = $this->newInstance($list); 68 | 69 | $this->assertFalse($this->fixture->isValueResult()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/StatementSetResultImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Sparql\Result\StatementSetResultImpl; 16 | 17 | class StatementSetResultImplTest extends StatementSetResultAbstractTest 18 | { 19 | /** 20 | * @return StatementResult 21 | */ 22 | public function newInstance($list) 23 | { 24 | return new StatementSetResultImpl($list); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/ValueResultAbstractTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Rdf\Test\TestCase; 16 | use Saft\Sparql\Result\ValueResultImpl; 17 | 18 | abstract class ValueResultAbstractTest extends TestCase 19 | { 20 | /** 21 | * @param $mixed $scalar 22 | * 23 | * @return Result An instance Of ValueResult 24 | */ 25 | abstract public function newInstance($scalar); 26 | 27 | public function setUp() 28 | { 29 | $this->fixture = new ValueResultImpl(0); 30 | } 31 | 32 | /** 33 | * Tests for __construct. 34 | */ 35 | public function testConstructor() 36 | { 37 | $this->fixture = new ValueResultImpl(0); 38 | $this->assertEquals(0, $this->fixture->getValue()); 39 | } 40 | 41 | public function testConstructorNonScalarParameter() 42 | { 43 | $this->setExpectedException('Exception'); 44 | 45 | $this->fixture = new ValueResultImpl([]); 46 | } 47 | 48 | /* 49 | * Tests for isEmptyResult 50 | */ 51 | 52 | public function testIsEmptyResult() 53 | { 54 | $this->assertFalse($this->fixture->isEmptyResult()); 55 | } 56 | 57 | /** 58 | * Tests for isSetResult. 59 | */ 60 | public function testIsSetResult() 61 | { 62 | $this->assertFalse($this->fixture->isSetResult()); 63 | } 64 | 65 | /** 66 | * Tests for isStatementSetResult. 67 | */ 68 | public function testisStatementSetResult() 69 | { 70 | $this->assertFalse($this->fixture->isStatementSetResult()); 71 | } 72 | 73 | /** 74 | * Tests for isValueResult. 75 | */ 76 | public function testIsValueResult() 77 | { 78 | $this->assertTrue($this->fixture->isValueResult()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/Result/ValueResultImplTest.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Sparql\Test\Result; 14 | 15 | use Saft\Sparql\Result\ValueResultImpl; 16 | 17 | class ValueResultImplTest extends ValueResultAbstractTest 18 | { 19 | /** 20 | * @param $mixed $scalar 21 | * 22 | * @return Result 23 | */ 24 | public function newInstance($scalar) 25 | { 26 | return new ValueResultImpl($scalar); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Saft/Sparql/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Sparql/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-sparql", 3 | "type": "library", 4 | "description": "Sparql package for Saft.", 5 | "keywords": ["Saft", "Linked Data", "Semantic Web", "Sparql", "Query"], 6 | "homepage": "https://safting.github.com/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.6", 24 | "saft/saft-data": ">=1.0", 25 | "saft/saft-rdf": ">=1.0" 26 | }, 27 | "require-dev": { 28 | "phpunit/phpunit": "4.8.*" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "Saft\\Sparql\\": "." 33 | } 34 | }, 35 | "prefer-stable": true 36 | } 37 | -------------------------------------------------------------------------------- /src/Saft/Sparql/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Saft/Store/.coveralls.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | coverage_clover: gen/coverage/clover.xml 12 | json_path: gen/coverage/coveralls-upload.json 13 | service_name: travis-ci 14 | -------------------------------------------------------------------------------- /src/Saft/Store/.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | test-config.yml 3 | /gen 4 | /tmp 5 | /vendor 6 | -------------------------------------------------------------------------------- /src/Saft/Store/.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Saft. 3 | # 4 | # (c) Konrad Abicht 5 | # (c) Natanael Arndt 6 | # 7 | # For the full copyright and license information, please view the LICENSE 8 | # file that was distributed with this source code. 9 | # 10 | 11 | language: php 12 | 13 | php: 14 | - '5.6' 15 | - '7.0' 16 | - '7.1' 17 | - '7.2' 18 | - nightly 19 | 20 | matrix: 21 | fast_finish: true 22 | include: 23 | - php: hhvm 24 | allow_failures: 25 | - php: hhvm 26 | 27 | cache: 28 | directories: 29 | - $HOME/.composer/cache 30 | 31 | sudo: true 32 | 33 | before_install: 34 | - travis_retry composer install --dev --no-interaction 35 | # Install coveralls.phar 36 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar 37 | - chmod +x coveralls.phar 38 | - php coveralls.phar --version 39 | 40 | script: vendor/bin/phpunit --coverage-clover gen/coverage/clover.xml 41 | 42 | after_success: 43 | # Submit coverage report to Coveralls servers, see .coveralls.yml 44 | - travis_retry php coveralls.phar -v 45 | -------------------------------------------------------------------------------- /src/Saft/Store/ChainableStore.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Saft\Store; 14 | 15 | /** 16 | * @api 17 | * 18 | * @since 0.1 19 | */ 20 | interface ChainableStore extends Store 21 | { 22 | /** 23 | * Set successor instance. This method is useful, if you wanna build chain of instances which implement 24 | * StoreInterface. It sets another instance which will be later called, if a statement- or query-related 25 | * function gets called. 26 | * E.g. you chain a query cache and a virtuoso instance. In this example all queries will be handled by 27 | * the query cache first, but if no cache entry was found, the virtuoso instance gets called. 28 | * 29 | * @param Store $successor an instance of a class which implements Store interface 30 | * 31 | * @api 32 | * 33 | * @since 0.1 34 | */ 35 | public function setChainSuccessor(Store $successor); 36 | } 37 | -------------------------------------------------------------------------------- /src/Saft/Store/README.md: -------------------------------------------------------------------------------- 1 | # Saft.store 2 | 3 | [READ-ONLY] _Saft.store_ subtree of the _Saft_ project. 4 | -------------------------------------------------------------------------------- /src/Saft/Store/Test/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * (c) Natanael Arndt 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; 14 | 15 | error_reporting(E_ALL); 16 | -------------------------------------------------------------------------------- /src/Saft/Store/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saft/saft-store", 3 | "type": "library", 4 | "description": "Store package for library Saft.", 5 | "keywords": ["Saft", "Linked Data", "Semantic Web", "Store", "Triple Store"], 6 | "homepage": "https://safting.github.io/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Natanael Arndt", 11 | "homepage": "http://aksw.org/NatanaelArndt", 12 | "email": "arndtn@gmail.com", 13 | "role": "Developer" 14 | }, 15 | { 16 | "name": "Konrad Abicht", 17 | "homepage": "http://www.inspirito.de", 18 | "email": "hi@inspirito.de", 19 | "role": "Developer" 20 | }, 21 | { 22 | "name": "Viktor Befort", 23 | "email": "viktor.befort@stud.htwk-leipzig.de", 24 | "role": "Developer" 25 | } 26 | ], 27 | "require": { 28 | "php": ">=5.6", 29 | "saft/saft-rdf": ">=1.0", 30 | "saft/saft-sparql": ">=1.0" 31 | }, 32 | "require-dev": { 33 | "phpunit/phpunit": "4.8.*" 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "Saft\\Store\\": "." 38 | } 39 | }, 40 | "prefer-stable": true 41 | } 42 | -------------------------------------------------------------------------------- /src/Saft/Store/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ./Test 34 | 35 | 36 | 37 | --------------------------------------------------------------------------------