Documentation

Graph
in package
implements GraphInterface, JsonLdSerializable

A Graph represents a JSON-LD graph.

Tags
author

Markus Lanthaler mail@markus-lanthaler.com

Table of Contents

Interfaces

GraphInterface
JSON-LD graph interface
JsonLdSerializable
The JsonLdSerializable interface

Properties

$nodes  : array<string|int, mixed>
$termMap  : array<string|int, mixed>
A term map containing terms/prefixes mapped to IRIs. This is similar to a JSON-LD context but ignores all definitions except the IRI.
$blankNodeCounter  : int
$document  : DocumentInterface

Methods

__construct()  : mixed
Constructor
containsNode()  : bool
Check whether the document already contains a node with the specified ID
createNode()  : Node
Creates a new node which is linked to this document
getDocument()  : null|DocumentInterface
Get the document the node belongs to
getNode()  : Node|null
Get a node by ID
getNodes()  : array<string|int, Node>
Get all nodes
getNodesByType()  : array<string|int, Node>
Get nodes by type
merge()  : self
Merges the specified graph into the current graph
removeFromDocument()  : self
Removes the graph from the document
removeNode()  : self
Removes a node from the document
toJsonLd()  : mixed
Convert to expanded and flattened JSON-LD
createBlankNodeId()  : string
Create a new blank node identifier unique to the document.
resolveIri()  : IRI
Resolves an IRI against the document's IRI

Properties

$nodes

protected array<string|int, mixed> $nodes = array()

An associative array holding all nodes in the graph

$termMap

A term map containing terms/prefixes mapped to IRIs. This is similar to a JSON-LD context but ignores all definitions except the IRI.

protected array<string|int, mixed> $termMap = array()

$blankNodeCounter

private int $blankNodeCounter = 0

Blank node counter

Methods

containsNode()

Check whether the document already contains a node with the specified ID

public containsNode(mixed $id) : bool
Parameters
$id : mixed

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 values
bool

Returns true if the document contains a node with the specified ID; false otherwise.

createNode()

Creates a new node which is linked to this document

public createNode([mixed $id = null ][, mixed $preserveBnodeId = false ]) : Node
Parameters
$id : mixed = null

The ID of the node.

$preserveBnodeId : mixed = false

If set to false, blank nodes are relabeled to avoid collisions; otherwise the blank node identifier is preserved.

Return values
Node

The newly created node.

getDocument()

Get the document the node belongs to

public getDocument() : null|DocumentInterface
Return values
null|DocumentInterface

Returns the document the node belongs to or null if the node doesn't belong to any document.

getNode()

Get a node by ID

public getNode(mixed $id) : Node|null
Parameters
$id : mixed

The ID of the node to retrieve.

Return values
Node|null

Returns the node if found; null otherwise.

getNodes()

Get all nodes

public getNodes() : array<string|int, Node>
Return values
array<string|int, Node>

Returns an array containing all nodes defined in the document.

getNodesByType()

Get nodes by type

public getNodesByType(mixed $type) : array<string|int, Node>
Parameters
$type : mixed

The type

Return values
array<string|int, Node>

Returns an array containing all nodes of the specified type in the document.

merge()

Merges the specified graph into the current graph

public merge(GraphInterface $graph) : self
Parameters
$graph : GraphInterface

The graph that should be merged into the current graph.

Return values
self

removeFromDocument()

Removes the graph from the document

public removeFromDocument() : self
Return values
self

removeNode()

Removes a node from the document

public removeNode(NodeInterface $node) : self
Parameters
$node : NodeInterface

The node to remove from the document.

Return values
self

toJsonLd()

Convert to expanded and flattened JSON-LD

public toJsonLd([mixed $useNativeTypes = true ]) : mixed
Parameters
$useNativeTypes : mixed = true

If set to true, native types are used for xsd:integer, xsd:double, and xsd:boolean, otherwise typed strings will be used instead.

Return values
mixed

Returns data which can be serialized by JsonLD::toString() (which is a value of any type other than a resource) to expanded JSON-LD.

createBlankNodeId()

Create a new blank node identifier unique to the document.

protected createBlankNodeId() : string
Return values
string

The new blank node identifier.

resolveIri()

Resolves an IRI against the document's IRI

protected resolveIri(string|IRI $iri) : IRI

If the graph isn't attached to a document or the document's IRI is not set, the IRI is returned as-is.

Parameters
$iri : string|IRI

The (relative) IRI to resolve

Return values
IRI

The resolved IRI.


        
On this page

Search results