Documentation

GraphInterface

JSON-LD graph interface

Tags
author

Markus Lanthaler mail@markus-lanthaler.com

Table of Contents

Methods

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

Methods

containsNode()

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

public containsNode(string|Node $id) : bool
Parameters
$id : string|Node

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([null|string $id = null ][, bool $preserveBnodeId = false ]) : Node

If a blank node identifier or an invalid ID is passed, the ID will be ignored and a new blank node identifier unique to the document is created for the node.

If there exists already a node with the passed ID in the document, that node will be returned instead of creating a new one.

Parameters
$id : null|string = null

The ID of the node.

$preserveBnodeId : bool = 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.

getNode()

Get a node by ID

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

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(string|Node $type) : array<string|int, Node>
Parameters
$type : string|Node

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

This will also eliminate all references to the node within the document.

Parameters
$node : NodeInterface

The node to remove from the document.

Return values
self

        
On this page

Search results