class EasyRdf_Graph
Container for collection of EasyRdf_Resources.
Methods
object |
__construct(string $uri = null, string $data = null, string $format = null)
Constructor |
|
static object |
newAndLoad(string $uri, string $format = null)
Create a new graph and load RDF data from a URI into it |
|
object |
resource(string $uri = null, mixed $types = array())
Get or create a resource stored in a graph |
|
object |
newBNode(mixed $types = array())
Create a new blank node in the graph and return it. |
|
string |
newBNodeId()
Create a new unique blank node identifier and return it. |
|
integer |
parse(string $data, string $format = null, string $uri = null)
Parse some RDF data into the graph object. |
|
integer |
parseFile(string $filename, string $format = null, string $uri = null)
Parse a file containing RDF data into the graph object. |
|
integer |
load(string $uri = null, string $format = null)
Load RDF data into the graph from a URI. |
|
array |
resources()
Get an associative array of all the resources stored in the graph. |
|
array |
resourcesMatching(string $property, mixed $value = null)
Get an arry of resources matching a certain property and optional value. |
|
string |
getUri()
Get the URI of the graph |
|
mixed |
get(string $resource, string $propertyPath, string $type = null, string $lang = null)
Get a single value for a property of a resource |
|
object |
getLiteral(string $resource, string|array $property, string $lang = null)
Get a single literal value for a property of a resource |
|
object |
getResource(string $resource, string|array $property)
Get a single resource value for a property of a resource |
|
array |
all(string $resource, string $propertyPath, string $type = null, string $lang = null)
Get all values for a property path |
|
array |
allLiterals(string $resource, string $property, string $lang = null)
Get all literal values for a property of a resource |
|
array |
allResources(string $resource, string $property)
Get all resources for a property of a resource |
|
array |
allOfType(string $type)
Get all the resources in the graph of a certain type |
|
integer |
countValues(string $resource, string $property, string $type = null, string $lang = null)
Count the number of values for a property of a resource |
|
string |
join(mixed $resource, string $property, string $glue = ' ', string $lang = null)
Concatenate all values for a property of a resource into a string. |
|
integer |
add(mixed $resource, mixed $property, mixed $value)
Add data to the graph |
|
integer |
addLiteral(mixed $resource, mixed $property, mixed $value, string $lang = null)
Add a literal value as a property of a resource |
|
integer |
addResource(mixed $resource, mixed $property, mixed $resource2)
Add a resource as a property of another resource |
|
integer |
set(string $resource, string $property, mixed $value)
Set a value for a property |
|
integer |
delete(mixed $resource, string $property, mixed $value = null)
Delete a property (or optionally just a specific value) |
|
integer |
deleteSingleProperty(mixed $resource, string $property, mixed $value = null)
Delete a property (or optionally just a specific value) |
|
deleteResource(mixed $resource, mixed $property, mixed $resource2)
Delete a resource from a property of another resource |
||
deleteLiteral(mixed $resource, mixed $property, mixed $value, string $lang = null)
Delete a literal value from a property of a resource |
||
boolean |
isEmpty()
Check if the graph contains any statements |
|
array |
properties($resource)
Get a list of all the shortened property names (qnames) for a resource. |
|
array |
propertyUris($resource)
Get a list of the full URIs for the properties of a resource. |
|
array |
reversePropertyUris($resource)
Get a list of the full URIs for the properties that point to a resource. |
|
boolean |
hasProperty(mixed $resource, string $property, mixed $value = null)
Check to see if a property exists for a resource. |
|
mixed |
serialise(mixed $format, array $options = array())
Serialise the graph into RDF |
|
string |
dump(string $format = 'html')
Return a human readable view of all the resources in the graph |
|
string |
dumpResource(mixed $resource, string $format = 'html')
Return a human readable view of a resource and its properties |
|
string |
type($resource = null)
Get the resource type of the graph |
|
object |
typeAsResource($resource = null)
Get the resource type of the graph as a EasyRdf_Resource |
|
array |
types($resource = null)
Get a list of types for a resource |
|
EasyRdf_Resource[] |
typesAsResources($resource = null)
Get the resource types of the graph as a EasyRdf_Resource |
|
boolean |
isA(string $resource, string $type)
Check if a resource is of the specified type |
|
integer |
addType(string $resource, string $types)
Add one or more rdf:type properties to a resource |
|
integer |
setType(string $resource, string $type)
Change the rdf:type property for a resource |
|
string |
label($resource = null, $lang = null)
Get a human readable label for a resource |
|
EasyRdf_Resource |
primaryTopic($resource = null)
Get the primary topic of the graph |
|
array |
toRdfPhp()
Returns the graph as a RDF/PHP associative array |
|
integer |
countTriples()
Calculates the number of triples in the graph |
|
string |
__toString()
Magic method to return URI of resource when casted to string |
|
string |
__get(string $name)
Magic method to get a property of the graph |
|
__set(string $name, string $value)
Magic method to set the value for a property of the graph |
||
__isset(string $name)
Magic method to check if a property exists |
||
__unset(string $name)
Magic method to delete a property of the graph |
Details
at line 82
public object
__construct(string $uri = null, string $data = null, string $format = null)
Constructor
If no URI is given then an unnamed graph is created.
The $data parameter is optional and will be parsed into the graph if given.
The data format is optional and should be specified if it can't be guessed by EasyRdf.
at line 109
static public object
newAndLoad(string $uri, string $format = null)
Create a new graph and load RDF data from a URI into it
This static function is shorthand for: $graph = new EasyRdf_Graph($uri); $graph->load($uri, $format);
The document type is optional but should be specified if it can't be guessed or got from the HTTP headers.
at line 129
public object
resource(string $uri = null, mixed $types = array())
Get or create a resource stored in a graph
If the resource did not previously exist, then a new resource will be created. If you provide an RDF type and that type is registered with the EasyRdf_TypeMapper, then the resource will be an instance of the class registered.
If URI is null, then the URI of the graph is used.
at line 193
public object
newBNode(mixed $types = array())
Create a new blank node in the graph and return it.
If you provide an RDF type and that type is registered with the EasyRdf_TypeMapper, then the resource will be an instance of the class registered.
at line 203
public string
newBNodeId()
Create a new unique blank node identifier and return it.
at line 216
public integer
parse(string $data, string $format = null, string $uri = null)
Parse some RDF data into the graph object.
at line 245
public integer
parseFile(string $filename, string $format = null, string $uri = null)
Parse a file containing RDF data into the graph object.
at line 270
public integer
load(string $uri = null, string $format = null)
Load RDF data into the graph from a URI.
If no URI is given, then the URI of the graph will be used.
The document type is optional but should be specified if it can't be guessed or got from the HTTP headers.
at line 349
public array
resources()
Get an associative array of all the resources stored in the graph.
The keys of the array is the URI of the EasyRdf_Resource.
at line 382
public array
resourcesMatching(string $property, mixed $value = null)
Get an arry of resources matching a certain property and optional value.
For example this routine could be used as a way of getting everyone who has name: $people = $graph->resourcesMatching('foaf:name')
Or everyone who is male: $people = $graph->resourcesMatching('foaf:gender', 'male');
Or all homepages: $people = $graph->resourcesMatching('^foaf:homepage');
at line 417
public string
getUri()
Get the URI of the graph
at line 571
public mixed
get(string $resource, string $propertyPath, string $type = null, string $lang = null)
Get a single value for a property of a resource
If multiple values are set for a property then the value returned may be arbitrary.
If $property is an array, then the first item in the array that matches a property that exists is returned.
This method will return null if the property does not exist.
at line 672
public object
getLiteral(string $resource, string|array $property, string $lang = null)
Get a single literal value for a property of a resource
If multiple values are set for a property then the value returned may be arbitrary.
This method will return null if there is not literal value for the property.
at line 689
public object
getResource(string $resource, string|array $property)
Get a single resource value for a property of a resource
If multiple values are set for a property then the value returned may be arbitrary.
This method will return null if there is not resource for the property.
at line 743
public array
all(string $resource, string $propertyPath, string $type = null, string $lang = null)
Get all values for a property path
This method will return an empty array if the property does not exist.
at line 845
public array
allLiterals(string $resource, string $property, string $lang = null)
Get all literal values for a property of a resource
This method will return an empty array if the resource does not has any literal values for that property.
at line 859
public array
allResources(string $resource, string $property)
Get all resources for a property of a resource
This method will return an empty array if the resource does not has any resources for that property.
at line 872
public array
allOfType(string $type)
Get all the resources in the graph of a certain type
If no resources of the type are available and empty array is returned.
at line 885
public integer
countValues(string $resource, string $property, string $type = null, string $lang = null)
Count the number of values for a property of a resource
at line 901
public string
join(mixed $resource, string $property, string $glue = ' ', string $lang = null)
Concatenate all values for a property of a resource into a string.
The default is to join the values together with a space character. This method will return an empty string if the property does not exist.
at line 918
public integer
add(mixed $resource, mixed $property, mixed $value)
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');
at line 966
public integer
addLiteral(mixed $resource, mixed $property, mixed $value, string $lang = null)
Add a literal value as a property of a resource
The resource can either be a resource or the URI of a resource. The value can either be a single value or an array of values.
Example: $graph->add("http://www.example.com", 'dc:title', 'Title of Page');
at line 995
public integer
addResource(mixed $resource, mixed $property, mixed $resource2)
Add a resource as a property of another resource
The resource can either be a resource or the URI of a resource.
Example: $graph->add("http://example.com/bob", 'foaf:knows', 'http://example.com/alice');
at line 1020
public integer
set(string $resource, string $property, mixed $value)
Set a value for a property
The new value will replace the existing values for the property.
at line 1040
public integer
delete(mixed $resource, string $property, mixed $value = null)
Delete a property (or optionally just a specific value)
at line 1072
public integer
deleteSingleProperty(mixed $resource, string $property, mixed $value = null)
Delete a property (or optionally just a specific value)
at line 1115
public
deleteResource(mixed $resource, mixed $property, mixed $resource2)
Delete a resource from a property of another resource
The resource can either be a resource or the URI of a resource.
Example: $graph->delete("http://example.com/bob", 'foaf:knows', 'http://example.com/alice');
at line 1141
public
deleteLiteral(mixed $resource, mixed $property, mixed $value, string $lang = null)
Delete a literal value from a property of a resource
Example: $graph->delete("http://www.example.com", 'dc:title', 'Title of Page');
at line 1181
public boolean
isEmpty()
Check if the graph contains any statements
at line 1192
public array
properties($resource)
Get a list of all the shortened property names (qnames) for a resource.
This method will return an empty array if the resource has no properties.
at line 1214
public array
propertyUris($resource)
Get a list of the full URIs for the properties of a resource.
This method will return an empty array if the resource has no properties.
at line 1229
public array
reversePropertyUris($resource)
Get a list of the full URIs for the properties that point to a resource.
at line 1254
public boolean
hasProperty(mixed $resource, string $property, mixed $value = null)
Check to see if a property exists for a resource.
This method will return true if the property exists. If the value parameter is given, then it will only return true if the value also exists for that property.
By providing a value parameter you can use this function to check to see if a triple exists in the graph.
at line 1294
public mixed
serialise(mixed $format, array $options = array())
Serialise the graph into RDF
The $format parameter can be an EasyRdf_Format object, a format name, a mime type or a file extension.
Example: $turtle = $graph->serialise('turtle');
at line 1312
public string
dump(string $format = 'html')
Return a human readable view of all the resources in the graph
This method is intended to be a debugging aid and will return a pretty-print view of all the resources and their properties.
at line 1338
public string
dumpResource(mixed $resource, string $format = 'html')
Return a human readable view of a resource and its properties
This method is intended to be a debugging aid and will print a resource and its properties.
at line 1399
public string
type($resource = null)
Get the resource type of the graph
The type will be a shortened URI as a string. If the graph has multiple types then the type returned may be arbitrary. This method will return null if the resource has no type.
at line 1418
public object
typeAsResource($resource = null)
Get the resource type of the graph as a EasyRdf_Resource
If the graph has multiple types then the type returned may be arbitrary. This method will return null if the resource has no type.
at line 1438
public array
types($resource = null)
Get a list of types for a resource
The types will each be a shortened URI as a string. This method will return an empty array if the resource has no types.
If $resource is null, then it will get the types for the URI of the graph.
at line 1455
public EasyRdf_Resource[]
typesAsResources($resource = null)
Get the resource types of the graph as a EasyRdf_Resource
at line 1472
public boolean
isA(string $resource, string $type)
Check if a resource is of the specified type
at line 1491
public integer
addType(string $resource, string $types)
Add one or more rdf:type properties to a resource
at line 1517
public integer
setType(string $resource, string $type)
Change the rdf:type property for a resource
Note that if the resource object has already previously been created, then the PHP class of the resource will not change.
at line 1534
public string
label($resource = null, $lang = null)
Get a human readable label for a resource
This method will check a number of properties for a resource (in the order: skos:prefLabel, rdfs:label, foaf:name, dc:title) and return an approriate first that is available. If no label is available then it will return null.
at line 1554
public EasyRdf_Resource
primaryTopic($resource = null)
Get the primary topic of the graph
at line 1573
public array
toRdfPhp()
Returns the graph as a RDF/PHP associative array
at line 1582
public integer
countTriples()
Calculates the number of triples in the graph
at line 1597
public string
__toString()
Magic method to return URI of resource when casted to string
at line 1613
public string
__get(string $name)
Magic method to get a property of the graph
Note that only properties in the default namespace can be accessed in this way.
Example: $value = $graph->title;
at line 1629
public
__set(string $name, string $value)
Magic method to set the value for a property of the graph
Note that only properties in the default namespace can be accessed in this way.
Example: $graph->title = 'Title';
at line 1644
public
__isset(string $name)
Magic method to check if a property exists
Note that only properties in the default namespace can be accessed in this way.
Example: if (isset($graph->title)) { blah(); }
at line 1659
public
__unset(string $name)
Magic method to delete a property of the graph
Note that only properties in the default namespace can be accessed in this way.
Example: unset($graph->title);