甜RDF / quick-rdf
又一 个RDF库
2.0.1
2024-03-13 14:37 UTC
Requires
- php: >=8.0
- sweetrdf/rdf-helpers: ^2
- sweetrdf/rdf-interface: ^2
- sweetrdf/term-templates: ^2.0.2
- zozlak/rdf-constants: ^1.1
Requires (Dev)
- phpstan/phpstan: ^1
- phpunit/phpunit: ^10
- sweetrdf/rdf-interface-tests: 2.0.0
- sweetrdf/simple-rdf: ^2
Suggests
This package is auto-updated.
Last update: 2024-09-22 12:40:10 UTC
README
一个为PHP提供的RDF库,实现了https://github.com/sweetrdf/rdfInterface术语和数据集。
设计为快速和内存高效。
这是通过使用全局术语哈希表并在给定时间只存储相同rdfInterface术语的一个副本来实现的。它允许在密集图中节省大量内存,并提供闪电般的术语比较(如果且仅如果它是同一对象)。它还提供了一个非常高效的Dataset集合操作实现,使用PHP的SplObjectStorage。
数据集实现维护索引,允许快速四元组搜索(如果需要,可以关闭索引,因为它会显著减慢数据集的创建)。
安装
- 获取Composer
- 运行
composer require sweetrdf/quick-rdf
- 运行
composer require sweetrdf/quick-rdf-io
来安装解析器和序列化器。
自动生成的文档
https://sweetrdf.github.io/quickRdf/namespaces/quickrdf.html
它很不完整,但总比没有好。
包含RdfInterface文档,它解释了最重要的设计决策。
用法
(您还可以查看通用的rdfInterface 示例)
include 'vendor/autoload.php'; use quickRdf\DataFactory as DF; $graph = new quickRdf\Dataset(); $parser = new quickRdfIo\TriGParser(); $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);