graphaware / neoclient-timetree
GraphAware TimeTree Neo4j 插件的 PHP NeoClient 扩展
Requires
- neoxygen/neoclient: ~2.1
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2022-02-01 12:44:43 UTC
README
此库通过添加与Neo4j PHP NeoClient一起使用的便捷方法来扩展GraphAware TimeTree 插件。
在某个点上,该库将 TimeTree 插件的某些高价值功能与 Cypher 混合,以保持与 NeoClient 使用的响应结果的一致性,允许使用节点对象。
安装和设置
您需要在依赖中要求此库并在 NeoClient 中注册扩展
composer.json
"require": { "neoxygen/neoclient": "~2.1", "graphaware/neoclient-timetree": "~1.0" }
在构建客户端时注册扩展
use Neoxygen\NeoClient\ClientBuilder; $client = ClientBuilder::create() ->addDefaultLocalConnection() ->setAutoFormatResponse(true) ->registerExtension('graphaware_timetree', 'GraphAware\NeoClientExtension\TimeTree\TimeTreeExtension') ->build();
请注意,扩展名 graphaware-timetree
可以更改为您想要的任何名称。
注意
由于 NeoClient 本地构建用于与多个 Neo4j 实例一起工作,以下每个方法的最后一个参数是连接别名字符串(省略时使用默认连接)。
为 TimeTree 时间节点添加模式索引
使用此简单方法,它将在年、月、日、时、分、秒和毫秒节点上添加模式索引。
$client->createTimeTreeIndexes();
通常,在构建应用程序时应仅运行一次。
用法
对于以下所有方法,timestamp
是可选的,省略时将使用“NOW”时间戳。
获取时间瞬间节点
只需将时间戳传递给以下方法,您将获得时间瞬间节点 ID 和所有自动创建的时间树
$today = $client->getTimeNode(time());
TimeTree 插件的默认分辨率为 day
,您可以使用扩展提供的 timetree 常量来增加或减少分辨率
use GraphAware\NeoClientExtension\TimeTree\TimeTreeExtension; $now = $client->getTimeNode(time(), TimeTreeExtension::TIMETREE_RESOLUTION_MILLISECOND);
向时间瞬间添加节点
您需要传递事件的节点 ID、时间和所需的关系类型。请注意,关系是从时间瞬间节点到事件节点单向的。
// Example for adding a node to a timeTree after its creation : $q = 'CREATE (n:SuperEvent) RETURN n'; $result = $client->sendCypherQuery($q)->getResult(); $nodeId = $result->get('n')->getId(); $client->addNodeToTime($nodeId, time(), 'EVENT_OCCUR_ON'); // Returns true
检索某个时间的事件节点
此方法将 timetree 功能与 Cypher 混合,以检索您的对象中的所有节点信息,如标签等...
$result = $client->getTimeEvents(time())->getResult(); // Returns you a collection of nodes, the identifier of the collection is "n" $events = $result->get('n'); // OR $events = $result->getNodes();
检索在时间范围内发生的事件节点
在此处应指定开始时间,默认结束时间为 NOW
。
$result = $client->getTimeEventsInRange(112556325)->getResult(); // Again the identifier is n $events = $result->get('n');
您还可以指定分辨率,例如,到小时
$result = $client->getTimeEventsInRange( 112556325, time(), TimeTreeExtension::TIMETREE_RESOLUTION_HOUR )->getResult(); // Again the identifier is n $events = $result->get('n');
将事件添加到具有指定 rootNodeId 的时间树中
$client->addNodeToTimeForRoot($rootNodeId, $eventNodeId, $time, $relationshipType, $resolution, $connection);
根据时间和指定的rootNodeId检索事件
$events = $client->getTimeEventsForRoot($rootNodeId, $time);
待办事项
- 支持更多的TT功能
- 支持多个树根
- 更多的Cypher/TT集成,例如通过时间标签检索节点
- 用户自定义检索事件的方法(Cypher或TT)
测试
使用PHPUnit运行测试套件
./vendor/bin/phpunit
许可证
版权所有 (c) 2014 GraphAware
GraphAware是免费软件:您可以在自由软件基金会发布的GNU通用公共许可证的条款下重新分发和/或修改它,无论是许可证的第3版,还是(根据您的选择)任何较新版本。本程序分发时附带希望它将是有用的,但没有任何保证;甚至没有关于适销性或适用于特定目的的隐含保证。有关详细信息,请参阅GNU通用公共许可证。您应已收到与该程序一起的GNU通用公共许可证副本。如果没有,请参阅https://gnu.ac.cn/licenses/。