Add data to the graph
The resource can either be a resource or the URI of a resource.
Example: $graph->add("http://www.example.com", 'dc:title', 'Title of Page');
mixed $resource The resource to add data to:
mixed $property The property name:
mixed $value The new value for the property:
integer The number of values added (1 or 0)
public function add($resource, $property, $value) {
$this
->checkResourceParam($resource);
$this
->checkSinglePropertyParam($property, $inverse);
$this
->checkValueParam($value);
// No value given?
if ($value === null) {
return 0;
}
// Check that the value doesn't already exist
if (isset($this->index[$resource][$property])) {
foreach ($this->index[$resource][$property] as $v) {
if ($v == $value) {
return 0;
}
}
}
$this->index[$resource][$property][] = $value;
// Add to the reverse index if it is a resource
if ($value['type'] == 'uri' or $value['type'] == 'bnode') {
$uri = $value['value'];
$this->revIndex[$uri][$property][] = array(
'type' => substr($resource, 0, 2) == '_:' ? 'bnode' : 'uri',
'value' => $resource,
);
}
// Success
return 1;
}