PHPackages                             sweetrdf/simple-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sweetrdf/simple-rdf

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sweetrdf/simple-rdf
===================

As simple as possible rdfInterface implementation

2.1.2(7mo ago)05.7k—0%6MITPHPPHP &gt;=8.0CI passing

Since Mar 16Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/sweetrdf/simpleRdf)[ Packagist](https://packagist.org/packages/sweetrdf/simple-rdf)[ Docs](https://github.com/sweetrdf/simpleRdf)[ RSS](/packages/sweetrdf-simple-rdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (25)Used By (6)

simpleRdf
=========

[](#simplerdf)

[![Latest Stable Version](https://camo.githubusercontent.com/a9e00a47ab18f6d669c67b6bb2f312a03d5ed10bec363f2b0de9d171dd25e10c/68747470733a2f2f706f7365722e707567782e6f72672f73776565747264662f73696d706c652d7264662f762f737461626c65)](https://packagist.org/packages/sweetrdf/simple-rdf)[![Build status](https://github.com/sweetrdf/simpleRdf/workflows/phpunit/badge.svg?branch=master)](https://github.com/sweetrdf/simpleRdf/workflows/phpunit/badge.svg?branch=master)[![Coverage Status](https://camo.githubusercontent.com/d83a4a27d5fce19f801daeaa52bcd54da140fbec52f1caccfbde6bb9204688c8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73776565747264662f73696d706c655264662f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sweetrdf/simpleRdf?branch=master)[![License](https://camo.githubusercontent.com/d915b8426dab3c851bc279d56cba54b098e0abc060123ac8b9dc7d06f99e79a8/68747470733a2f2f706f7365722e707567782e6f72672f73776565747264662f73696d706c652d7264662f6c6963656e7365)](https://packagist.org/packages/sweetrdf/simple-rdf)

An RDF library for PHP implementing the  interface.

The aim was to provide as simple, short and clear implementation as possible. Performance wasn't really important (see the Performance chapter below).

It can be used as a baseline for testing performance of other libraries as well for testing interoperability of the rdfInterface implementations (e.g. making sure they work correctly with `rdfInterface\Term` objects created by other library).

Installation
------------

[](#installation)

- Obtain the [Composer](https://getcomposer.org)
- Run `composer require sweetrdf/simple-rdf`
- Run `composer require sweetrdf/quick-rdf-io` to install parsers and serializers.

Automatically generated documentation
-------------------------------------

[](#automatically-generated-documentation)

It's very incomplete but better than nothing.
[RdfInterface](https://github.com/sweetrdf/rdfInterface/) documentation is included which explains the most important design decisions.

Usage
-----

[](#usage)

(you can also take a look at generic rdfInterface [examples](https://github.com/sweetrdf/rdfInterface/blob/master/EasyRdfReadme.md))

```
include 'vendor/autoload.php';

use simpleRdf\DataFactory as DF;

$graph = new simpleRdf\Dataset();
$parser = new quickRdfIo\TriGParser(new simpleRdf\DataFactory());
$stream = fopen('pathToTurtleFile', 'r');
$graph->add($parser->parseStream($stream));
fclose($stream);

// count edges in the graph
echo count($graph);

// go trough all edges in the graph
foreach ($graph as $i) {
  echo "$i\n";
}

// find all graph edges with a given subject
echo $graph->copy(DF::quadTemplate(DF::namedNode('http://mySubject')));

// find all graph edges with a given predicate
echo $graph->copy(DF::quadTemplate(null, DF::namedNode('http://myPredicate')));

// find all graph edges with a given object
echo $graph->copy(DF::quadTemplate(null, null, DF::literal('value', 'en')));

// replace an edge in the graph
$edge = DF::quad(DF::namedNode('http://edgeSubject'), DF::namedNode('http://edgePredicate'), DF::namedNode('http://edgeObject'));
$graph[$edge] = $edge->withObject(DF::namedNode('http://anotherObject'));

// find intersection with other graph
$graph->copy($otherGraph); // immutable
$graph->delete($otherGraph); // in-place

// compute union with other graph
$graph->union($otherGraph); // immutable
$graph->add($otherGraph); // in-place

// compute set difference with other graph
$graph->copyExcept($otherGraph); // immutable
$graph->delete($otherGraph); // in-place

$serializer = new quickRdfIo\TurtleSerializer();
$stream = fopen('pathToOutputTurtleFile', 'w');
$serializer->serializeStream($stream, $graph);
fclose($stream);
```

Performance
-----------

[](#performance)

The `simpleRdf\Dataset` class **shouldn't be used** to deal with larger amounts of quads.

Adding a quad has computational complexity of `O(N)` where `N` is the number of quads in the dataset. It means adding `n` quads has computational complexity of `O(n!)` (read - it quickly gets out of hand with larger `n`).

Just a sample results:

quads countexecution time \[s\]relative quads countrelative execution time1250.01809011.02500.05955923.35000.210958411.710000.849956847.020002.94131916162.6400010.69716432591.3800045.792556642531.4You get the idea, don't you?

Other operations are also not performant, e.g. all searches and in-place deletions have complexity of `O(N)` and all methods returning a new copy of the dataset have complexity of `O(N) + O(n!)` (where `N` is number of quads in the dataset and `n` the number of quads in the returned dataset).

If you are looking for a performant implementation, please take a look at the [quickRdf](https://github.com/sweetrdf/quickRdf).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

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 ~75 days

Recently: every ~150 days

Total

23

Last Release

228d ago

Major Versions

0.7.3 → 1.0.0-RC12022-11-01

1.0.0 → 2.0.0-RC12023-07-26

### Community

Maintainers

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

---

Top Contributors

[![zozlak](https://avatars.githubusercontent.com/u/6503177?v=4)](https://github.com/zozlak "zozlak (86 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[godruoyi/php-snowflake

An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).

8582.3M61](/packages/godruoyi-php-snowflake)[tuupola/ksuid

K-Sortable Globally Unique IDs

1081.2M4](/packages/tuupola-ksuid)[sweetrdf/easyrdf

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

261.3M11](/packages/sweetrdf-easyrdf)[mcordingley/linearalgebra

Matrix math for PHP.

85146.3k1](/packages/mcordingley-linearalgebra)[hyva-themes/magento2-wysiwyg-svg

Allow SVGs and all tailwind classes in CMS block and page content.

17130.8k](/packages/hyva-themes-magento2-wysiwyg-svg)[syrian-open-source/laravel-youtube-iframe-generator

Laravel package allows you to generate an iframe tag with a video player depending on a youtube URL.

184.2k](/packages/syrian-open-source-laravel-youtube-iframe-generator)

PHPackages © 2026

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