GraphView#

class GraphView#

Bases: object

Graph view is a read-only version of a graph at a certain point in time.

Methods:

after(start)

Create a view of the GraphView including all events after start (exclusive).

at(time)

Create a view of the GraphView including all events at time.

before(end)

Create a view of the GraphView including all events before end (exclusive).

cache_view()

Applies the filters to the graph and retains the node ids and the edge ids in the graph that satisfy the filters creates bitsets per layer for nodes and edges

count_edges()

Number of edges in the graph

count_nodes()

Number of nodes in the graph

count_temporal_edges()

Number of edges in the graph

create_index()

Create graph index

default_layer()

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

edge(src, dst)

Gets the edge with the specified source and destination nodes

exclude_layer(name)

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

exclude_layers(names)

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

exclude_nodes(nodes)

Returns a subgraph given a set of nodes that are excluded from the subgraph

exclude_valid_layer(name)

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

exclude_valid_layers(names)

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

expanding(step)

Creates a WindowSet with the given step size using an expanding window.

filter_edges(filter)

Return a filtered view that only includes edges that satisfy the filter

filter_exploded_edges(filter)

Return a filtered view that only includes exploded edges that satisfy the filter

filter_nodes(filter)

Return a filtered view that only includes nodes that satisfy the filter

find_edges(properties_dict)

Get the edges that match the properties name and value :param properties_dict: the properties name and value :type properties_dict: dict[str, Prop]

find_nodes(properties_dict)

Get the nodes that match the properties name and value :param properties_dict: the properties name and value :type properties_dict: dict[str, Prop]

has_edge(src, dst)

Returns true if the graph contains the specified edge

has_layer(name)

Check if GraphView has the layer "name"

has_node(id)

Returns true if the graph contains the specified node

latest()

Create a view of the GraphView including all events at the latest time.

layer(name)

Return a view of GraphView containing the layer "name" Errors if the layer does not exist

layers(names)

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

materialize()

Returns a 'materialized' clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph.

node(id)

Gets the node with the specified id

rolling(window[, step])

Creates a WindowSet with the given window size and optional step using a rolling window.

search_edges(filter[, limit, offset])

Searches for edges which match the given filter expression.

search_nodes(filter[, limit, offset])

Searches for nodes which match the given filter expression.

shrink_end(end)

Set the end of the window to the smaller of end and self.end()

shrink_start(start)

Set the start of the window to the larger of start and self.start()

shrink_window(start, end)

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

snapshot_at(time)

Create a view of the GraphView including all events that have not been explicitly deleted at time.

snapshot_latest()

Create a view of the GraphView including all events that have not been explicitly deleted at the latest time.

subgraph(nodes)

Returns a subgraph given a set of nodes

subgraph_node_types(node_types)

Returns a subgraph filtered by node types given a set of node types

to_networkx([explode_edges, ...])

Returns a graph with NetworkX.

to_pyvis([explode_edges, edge_color, shape, ...])

Draw a graph with PyVis.

valid_layers(names)

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

vectorise(embedding[, cache, ...])

Create a VectorisedGraph from the current graph

window(start, end)

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Attributes:

earliest_date_time

DateTime of earliest activity in the graph

earliest_time

Timestamp of earliest activity in the graph

edges

Gets all edges in the graph

end

Gets the latest time that this GraphView is valid.

end_date_time

Gets the latest datetime that this GraphView is valid

latest_date_time

DateTime of latest activity in the graph

latest_time

Timestamp of latest activity in the graph

nodes

Gets the nodes in the graph

properties

Get all graph properties

start

Gets the start time for rolling and expanding windows for this GraphView

start_date_time

Gets the earliest datetime that this GraphView is valid

unique_layers

Return all the layer ids in the graph

window_size

Get the window size (difference between start and end) for this GraphView

after(start)#

Create a view of the GraphView including all events after start (exclusive).

Parameters:

start (TimeInput) – The start time of the window.

Return type:

GraphView

at(time)#

Create a view of the GraphView including all events at time.

Parameters:

time (TimeInput) – The time of the window.

Return type:

GraphView

before(end)#

Create a view of the GraphView including all events before end (exclusive).

Parameters:

end (TimeInput) – The end time of the window.

Return type:

GraphView

cache_view()#

Applies the filters to the graph and retains the node ids and the edge ids in the graph that satisfy the filters creates bitsets per layer for nodes and edges

Returns:

Returns the masked graph

Return type:

GraphView

count_edges()#

Number of edges in the graph

Returns:

the number of edges in the graph

Return type:

int

count_nodes()#

Number of nodes in the graph

Returns:

the number of nodes in the graph

Return type:

int

count_temporal_edges()#

Number of edges in the graph

Returns:

the number of temporal edges in the graph

Return type:

int

create_index()#

Create graph index

default_layer()#

Return a view of GraphView containing only the default edge layer :returns: The layered view :rtype: GraphView

earliest_date_time#

DateTime of earliest activity in the graph

Returns:

the datetime of the earliest activity in the graph

Return type:

Optional[datetime]

earliest_time#

Timestamp of earliest activity in the graph

Returns:

the timestamp of the earliest activity in the graph

Return type:

Optional[int]

edge(src, dst)#

Gets the edge with the specified source and destination nodes

Parameters:
Returns:

the edge with the specified source and destination nodes, or None if the edge does not exist

Return type:

Optional[Edge]

edges#

Gets all edges in the graph

Returns:

the edges in the graph

Return type:

Edges

end#

Gets the latest time that this GraphView is valid.

Returns:

The latest time that this GraphView is valid or None if the GraphView is valid for all times.

Return type:

Optional[int]

end_date_time#

Gets the latest datetime that this GraphView is valid

Returns:

The latest datetime that this GraphView is valid or None if the GraphView is valid for all times.

Return type:

Optional[datetime]

exclude_layer(name)#

Return a view of GraphView containing all layers except the excluded name Errors if any of the layers do not exist.

Parameters:

name (str) – layer name that is excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_layers(names)#

Return a view of GraphView containing all layers except the excluded names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names that are excluded for the new view

Returns:

The layered view

Return type:

GraphView

exclude_nodes(nodes)#

Returns a subgraph given a set of nodes that are excluded from the subgraph

Parameters:

nodes (list[NodeInput]) – set of nodes

Returns:

Returns the subgraph

Return type:

GraphView

exclude_valid_layer(name)#

Return a view of GraphView containing all layers except the excluded name :param name: layer name that is excluded for the new view :type name: str

Returns:

The layered view

Return type:

GraphView

exclude_valid_layers(names)#

Return a view of GraphView containing all layers except the excluded names :param names: list of layer names that are excluded for the new view :type names: list[str]

Returns:

The layered view

Return type:

GraphView

expanding(step)#

Creates a WindowSet with the given step size using an expanding window.

An expanding window is a window that grows by step size at each iteration.

Parameters:

step (int | str) – The step size of the window.

Returns:

A WindowSet object.

Return type:

WindowSet

filter_edges(filter)#

Return a filtered view that only includes edges that satisfy the filter

Parameters:

filter (PropertyFilter) – The filter to apply to the edge properties. Construct a filter using Prop.

Returns:

The filtered view

Return type:

GraphView

filter_exploded_edges(filter)#

Return a filtered view that only includes exploded edges that satisfy the filter

Parameters:

filter (PropertyFilter) – The filter to apply to the exploded edge properties. Construct a filter using Prop.

Returns:

The filtered view

Return type:

GraphView

filter_nodes(filter)#

Return a filtered view that only includes nodes that satisfy the filter

Parameters:

filter (PropertyFilter) – The filter to apply to the node properties. Construct a filter using Prop.

Returns:

The filtered view

Return type:

GraphView

find_edges(properties_dict)#

Get the edges that match the properties name and value :param properties_dict: the properties name and value :type properties_dict: dict[str, Prop]

Returns:

the edges that match the properties name and value

Return type:

list[Edge]

find_nodes(properties_dict)#

Get the nodes that match the properties name and value :param properties_dict: the properties name and value :type properties_dict: dict[str, Prop]

Returns:

the nodes that match the properties name and value

Return type:

list[Node]

has_edge(src, dst)#

Returns true if the graph contains the specified edge

Parameters:
Returns:

true if the graph contains the specified edge, false otherwise

Return type:

bool

has_layer(name)#

Check if GraphView has the layer “name”

Parameters:

name (str) – the name of the layer to check

Return type:

bool

has_node(id)#

Returns true if the graph contains the specified node

Parameters:

id (NodeInput) – the node id

Returns:

true if the graph contains the specified node, false otherwise

Return type:

bool

latest()#

Create a view of the GraphView including all events at the latest time.

Return type:

GraphView

latest_date_time#

DateTime of latest activity in the graph

Returns:

the datetime of the latest activity in the graph

Return type:

Optional[datetime]

latest_time#

Timestamp of latest activity in the graph

Returns:

the timestamp of the latest activity in the graph

Return type:

Optional[int]

layer(name)#

Return a view of GraphView containing the layer “name” Errors if the layer does not exist

Parameters:

name (str) – then name of the layer.

Returns:

The layered view

Return type:

GraphView

layers(names)#

Return a view of GraphView containing all layers names Errors if any of the layers do not exist.

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

materialize()#

Returns a ‘materialized’ clone of the graph view - i.e. a new graph with a copy of the data seen within the view instead of just a mask over the original graph

Returns:

Returns a graph clone

Return type:

GraphView

node(id)#

Gets the node with the specified id

Parameters:

id (NodeInput) – the node id

Returns:

the node with the specified id, or None if the node does not exist

Return type:

Optional[Node]

nodes#

Gets the nodes in the graph

Returns:

the nodes in the graph

Return type:

Nodes

properties#

Get all graph properties

Returns:

Properties paired with their names

Return type:

Properties

rolling(window, step=None)#

Creates a WindowSet with the given window size and optional step using a rolling window.

A rolling window is a window that moves forward by step size at each iteration.

Parameters:
  • window (int | str) – The size of the window.

  • step (int | str | None) – The step size of the window. step defaults to window.

Returns:

A WindowSet object.

Return type:

WindowSet

search_edges(filter, limit=25, offset=0)#

Searches for edges which match the given filter expression. This uses Tantivy’s exact search.

Parameters:
  • filter – The filter expression to search for.

  • limit (int) – The maximum number of results to return. Defaults to 25.

  • offset (int) – The number of results to skip. This is useful for pagination. Defaults to 0.

Returns:

A list of edges which match the filter expression. The list will be empty if no edges match the query.

Return type:

list[Edge]

search_nodes(filter, limit=25, offset=0)#

Searches for nodes which match the given filter expression. This uses Tantivy’s exact search.

Parameters:
  • filter – The filter expression to search for.

  • limit (int) – The maximum number of results to return. Defaults to 25.

  • offset (int) – The number of results to skip. This is useful for pagination. Defaults to 0.

Returns:

A list of nodes which match the filter expression. The list will be empty if no nodes match.

Return type:

list[Node]

shrink_end(end)#

Set the end of the window to the smaller of end and self.end()

Parameters:

end (TimeInput) – the new end time of the window

Return type:

GraphView

shrink_start(start)#

Set the start of the window to the larger of start and self.start()

Parameters:

start (TimeInput) – the new start time of the window

Return type:

GraphView

shrink_window(start, end)#

Shrink both the start and end of the window (same as calling shrink_start followed by shrink_end but more efficient)

Parameters:
  • start (TimeInput) – the new start time for the window

  • end (TimeInput) – the new end time for the window

Return type:

GraphView

snapshot_at(time)#

Create a view of the GraphView including all events that have not been explicitly deleted at time.

This is equivalent to before(time + 1) for Graph and at(time) for PersistentGraph

Parameters:

time (TimeInput) – The time of the window.

Return type:

GraphView

snapshot_latest()#

Create a view of the GraphView including all events that have not been explicitly deleted at the latest time.

This is equivalent to a no-op for Graph and latest() for PersistentGraph

Return type:

GraphView

start#

Gets the start time for rolling and expanding windows for this GraphView

Returns:

The earliest time that this GraphView is valid or None if the GraphView is valid for all times.

Return type:

Optional[int]

start_date_time#

Gets the earliest datetime that this GraphView is valid

Returns:

The earliest datetime that this GraphView is valid or None if the GraphView is valid for all times.

Return type:

Optional[datetime]

subgraph(nodes)#

Returns a subgraph given a set of nodes

Parameters:

nodes (list[NodeInput]) – set of nodes

Returns:

Returns the subgraph

Return type:

GraphView

subgraph_node_types(node_types)#

Returns a subgraph filtered by node types given a set of node types

Parameters:

node_types (list[str]) – set of node types

Returns:

Returns the subgraph

Return type:

GraphView

to_networkx(explode_edges=False, include_node_properties=True, include_edge_properties=True, include_update_history=True, include_property_history=True)#

Returns a graph with NetworkX.

Network X is a required dependency. If you intend to use this function make sure that you install Network X with pip install networkx

Parameters:
  • explode_edges (bool) – A boolean that is set to True if you want to explode the edges in the graph. Defaults to False.

  • include_node_properties (bool) – A boolean that is set to True if you want to include the node properties in the graph. Defaults to True.

  • include_edge_properties (bool) – A boolean that is set to True if you want to include the edge properties in the graph. Defaults to True.

  • include_update_history (bool) – A boolean that is set to True if you want to include the update histories in the graph. Defaults to True.

  • include_property_history (bool) – A boolean that is set to True if you want to include the histories in the graph. Defaults to True.

Returns:

A Networkx MultiDiGraph.

Return type:

nx.MultiDiGraph

to_pyvis(explode_edges=False, edge_color='#000000', shape='dot', node_image=None, edge_weight=None, edge_label=None, colour_nodes_by_type=False, directed=True, notebook=False, **kwargs)#

Draw a graph with PyVis. Pyvis is a required dependency. If you intend to use this function make sure that you install Pyvis with pip install pyvis

Parameters:
  • explode_edges (bool) – A boolean that is set to True if you want to explode the edges in the graph. Defaults to False.

  • edge_color (str) – A string defining the colour of the edges in the graph. Defaults to “#000000”.

  • shape (str) – A string defining what the node looks like. Defaults to “dot”. There are two types of nodes. One type has the label inside of it and the other type has the label underneath it. The types with the label inside of it are: ellipse, circle, database, box, text. The ones with the label outside of it are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon.

  • node_image (str, optional) – An optional node property used as the url of a custom node image. Use together with shape=”image”.

  • edge_weight (str, optional) – An optional string defining the name of the property where edge weight is set on your Raphtory graph. If provided, the default weight for edges that are missing the property is 1.0.

  • edge_label (str, optional) – An optional string defining the name of the property where edge label is set on your Raphtory graph. By default, the edge layer is used as the label.

  • colour_nodes_by_type (bool) – If True, nodes with different types have different colours. Defaults to False.

  • directed (bool) – Visualise the graph as directed. Defaults to True.

  • notebook (bool) – A boolean that is set to True if using jupyter notebook. Defaults to False.

  • kwargs – Additional keyword arguments that are passed to the pyvis Network class.

Returns:

A pyvis network

Return type:

pyvis.network.Network

unique_layers#

Return all the layer ids in the graph

Returns:

the names of all layers in the graph

Return type:

list[str]

valid_layers(names)#

Return a view of GraphView containing all layers names Any layers that do not exist are ignored

Parameters:

names (list[str]) – list of layer names for the new view

Returns:

The layered view

Return type:

GraphView

vectorise(embedding, cache=None, overwrite_cache=False, graph=..., nodes=..., edges=..., graph_name=None, verbose=False)#

Create a VectorisedGraph from the current graph

Parameters:
  • embedding (Callable[[list], list]) – the embedding function to translate documents to embeddings

  • cache (str, optional) – the file to be used as a cache to avoid calling the embedding function

  • overwrite_cache (bool) – whether or not to overwrite the cache if there are new embeddings. Defaults to False.

  • graph (bool | str) – if the graph has to be embedded or not or the custom template to use if a str is provided. Defaults to True.

  • nodes (bool | str) – if nodes have to be embedded or not or the custom template to use if a str is provided. Defaults to True.

  • edges (bool | str) – if edges have to be embedded or not or the custom template to use if a str is provided. Defaults to True.

  • graph_name (str, optional) – the name of the graph

  • verbose (bool) – whether or not to print logs reporting the progress. Defaults to False.

Returns:

A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection

Return type:

VectorisedGraph

window(start, end)#

Create a view of the GraphView including all events between start (inclusive) and end (exclusive)

Parameters:
  • start (TimeInput | None) – The start time of the window (unbounded if None).

  • end (TimeInput | None) – The end time of the window (unbounded if None).

Return type:

GraphView

window_size#

Get the window size (difference between start and end) for this GraphView

Return type:

Optional[int]