PHPackages                             botk/rdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. botk/rdf

AbandonedArchivedLibrary[API Development](/categories/api)

botk/rdf
========

EasyRdf extension to support authentication and reasoning in some sparql endpoints.

4.1.1(10y ago)32441MITPHPPHP &gt;=5.5

Since Jan 28Pushed 9y ago1 watchersCompare

[ Source](https://github.com/linkeddatacenter/BOTK-rdf)[ Packagist](https://packagist.org/packages/botk/rdf)[ Docs](http://ontology.it/tools/botk4/rdf/)[ RSS](/packages/botk-rdf/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (7)Used By (1)

WARNING
=======

[](#warning)

The support to this project is now discontinued. Update your links.

Find the old version as tagged branch.

BOTK\\Rdf
=========

[](#botkrdf)

[![Build Status](https://camo.githubusercontent.com/bc7222e9d4b2b007bd42be7d0fa89e3390d00df18de30a6d81c1bf556f5282d4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c696e6b65646461746163656e7465722f424f544b2d7264662e7376673f7374796c653d666c61742d737175617265)](http://travis-ci.org/linkeddatacenter/BOTK-rdf)[![Code Coverage](https://camo.githubusercontent.com/0c6f843875a906b796dffb5ed8c022ae6995ab05f68a82c57efce97c2fe10fb7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6c696e6b65646461746163656e7465722f424f544b2d7264662e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/linkeddatacenter/BOTK-rdf)[![Latest Version](https://camo.githubusercontent.com/8d12c3724f590b31ce217d612a5262a0c4b29483a838c2bce3959b78ef5921d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626f746b2f7264662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/botk/rdf)[![Total Downloads](https://camo.githubusercontent.com/6f3c0047e53ddddae5b891cb0a5be23438f218f522f93f9189a0acd5a30da09e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f746b2f7264662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/botk/rdf)[![License](https://camo.githubusercontent.com/76049c9c065bac2fd7dd617827848c76c70e918c12744249b02fc766d9b04e93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626f746b2f7264662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/botk/rdf)

This package is an [EasyRDF](http://www.easyrdf.org/) extension to support authentication,reasoning, LDP server endpoints and more.

It extends the default [httpclient of EasyRDF](http://www.easyrdf.org/docs/api/EasyRdf_Http_Client.html) to support basic authentication and and provides two content negotiation policies to manage consistently representations for RDF graphs and for Sparql Results data models.

Beside this it contains an implementation of a simple end point to publish linked data supporting many serialization and html according [Linked Data Platform Editor Draft specification](https://dvcs.w3.org/hg/ldpwg/raw-file/default/ldp.html)

This package is available on [Packagist](https://packagist.org/packages/botk/rdf).

You can install adding following dependances to **composer.json** file in your project root:

```
    {
      "require": {
        "botk/rdf": "*"
      }
    }

```

Documentation
=============

[](#documentation)

HttpClient class
----------------

[](#httpclient-class)

This class is a replacement for[EasyRDF http client class](http://www.easyrdf.org/docs/api/EasyRdf_Http_Client.html). It adds the `setAuth(string $user, string $password)` method supporting basic http authentication type. HttpClient in turn it is a lightware alternative to *Zend\_Http\_client* or *Guzzle* libraries.

HttpClient is normally used as HTTP protocol wrapper for all EasyRDF specialized clients and for [SparqlClient](#SparqlClient)through [`EasyRdf_Http::setDefaultHttpClient()`](http://www.easyrdf.org/docs/api/EasyRdf_Http.html)method, but it can be also used as a generic Web Resource client.

For example, to use simple client identity in accessing a remote sparql endpoint execute:

```
// define common properties of http client to use to access RDF web resources
$httpClient = new BOTK\RDF\HttpClient;
$httpClient->setAuth('username', 'password');
EasyRdf_Http::setDefaultHttpClient($httpClient);

// access a private sparql end-point that requires basic authentication
$sparql = new EasyRdf_Sparql_Client('https://private/sparql');
$result=$sparql->query('SELECT * WHERE {?s ?p ?o} LIMIT 10');

```

HttpClient interface is compatible with [ZEND-Http\_client library](http://framework.zend.com/manual/2.2/en/modules/zend.http.client.html).

HttpClient provides a simple helper to create an authenticated HTTP client and use it in EasyRdf with a single call of the static method `HttpClient::useIdentity(string $usename = null, string $password=null, $timeout=null )` . If not specified the client will reuse the timeout of the calling script (if available) or 30 sec. otherwise. Using the helper, the previous code can be shorten as:

```
BOTK\RDF\HttpClient::useIdentity('username','password');

$sparql = new EasyRdf_Sparql_Client('https://private/sparql');
$result=$sparql->query('SELECT * WHERE {?s ?p ?o} LIMIT 10');

```

.

Content negotiation policies
----------------------------

[](#content-negotiation-policies)

### RDF

[](#rdf)

This content negotiation policy is designed for applications that use EasyRff\_Graph data structure as Resource Model.

It provide following response and request representations:

```
  RDF class define following renderer functions:

```

RDF::turtleRenderer(mixed $data, Standard::n3Renderer(mixed $data) Serializes data structure as RDF text/turle RDF::rdfxmlRenderer(mixed $data) Serializes data structure as RDF application/xml+rdf. RDF::jsonRenderer(mixed $data) Serializes data structure using jsonRDF::ntriplesRenderer(mixed $data) serializes data structure RDF ntriples. RDF::htmlRenderer(mixed $data) serializes data structure as html. RDF::serialphpRenderer(mixed $data) serializes data structure as php.### SparqlClientResult

[](#sparqlclientresult)

This content negotiation policy is designed for applications that use EasyRdf\_Sparql\_Result data structure as Resource Model.

It provide following response and request representations:

Simple Linked Data Platform Server (SLDPS)
------------------------------------------

[](#simple-linked-data-platform-server-sldps)

This set of classes allow you to implement a simple endpoint to publish linked data according last [Linked Data Platform Woking Group Draft Specifications](http://www.w3.org/2012/ldp/wiki/Main_Page). The provided classes can be used to base Linked Data Platform Server Implementations.

Here is a simple script that realizes an LDP PAGING server:

```
    class MyRouter extends EndPoint
    {
        protected function setRoutes()
        {
            $this->get('/', 'ProductsController')
                ->accept(RDF::renderers())
                ->through($this->representationCachingProcessor(Caching::SHORT));
        }
    }

    class ProductsController extends SparqlLDPController
    {
        protected
            $pagesize       = 10,
            $pagingPolicy   = self::CONSERVATIVE,
            $endpoint       = 'http://linkedopencommerce.com/sparql/',
            $constructor    = '
                PREFIX gr:
                DESCRIBE ?product WHERE {
                    ?product a gr:ProductOrServiceModel.
                }
            ';
    }

    $errorManager = BOTK\Core\ErrorManager::getInstance()->registerErrorHandler();
    try {
        echo BOTK\Core\EndPointFactory::make('MyRouter')->run();
    } catch ( Exception $e) {
        echo $errorManager->render($e);
    }

```

LDPController class
-------------------

[](#ldpcontroller-class)

This class provides an generic abstract implementation of a LDP paged controller. In order to get a working implementation you have to implement three methods:

- `detectIfHasNextPage()`: that must return true if another linked data page is available. If it is not provided, paging features will be disabled.
- `linkData()`: that populate the protected var `resultGraph` (an EasyRdf\_Graph object) with linked resource
- `linkMetaData()`: that optionally add metadata to `resultGraph`

It provides a simple template engine (from Core Package) populated with a set of predefine variables placeholders:

- `{pagedResourceUri}` : the requested uri without page info;
- `{strippedUri}` : the requested uri without query strings and fragment.
- `{requestUri}` : the requested uri as written by user (with or partial page info)

The protected `context` variable contains an instance of Core PagedResourceContext.

SparqlLDPController Class
-------------------------

[](#sparqlldpcontroller-class)

This class extends LDPController and provides a generic implementation of a Linked Data Platform Server that publish as Linked Data Resources some resources contained in a sparql Server.

You need to redefine following variables to override defaults :

$usernamethe username required to access sparql update endpoint, default is empty$passwordthe password required to access sparql update endpoint. only Basic method supported, default is empty$endpointthe sparql endpoint uri. The default is empty. Examples of valid open sparql endpoints are: , ,  $pagingPolicyit is a string value that can be `AGGRESSIVE` or `CONSERVATIVE` to drive next page detection algorithm. The default is AGGRESSIVE$constructormust contain a valid sparq query template that build a graph with linked data. Do not include LIMIT/OFFSET clause.The default is empty.$metadataoptionally contains a turtle template with paged resource metadata. The default is emptySparqlLDPController class implements LDPController abstract methods:

- it provides an implementation of `detectIfHasNextPage()` based on a parametric algorithm that use the ` $pagingPolicy` variable. If `$pagingPolicy`=AGGRESSIVE than `detectIfHasNextPage()`method returns true when last query to sparqls server resulted in exactly `$pagesize` triples, false otherwise. If `$pagingPolicy`=CONSERVATIVE returns true when last query to sparql server was not empty.
- It provides an implementation of `linkData()` methods based on the sparql query in `$selector`variable.
- It provides an implementation of `linkMedtadata()` methods based on the turtle template in in `$metadata` variable.

Beside this, SparqlLDPController class implements :

- `get($resourceId=null)`: a default controller get methods with an optional argument that is set by router.

This class add following predefined variables placeholders to the simple template engine:

- `{endpoint}`: the value of the variable of the same name.
- `{limit}`: same value of PagedResouceContext::getPageSize()
- `{offset}`: a calculated value as PagedResouceContext::getPageNum() \* PagedResouceContext::getPageSize()
- `{username}`: the value of the variable of the same name.
- `{containerUri}`: the guessed uri of the container extracted from {strippedUri}
- `{resourceId}`: the value of the router template var argument. If resouceId is an array, it is transformed in string with `implode('/',$resourceId)` php instruction.
- `{encodedResourceId}`: same as {resourceId} but url encoded.

You can use these variables, plus the ones defined in LDPController, in $constructor and $metadata templates.

```
    Here is a full example of a contanainer/resource LDP-PAGING implementation using void and prov ontology to
    annotate resources:

```

```
    class MyRouter extends EndPoint
    {
        protected function setRoutes()
        {
            $this->get('/', 'DatasetController');
            $this->get('/*','DataDumpController');

            $this->always('Accept', RDF::renderers() );
            $this->always('Through', $this->representationCachingProcessor(Caching::SHORT));
        }
    }

    class DataDumpController extends SparqlLDPController
    {
        protected $endpoint = 'http://lod.openlinksw.com/sparql';

        protected $constructor  = '
            PREFIX ld:
            CONSTRUCT {
              ?ldpr ?p ?o .
            } WHERE {
                GRAPH  {
                    ?ldpr ?p ?o
                    FILTER (?ldpr = ld:{resourceId} )
                }
            } LIMIT {limit} OFFSET {offset}
        ';

        protected $metadata = '
            @base  .
            @prefix foaf:  .
            @prefix void:  .
            @prefix prov:  .
            @prefix ldp:   .
            @prefix rdfs:  .
            @prefix container:   .
            @prefix ld:  .
             a ldp:Resource, foaf:Document, prov:Entity ;
                foaf:primaryTopic ld:{resourceId} ;
                void:inDataset container:dataset ;
                rdfs:seeAlso  ;
                prov:wasGeneratedBy [
                    a prov:Activity ;
                    prov:used  ;
                    prov:wasAssociatedWith container:sparqlServerUser ;
               ]
            .
         ';
    }

    class DatasetController extends SparqlLDPController
    {
        protected $type     = 'DirectContainer';
        protected $endpoint = 'http://lod.openlinksw.com/sparql';

        protected $constructor  = '
            PREFIX void:
            PREFIX ldp:
            CONSTRUCT {
               void:dataDump ?ldpr .
            } WHERE {
                GRAPH  {
                    ?resource a ?type
                    FILTER(!isBlank(?resource))
                }
                BIND( IRI(REPLACE(STR(?resource), "http://e-artspace.com/s/eCloud#","{strippedUri}")) AS ?ldpr)
            }
        ';

        protected $metadata = '
            @base  .
            @prefix foaf:  .
            @prefix void:  .
            @prefix prov:  .
            @prefix ldp:   .
            @prefix :  .
              a ldp:DirectContainer, foaf:Document ;
                foaf:primaryTopic :dataset ;
                ldp:membershipResource :dataset ;
                ldp:hasMemberRelation void:dataDump ;
                ldp:insertedContentRelation foaf:primaryTopic ;

            .
            :dataset a void:Dataset, prov:Entity ;
                prov:wasGeneratedBy [
                    a prov:Activity ;
                    prov:used  ;
                    prov:wasAssociatedWith :sparqlServerUser
                ]
            .
            :sparqlServerUser a foaf:Agent;
                foaf:account [
                    a foaf:OnlineAccount ;
                    foaf:accountServiceHomepage  ;
                    foaf:accountname "{username}" ;
                ]
            .
         ';
    }

    $errorManager = BOTK\Core\ErrorManager::getInstance()->registerErrorHandler();
    try {
        echo BOTK\Core\EndPointFactory::make('MyRouter')->run();
    } catch ( Exception $e) {
        echo $errorManager->render($e);
    }

```

License
=======

[](#license)

Copyright © 2016 by Enrico Fagnoni at [LinkedData.Center](http://LinkedData.Center/)®

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

6

Last Release

3700d ago

PHP version history (2 changes)4.0.0PHP &gt;=5.3

4.0.2PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/cdabb6f1a7cc46c4a299c684f66c7e3ae2fda117fe4db45758c01fe24d66221b?d=identicon)[botk](/maintainers/botk)

---

Top Contributors

[![ecow](https://avatars.githubusercontent.com/u/5788689?v=4)](https://github.com/ecow "ecow (6 commits)")

---

Tags

RDFSemantic WebLinked DataTurtleLinkedData.CenterE-ArtspaceEasyRdf

### Embed Badge

![Health badge](/badges/botk-rdf/health.svg)

```
[![Health](https://phpackages.com/badges/botk-rdf/health.svg)](https://phpackages.com/packages/botk-rdf)
```

###  Alternatives

[easyrdf/easyrdf

EasyRdf is a PHP library designed to make it easy to consume and produce RDF.

62231.5M42](/packages/easyrdf-easyrdf)[sweetrdf/easyrdf

EasyRdf is a PHP library designed to make it easy to consume and produce RDF.

261.3M11](/packages/sweetrdf-easyrdf)[digitalbazaar/json-ld

A JSON-LD Processor and API implementation in PHP.

28555.4k1](/packages/digitalbazaar-json-ld)[pietercolpaert/hardf

A fast parser for RDF serializations such as turtle, n-triples, n-quads, trig and N3

37141.1k9](/packages/pietercolpaert-hardf)[aksw/erfurt

PHP/Zend based Semantic Web API for Social Semantic Software

426.6k1](/packages/aksw-erfurt)[wikimedia/purtle

Fast streaming RDF serializer

11698.1k1](/packages/wikimedia-purtle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
