-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatement.php
More file actions
222 lines (205 loc) · 6.29 KB
/
Copy pathStatement.php
File metadata and controls
222 lines (205 loc) · 6.29 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
namespace librdf;
/* $Id: Statement.php 171 2006-06-15 23:24:18Z das-svn $ */
/**
* Statement, a representation of a single triple.
*
* Statements are a pair of nodes and an arc. Both nodes and the arc are
* represented as {@link Node} objects. Statements are collected into
* a graph using {@link Model}.
*
* PHP version 5
*
* Copyright (C) 2006, David Shea <[email protected]>
*
* LICENSE: This package is Free Software and a derivative work of Redland
* http://librdf.org/. This package is not endorsed by Dave Beckett or the
* University of Bristol. It is licensed under the following three licenses as
* alternatives:
* 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
* 2. GNU General Public License (GPL) V2 or any newer version
* 3. Apache License, V2.0 or any newer version
*
* You may not use this file except in compliance with at least one of the
* above three licenses.
*
* See LICENSE.txt at the top of this package for the complete terms and futher
* detail along with the license tests for the licenses in COPYING.LIB, COPYING
* and LICENSE-2.0.txt repectively.
*
* @package LibRDF
* @author David Shea <[email protected]>
* @copyright 2006 David Shea
* @license LGPL/GPL/APACHE
* @version Release: 1.0.0
* @link http://reallylongword.org/projects/librdf-php/
*/
/**
*/
use librdf\exception\Error;
use librdf\Node;
/**
* A wrapper around the statement datatype.
*
* @package LibRDF
* @author David Shea <[email protected]>
* @copyright 2006 David Shea
* @license LGPL/GPL/APACHE
* @version Release: 1.0.0
* @link http://reallylongword.org/projects/librdf-php/
*/
class Statement
{
/**
* The wrapped statement resource.
*
* @var resource
* @access public
*/
private $statement;
/**
* Create a new Statement.
*
* The subject must be either a URINode or a BlankNode. The predicate
* must be a URINode.
*
* @param mixed $statement The statement to copy or the source Node of a statement
* @param Node $predicate The statement's predicate
* @param Node $object The statement's object
* @return void
* @throws Error If unable to create a new statement
* @access public
*/
public function __construct()
{
$num_args = func_num_args();
if ($num_args == 1) {
$statement = func_get_arg(0);
if (!is_resource($statement)) {
throw new Error("Single parameter must be a statement");
} else {
$this->statement = $statement;
}
} elseif ($num_args == 3) {
$subject = func_get_arg(0);
$predicate = func_get_arg(1);
$object = func_get_arg(2);
if (($subject instanceof Node) and
($predicate instanceof Node) and
($object instanceof Node)) {
$this->statement = librdf_new_statement_from_nodes(librdf_php_get_world(),
librdf_new_node_from_node($subject->getNode()),
librdf_new_node_from_node($predicate->getNode()),
librdf_new_node_from_node($object->getNode()));
} else {
throw new Error("Arguments must be of type Node");
}
}
if (!$this->statement) {
throw new Error("Unable to create new statement");
}
}
/**
* Free a Statement's resources.
*
* @return void
* @access public
*/
public function __destruct()
{
if ($this->statement) {
librdf_free_statement($this->statement);
}
}
/**
* Return a string representation of a statement
*
* @return string The statement as a string
* @access public
*/
public function __toString()
{
return librdf_statement_to_string($this->statement);
}
/**
* Clone a Statement
*
* @return void
* @throws Error If unable to create a new statement
* @access public
*/
public function __clone()
{
$this->statement = librdf_new_statement_from_statement($this->statement);
if (!$this->statement) {
throw new Error("Unable to create new statement from statement");
}
}
/**
* Get the underlying statement resource.
*
* This function is intended for other LibRDF classes and should not
* be called.
*
* @return resource The wrapped statement
* @access public
*/
public function getStatement()
{
return $this->statement;
}
/**
* Get the statement's subject.
*
* @return Node The statement's subject
* @access public
*/
public function getSubject()
{
$node = librdf_statement_get_subject($this->statement);
// create a copy of the node to avoid double frees when the Node
// object gets garbage collected
$object = Node::makeNode(librdf_new_node_from_node($node));
return $object;
}
/**
* Get the statement's predicate
*
* @return Node The statement's predicate
* @access public
*/
public function getPredicate()
{
$node = librdf_statement_get_predicate($this->statement);
$object = Node::makeNode(librdf_new_node_from_node($node));
return $object;
}
/**
* Get the statement's object.
*
* @return Node The statement's object
* @access public
*/
public function getObject()
{
$node = librdf_statement_get_object($this->statement);
$object = Node::makeNode(librdf_new_node_from_node($node));
return $object;
}
/**
* Compare this statement with another statement.
*
* Two statements are equal if each of the three nodes in a statement
* are equal to the corresponding nodes in the other statement.
*
* @param Statement $statement The statement against which to compare
* @return boolean Whether the statements are equal
* @access public
*/
public function isEqual(Statement $statement)
{
return ((boolean) librdf_statement_equals($this->statement,
$statement->getStatement()));
}
}
?>