-
Notifications
You must be signed in to change notification settings - Fork 61
/
GraphInterface.php
117 lines (106 loc) · 3.4 KB
/
GraphInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
* (c) Markus Lanthaler <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ML\JsonLD;
/**
* JSON-LD graph interface
*
* @author Markus Lanthaler <[email protected]>
*/
interface GraphInterface
{
/**
* Creates a new node which is linked to this document
*
* If a blank node identifier or an invalid ID is passed, the ID will be
* ignored and a new blank node identifier unique to the document is
* created for the node.
*
* If there exists already a node with the passed ID in the document,
* that node will be returned instead of creating a new one.
*
* @param null|string $id The ID of the node.
* @param bool $preserveBnodeId If set to false, blank nodes are
* relabeled to avoid collisions;
* otherwise the blank node identifier
* is preserved.
*
* @return Node The newly created node.
*/
public function createNode($id = null, $preserveBnodeId = false);
/**
* Removes a node from the document
*
* This will also eliminate all references to the node within the
* document.
*
* @param NodeInterface $node The node to remove from the document.
*
* @return self
*/
public function removeNode(NodeInterface $node);
/**
* Get all nodes
*
* @return Node[] Returns an array containing all nodes defined in the
* document.
*/
public function getNodes();
/**
* Get a node by ID
*
* @param string $id The ID of the node to retrieve.
*
* @return Node|null Returns the node if found; null otherwise.
*/
public function getNode($id);
/**
* Get nodes by type
*
* @param string|Node $type The type
*
* @return Node[] Returns an array containing all nodes of the specified
* type in the document.
*/
public function getNodesByType($type);
/**
* Check whether the document already contains a node with the
* specified ID
*
* @param string|Node $id The node ID to check. Blank node identifiers
* will always return false except a node instance
* which is part of the document will be passed
* instead of a string.
*
* @return bool Returns true if the document contains a node with the
* specified ID; false otherwise.
*/
public function containsNode($id);
/**
* Get the document the node belongs to
*
* @return null|DocumentInterface Returns the document the node belongs
* to or null if the node doesn't belong
* to any document.
*/
public function getDocument();
/**
* Removes the graph from the document
*
* @return self
*/
public function removeFromDocument();
/**
* Merges the specified graph into the current graph
*
* @param GraphInterface $graph The graph that should be merged into the
* current graph.
*
* @return self
*/
public function merge(GraphInterface $graph);
}