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).
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
Number of edges in the graph
Number of nodes in the graph
Number of edges in the graph
Create graph index
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.
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.
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:
DateTime of earliest activity in the graph
Timestamp of earliest activity in the graph
Gets all edges in the graph
Gets the latest time that this GraphView is valid.
Gets the latest datetime that this GraphView is valid
DateTime of latest activity in the graph
Timestamp of latest activity in the graph
Gets the nodes in the graph
Get all graph properties
Gets the start time for rolling and expanding windows for this GraphView
Gets the earliest datetime that this GraphView is valid
Return all the layer ids in the graph
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).
- 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
- Returns:
Returns the masked graph
- Return type:
- count_edges()#
Number of edges in the graph
- Returns:
the number of edges in the graph
- Return type:
- count_nodes()#
Number of nodes in the graph
- Returns:
the number of nodes in the graph
- Return type:
- count_temporal_edges()#
Number of edges in the graph
- Returns:
the number of temporal edges in the graph
- Return type:
- 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
- earliest_time#
Timestamp of earliest activity in the graph
- edge(src, dst)#
Gets the edge with the specified source and destination nodes
- end#
Gets the latest time that this GraphView is valid.
- end_date_time#
Gets the latest datetime that this GraphView is valid
- 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
- Returns:
The layered view
- Return type:
- 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:
- 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.
- 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:
- 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:
- 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:
- 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.
- Return type:
- latest_date_time#
DateTime of latest activity in the graph
- latest_time#
Timestamp of latest activity in the graph
- 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
- Returns:
Returns a graph clone
- Return type:
- node(id)#
Gets the node with the specified id
- properties#
Get all graph properties
- Returns:
Properties paired with their names
- Return type:
- 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.
- search_edges(filter, limit=25, offset=0)#
Searches for edges which match the given filter expression. This uses Tantivy’s exact search.
- Parameters:
- Returns:
A list of edges which match the filter expression. The list will be empty if no edges match the query.
- Return type:
- search_nodes(filter, limit=25, offset=0)#
Searches for nodes which match the given filter expression. This uses Tantivy’s exact search.
- Parameters:
- Returns:
A list of nodes which match the filter expression. The list will be empty if no nodes match.
- Return type:
- 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.
This is equivalent to before(time + 1) for Graph and at(time) for PersistentGraph
- 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:
- 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
- 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=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:
- 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:
- unique_layers#
Return all the layer ids in the graph
- valid_layers(names)#
Return a view of GraphView containing all layers names Any layers that do not exist are ignored
- 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:
- window(start, end)#
Create a view of the GraphView including all events between start (inclusive) and end (exclusive)