sweetrdf/rdf-interface
Composer 安装命令:
composer require sweetrdf/rdf-interface
包简介
A common RDF interface for PHP RDF libraries.
README 文档
README
Why do we need common interfaces?
The PHP RDF ecosystem suffers from big monolythic libraries trying to provide a full RDF stack from parsers to triplestores, serializers and sometimes even SPARQL engines in one library.
It makes them quite difficult to maintain and extend. It also makes it impossible to couple parts of different libraries with each other, e.g. combine a faster parser from one library with a nicer triplestore from another.
The solution for these troubles is to agree on
- A set of separate RDF stack layers: parser, serializer, dataset, SPARQL client, etc.
- Common interfaces each layer should use to communicate with the other (think of it as a PSR-7 for RDF).
Implementations
- The reference implementation of
Termand theDatasetclasses are provided by the quickRdf library and the simpleRdf library. - Turtle, NTriples, NQuads and NTriplesStar parsers and serialisers are provided by the quickRdfIo library.
- A collection of
QuadTemplateandLiteralTemplateclasses providing a convenient way for quads/triples filtering can be found in the termTemplates library. - The sparqlClient library provides a SPARQL client (still in early development).
- Generic helpers which can be reuesed when developing your own implementations or plugging foreign code can be found in the rdfHelpers library.
Compliance tests
The rdfInterfaceTests provides a set of tests for validating if your library is compliant with the rdfInterface.
For EasyRdf users
If you are using EasyRdf, you are likely to find the rdfInterface API quite strange and difficult to understand.
This document should help.
There's also an rdfInterface2easyRdf library which provides conversion routines between rdfInterface and EasyRdf (in both directions).
Design decisions
Inspirations
The rdfInterface is strongly influenced by RDF/JS and RDFLib.
Strong typing
The rdfInterface is strongly typed.
Strong typing provides many benefits. It assures the syntax is unambiguous and extensible, allows to leverage static code analysis and makes errors easier to understand.
The downside of strong typing is much more verbose syntax but we decided benefits outweight it easily.
Immutability
RdfInterface terms are immutable. It's impossible to change their properties. You can only get a new object instance with a given property set to a new value.
Immutability provides three benefits:
- It makes it clear for the programmer that there is no back-propagation of changes.
- It's easy to implement it without flaws (in contrary to deep cloning).
- It allows to implement useful performance optimizations (e.g. a global term cache).
And modern PHP should be already familiar with it as e.g. PSR-7 request/response objects follow the same approach.
Use streams for data import and export
RdfInterface uses streams as RDF parsing input and serialization output.
Streams are far more flexible than strings. They allow asynchronous operation, have lower memory footprint, fit the PSR-7 interface nicely and much more.
Last but not least a string can be easilly packed into a in-memory stream.
Reuse native PHP interfaces
RdfInterface, especially the Dataset interface extends native PHP interfaces, e.g.:
- iterable over edges/nodes of a dataset.
- ArrayAccess for adding/removing/accessing edges of a dataset.
- Countable for e.g. counting quads in a dataset.
Using native interfaces makes the library easier to learn and it feels better integrated with the PHP ecosystem.
Extensibility
RdfInterface is meant to be extensible.
RDF is changing with new ideas being introduced (like RDF-star) and the API should be able to accomodate such developments.
For that reason the Quad specification is rather relaxed and allows any term as a subject and object.
It doesn't mean all implementations must support any possible term. Implementations may support any subset they want, just checking if they can deal with a term they recive from user is their responsibility.
sweetrdf/rdf-interface 适用场景与选型建议
sweetrdf/rdf-interface 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.26M 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sweetrdf/rdf-interface 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sweetrdf/rdf-interface 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.26M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 20
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-16