Docs For Class EasyRdf_Graph

## Class EasyRdf_Graph

Description

Container for collection of EasyRdf_Resources.

- copyright: Copyright (c) 2009-2010 Nicholas J Humfrey
- license: http://www.opensource.org/licenses/bsd-license.php

Located in /EasyRdf/Graph.php (line 46)

Method Summary
object EasyRdf_Graph __construct ([string $uri = null], [string $data = null], [string $format = null])
void add (mixed $resource, mixed $property, mixed $value)
void addLiteral (mixed $resource, mixed $property, mixed $value, [string $lang = null])
void addResource (mixed $resource, mixed $property, mixed $resource2)
void addType (string $resource, $types, string $type)
array all (string $resource, string $property, [string $type = null], [string $lang = null])
array allLiterals (string $resource, string $property, [string $lang = null])
array allOfType (string $type)
array allResources (string $resource, string $property)
integer countTriples ()
null delete ( $resource, string $property, [object $value = null])
string dump ([bool $html = true])
string dumpResource ( $resource, [bool $html = true])
mixed get (string $resource, string|array $property, [string $type = null], [string $lang = null])
object EasyRdf_Literal getLiteral (string $resource, string|array $property, [string $lang = null])
object EasyRdf_Resource getResource (string $resource, string|array $property)
string getUri ()
bool hasProperty ( $resource, string $property)
boolean isEmpty ()
boolean is_a ( $resource, string $type)
string join ( $resource, string $property, [string $glue = ' '], [string $lang = null])
string label ([ $resource = null], [ $lang = null])
void load ([string $uri = null], [string $data = null], [string $format = null])
object EasyRdf_Resource newBNode ([mixed $types = array()])
string newBNodeId ()
void parse (string $data, [string $format = null], [string $uri = null])
EasyRdf_Resource primaryTopic ([ $resource = null])
array properties ( $resource)
array propertyUris ( $resource)
object The resolveResource (string $baseUri, string $referenceUri, [mixed $types = array()])
object EasyRdf_Resource resource ([string $uri = null], [mixed $types = array()])
array resources ()
array resourcesMatching (string $property, mixed $value)
array reversePropertyUris ( $resource)
mixed serialise (string $format)
array set ( $resource, string $property, $value, mixed $values)
void setType (string $resource, string $type)
array toArray ()
string type ([ $resource = null])
object EasyRdf_Resource typeAsResource ([ $resource = null])
array types ([ $resource = null])
string __toString ()
Methods
Constructor __construct (line 78)

Constructor

If no URI is given then an empty graph is created.

If a URI is supplied, but no data then the data will be fetched from the URI.

The document type is optional and can be specified if it can't be guessed or got from the HTTP headers.

- access: public

object EasyRdf_Graph __construct ([string $uri = null], [string $data = null], [string $format = null])

- string $uri: The URI of the graph
- string $data: Data for the graph
- string $format: The document type of the data

add (line 656)

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');

- access: public

void add (mixed $resource, mixed $property, mixed $value)

- mixed $resource: The resource to add data to
- mixed $property: The property name
- mixed $value: The new value for the property

addLiteral (line 699)

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');

- access: public

void addLiteral (mixed $resource, mixed $property, mixed $value, [string $lang = null])

- mixed $resource: The resource to add data to
- mixed $property: The property name
- mixed $value: The value or values for the property
- string $lang: The language of the literal

addResource (line 741)

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');

- access: public

void addResource (mixed $resource, mixed $property, mixed $resource2)

- mixed $resource: The resource to add data to
- mixed $property: The property name
- mixed $resource2: The resource to be value of the property

addType (line 1100)

Add one or more rdf:type properties to a resource

- access: public

void addType (string $resource, $types, string $type)

- string $resource: The resource to add the type to
- string $type: The new type (e.g. foaf:Person)
- $types

all (line 557)

Get all values for a property of a resource

This method will return an empty array if the property does not exist.

- return: An array of values associated with the property
- access: public

array all (string $resource, string $property, [string $type = null], [string $lang = null])

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string $property: The name of the property (e.g. foaf:name)
- string $type: The type of value to filter by (e.g. literal)
- string $lang: The language to filter by (e.g. en)

allLiterals (line 598)

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.

- return: An array of values associated with the property
- access: public

array allLiterals (string $resource, string $property, [string $lang = null])

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string $property: The name of the property (e.g. foaf:name)
- string $lang: The language to filter by (e.g. en)

allOfType (line 625)

Get all the resources in the graph of a certain type

If no resources of the type are available and empty array is returned.

- return: The array of resources
- access: public

array allOfType (string $type)

- string $type: The type of the resource (e.g. foaf:Person)

allResources (line 612)

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.

- return: An array of values associated with the property
- access: public

array allResources (string $resource, string $property)

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string $property: The name of the property (e.g. foaf:name)

countTriples (line 1184)

Calculates the number of triples in the graph

- return: The number of triples in the graph.
- access: public

integer countTriples ()
delete (line 785)

Delete a property (or optionally just a specific value)

- access: public

null delete ( $resource, string $property, [object $value = null])

- string $property: The name of the property (e.g. foaf:name)
- object $value: The value to delete (null to delete all values)
- $resource

dump (line 937)

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.

- access: public

string dump ([bool $html = true])

- bool $html: Set to true to format the dump using HTML

dumpResource (line 962)

Return a human readable view of the resource and its properties

This method is intended to be a debugging aid and will print a resource and its properties.

- access: public

string dumpResource ( $resource, [bool $html = true])

- bool $html: Set to true to format the dump using HTML
- $resource

get (line 432)

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.

- return: A value associated with the property
- access: public

mixed get (string $resource, string|array $property, [string $type = null], [string $lang = null])

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string|array $property: The name of the property (e.g. foaf:name)
- string $type: The type of value to filter by (e.g. literal or resource)
- string $lang: The language to filter by (e.g. en)

getLiteral (line 487)

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.

- return: Literal value associated with the property
- access: public

object EasyRdf_Literal getLiteral (string $resource, string|array $property, [string $lang = null])

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string|array $property: The name of the property (e.g. foaf:name)
- string $lang: The language to filter by (e.g. en)

getResource (line 504)

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.

- return: Resource associated with the property
- access: public

object EasyRdf_Resource getResource (string $resource, string|array $property)

- string $resource: The URI of the resource (e.g. http://example.com/joe#me)
- string|array $property: The name of the property (e.g. foaf:name)

getUri (line 318)

Get the URI of the graph

- return: The URI of the graph
- access: public

string getUri ()
hasProperty (line 900)

Check to see if a property exists for a resource.

This method will return true if the property exists.

- return: True if value the property exists.
- access: public

bool hasProperty ( $resource, string $property)

- string $property: The name of the property (e.g. foaf:gender)
- $resource

isEmpty (line 835)

Check if the graph contains any statements

- return: True if the graph contains no statements
- access: public

boolean isEmpty ()
is_a (line 1082)

Check if a resource is of the specified type

- return: True if resource is of specified type.
- access: public

boolean is_a ( $resource, string $type)

- string $type: The type to check (e.g. foaf:Person)
- $resource

join (line 640)

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.

- return: Concatenation of all the values.
- access: public

string join ( $resource, string $property, [string $glue = ' '], [string $lang = null])

- string $property: The name of the property (e.g. foaf:name)
- string $glue: The string to glue the values together with.
- string $lang: The language to filter by (e.g. en)
- $resource

label (line 1138)

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.

- return: A label for the resource.
- access: public

string label ([ $resource = null], [ $lang = null])

- $resource
- $lang

load (line 233)

Load RDF data into the graph.

If a URI is supplied, but no data then the data will be fetched from the URI.

The document type is optional and can be specified if it can't be guessed or got from the HTTP headers.

- access: public

void load ([string $uri = null], [string $data = null], [string $format = null])

- string $uri: The URI of the data to load
- string $data: Optional data for the graph
- string $format: Optional format of the data

newBNode (line 178)

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.

- return: The new blank node
- access: public

object EasyRdf_Resource newBNode ([mixed $types = array()])

- mixed $types: RDF type of a new blank node (e.g. foaf:Person)

newBNodeId (line 188)

Create a new unique blank node identifier and return it.

- return: The new blank node identifier (e.g. _:genid1)
- access: public

string newBNodeId ()
parse (line 200)

Parse some RDF data into the graph object.

- access: public

void parse (string $data, [string $format = null], [string $uri = null])

- string $data: Data to parse for the graph
- string $format: Optional format of the data
- string $uri: The URI of the data to load

primaryTopic (line 1158)

Get the primary topic of the graph

- return: The primary topic of the document.
- access: public

EasyRdf_Resource primaryTopic ([ $resource = null])

- $resource

properties (line 846)

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.

- return: Array of shortened URIs
- access: public

array properties ( $resource)

- $resource

propertyUris (line 867)

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.

- return: Array of full URIs
- access: public

array propertyUris ( $resource)

- $resource

resolveResource (line 162)

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.

- return: newly resolved URI as an EasyRdf_Resource
- access: public

object The resolveResource (string $baseUri, string $referenceUri, [mixed $types = array()])

- string $baseUri: The base URI
- string $referenceUri: The URI to resolve
- mixed $types: RDF type of a new resource (e.g. foaf:Person)

resource (line 102)

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.

- access: public

object EasyRdf_Resource resource ([string $uri = null], [mixed $types = array()])

- string $uri: The URI of the resource
- mixed $types: RDF type of a new resource (e.g. foaf:Person)

resources (line 272)

Get an associative array of all the resources stored in the graph.

The keys of the array is the URI of the EasyRdf_Resource.

- return: Array of EasyRdf_Resource
- access: public

array resources ()
resourcesMatching (line 297)

Get an arry of resources matching a certain property and value.

For example this routine could be used as a way of getting everyone who is male: $people = $graph->resourcesMatching('foaf:gender', 'male');

- return: Array of EasyRdf_Resource
- access: public

array resourcesMatching (string $property, mixed $value)

- string $property: The property to check.
- mixed $value: The value of the propery to check for.

reversePropertyUris (line 882)

Get a list of the full URIs for the properties that point to a resource.

- return: Array of full property URIs
- access: public

array reversePropertyUris ( $resource)

- $resource

serialise (line 921)

Serialise the graph into RDF

- return: The serialised graph
- access: public

mixed serialise (string $format)

- string $format: The format to serialise to

set (line 766)

Set value(s) for a property

The new value(s) will replace the existing values for the property. The name of the property should be a string. If you set a property to null or an empty array, then the property will be deleted.

- return: Array of new values for this property.
- access: public

array set ( $resource, string $property, $value, mixed $values)

- string $property: The name of the property (e.g. foaf:name)
- mixed $values: The value(s) for the property.
- $resource
- $value

setType (line 1121)

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.

- access: public

void setType (string $resource, string $type)

- string $resource: The resource to change the type of
- string $type: The new type (e.g. foaf:Person)

toArray (line 1175)

Returns the graph as a RDF/PHP associative array

- return: The contents of the graph as an array.
- access: public

array toArray ()
type (line 1022)

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.

- return: A type assocated with the resource (e.g. foaf:Document)
- access: public

string type ([ $resource = null])

- $resource

typeAsResource (line 1043)

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.

- return: A type assocated with the resource
- access: public

object EasyRdf_Resource typeAsResource ([ $resource = null])

- $resource

types (line 1063)

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.

- return: All types assocated with the resource (e.g. foaf:Person)
- access: public

array types ([ $resource = null])

- $resource

__toString (line 1199)

Magic method to return URI of resource when casted to string

- return: The URI of the resource
- access: public

string __toString ()

Documentation generated on Wed, 20 Jul 2011 19:54:03 +0100 by phpDocumentor 1.4.3