定制 sweetrdf/simple-rdf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sweetrdf/simple-rdf

最新稳定版本:2.1.2

Composer 安装命令:

composer require sweetrdf/simple-rdf

包简介

As simple as possible rdfInterface implementation

README 文档

README

Latest Stable Version Build status Coverage Status License

An RDF library for PHP implementing the https://github.com/sweetrdf/rdfInterface 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

  • Obtain the Composer
  • Run composer require sweetrdf/simple-rdf
  • Run composer require sweetrdf/quick-rdf-io to install parsers and serializers.

Automatically generated documentation

https://sweetrdf.github.io/simpleRdf/namespaces/simplerdf.html

It's very incomplete but better than nothing.
RdfInterface documentation is included which explains the most important design decisions.

Usage

(you can also take a look at generic rdfInterface examples)

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

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 count execution time [s] relative quads count relative execution time
125 0.018090 1 1.0
250 0.059559 2 3.3
500 0.210958 4 11.7
1000 0.849956 8 47.0
2000 2.941319 16 162.6
4000 10.697164 32 591.3
8000 45.792556 64 2531.4

You 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.

统计信息

  • 总下载量: 5.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-14