GraphView
#
Bases: object
Graph view is a read-only version of a graph at a certain point in time.
earliest_date_time
property
#
DateTime of earliest activity in the graph
Returns:
Type | Description |
---|---|
Optional[datetime]
|
the datetime of the earliest activity in the graph |
earliest_time
property
#
Timestamp of earliest activity in the graph
Returns:
Type | Description |
---|---|
Optional[int]
|
the timestamp of the earliest activity in the graph |
end
property
#
Gets the latest time that this GraphView is valid.
Returns:
Type | Description |
---|---|
Optional[int]
|
The latest time that this GraphView is valid or None if the GraphView is valid for all times. |
end_date_time
property
#
Gets the latest datetime that this GraphView is valid
Returns:
Type | Description |
---|---|
Optional[datetime]
|
The latest datetime that this GraphView is valid or None if the GraphView is valid for all times. |
latest_date_time
property
#
DateTime of latest activity in the graph
Returns:
Type | Description |
---|---|
Optional[datetime]
|
the datetime of the latest activity in the graph |
latest_time
property
#
Timestamp of latest activity in the graph
Returns:
Type | Description |
---|---|
Optional[int]
|
the timestamp of the latest activity in the graph |
properties
property
#
start
property
#
Gets the start time for rolling and expanding windows for this GraphView
Returns:
Type | Description |
---|---|
Optional[int]
|
The earliest time that this GraphView is valid or None if the GraphView is valid for all times. |
start_date_time
property
#
Gets the earliest datetime that this GraphView is valid
Returns:
Type | Description |
---|---|
Optional[datetime]
|
The earliest datetime that this GraphView is valid or None if the GraphView is valid for all times. |
unique_layers
property
#
window_size
property
#
Get the window size (difference between start and end) for this GraphView
Returns:
Type | Description |
---|---|
Optional[int]
|
|
__eq__(value)
#
Return self==value.
__ge__(value)
#
Return self>=value.
__gt__(value)
#
Return self>value.
__le__(value)
#
Return self<=value.
__lt__(value)
#
Return self<value.
__ne__(value)
#
Return self!=value.
__repr__()
#
Return repr(self).
after(start)
#
at(time)
#
before(end)
#
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:
Type | Description |
---|---|
GraphView
|
Returns the masked graph |
count_edges()
#
count_nodes()
#
count_temporal_edges()
#
Number of edges in the graph
Returns:
Type | Description |
---|---|
int
|
the number of temporal edges in the graph |
default_layer()
#
Return a view of GraphView containing only the default edge layer Returns: GraphView: The layered view
edge(src, dst)
#
Gets the edge with the specified source and destination nodes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src
|
NodeInput
|
the source node id |
required |
dst
|
NodeInput
|
the destination node id |
required |
Returns:
Type | Description |
---|---|
Optional[Edge]
|
the edge with the specified source and destination nodes, or None if the edge does not exist |
exclude_layer(name)
#
exclude_layers(names)
#
exclude_nodes(nodes)
#
exclude_valid_layer(name)
#
Return a view of GraphView containing all layers except the excluded name
Arguments:
name (str): layer name that is excluded for the new view
Returns:
Type | Description |
---|---|
GraphView
|
The layered view |
exclude_valid_layers(names)
#
Return a view of GraphView containing all layers except the excluded names
Arguments:
names (list[str]): list of layer names that are excluded for the new view
Returns:
Type | Description |
---|---|
GraphView
|
The layered view |
expanding(step)
#
filter_edges(filter)
#
Return a filtered view that only includes edges that satisfy the filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
FilterExpr
|
The filter to apply to the edges. |
required |
Returns:
Type | Description |
---|---|
GraphView
|
The filtered view |
filter_exploded_edges(filter)
#
Return a filtered view that only includes exploded edges that satisfy the filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
FilterExpr
|
The filter to apply to the exploded edge properties. |
required |
Returns:
Type | Description |
---|---|
GraphView
|
The filtered view |
filter_nodes(filter)
#
Return a filtered view that only includes nodes that satisfy the filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
FilterExpr
|
The filter to apply to the nodes. |
required |
Returns:
Type | Description |
---|---|
GraphView
|
The filtered view |
find_edges(properties_dict)
#
Get the edges that match the properties name and value Arguments: properties_dict (dict[str, PropValue]): the properties name and value Returns: list[Edge]: the edges that match the properties name and value
find_nodes(properties_dict)
#
Get the nodes that match the properties name and value Arguments: properties_dict (dict[str, PropValue]): the properties name and value Returns: list[Node]: the nodes that match the properties name and value
has_edge(src, dst)
#
has_layer(name)
#
has_node(id)
#
latest()
#
Create a view of the GraphView including all events at the latest time.
Returns:
Type | Description |
---|---|
GraphView
|
|
layer(name)
#
layers(names)
#
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:
Type | Description |
---|---|
GraphView
|
Returns a graph clone |
node(id)
#
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:
Name | Type | Description | Default |
---|---|---|---|
window
|
int | str
|
The size of the window. |
required |
step
|
int | str | None
|
The step size of the window.
|
None
|
Returns:
Type | Description |
---|---|
WindowSet
|
A |
search_edges(filter, limit=25, offset=0)
#
Searches for edges which match the given filter expression. This uses Tantivy's exact search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
Any
|
The filter expression to search for. |
required |
limit
|
int
|
The maximum number of results to return. Defaults to 25. |
25
|
offset
|
int
|
The number of results to skip. This is useful for pagination. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
list[Edge]
|
A list of edges which match the filter expression. The list will be empty if no edges match the query. |
search_nodes(filter, limit=25, offset=0)
#
Searches for nodes which match the given filter expression. This uses Tantivy's exact search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
Any
|
The filter expression to search for. |
required |
limit
|
int
|
The maximum number of results to return. Defaults to 25. |
25
|
offset
|
int
|
The number of results to skip. This is useful for pagination. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
list[Node]
|
A list of nodes which match the filter expression. The list will be empty if no nodes match. |
shrink_end(end)
#
Set the end of the window to the smaller of end
and self.end()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
end
|
TimeInput
|
the new end time of the window |
required |
Returns: GraphView:
shrink_start(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)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
TimeInput
|
the new start time for the window |
required |
end
|
TimeInput
|
the new end time for the window |
required |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
time
|
TimeInput
|
The time of the window. |
required |
Returns:
Type | Description |
---|---|
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
Returns:
Type | Description |
---|---|
GraphView
|
|
subgraph(nodes)
#
subgraph_node_types(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``
Args:
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:
nx.MultiDiGraph: A Networkx 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:
Name | Type | Description | Default |
---|---|---|---|
explode_edges
|
bool
|
A boolean that is set to True if you want to explode the edges in the graph. Defaults to False. |
False
|
edge_color
|
str
|
A string defining the colour of the edges in the graph. Defaults to "#000000". |
'#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. |
'dot'
|
node_image
|
str
|
An optional node property used as the url of a custom node image. Use together with |
None
|
edge_weight
|
str
|
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. |
None
|
edge_label
|
str
|
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. |
None
|
colour_nodes_by_type
|
bool
|
If True, nodes with different types have different colours. Defaults to False. |
False
|
directed
|
bool
|
Visualise the graph as directed. Defaults to True. |
True
|
notebook
|
bool
|
A boolean that is set to True if using jupyter notebook. Defaults to False. |
False
|
kwargs
|
Any
|
Additional keyword arguments that are passed to the pyvis Network class. |
{}
|
Returns:
Type | Description |
---|---|
Network
|
A pyvis network |
valid()
#
Return a view of the graph that only includes valid edges
Note:
The semantics for `valid` depend on the time semantics of the underlying graph.
In the case of a persistent graph, an edge is valid if its last update is an addition.
In the case of an event graph, an edge is valid if it has at least one addition event.
Returns:
Type | Description |
---|---|
GraphView
|
The filtered graph |
valid_layers(names)
#
vectorise(embedding, nodes=True, edges=True, cache=None, verbose=False)
#
Create a VectorisedGraph from the current graph
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
Callable[[list], list]
|
the embedding function to translate documents to embeddings |
required |
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. |
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. |
True
|
cache
|
str
|
the path to use to store the cache for embeddings. |
None
|
verbose
|
bool
|
whether or not to print logs reporting the progress. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
VectorisedGraph
|
A VectorisedGraph with all the documents/embeddings computed and with an initial empty selection |
window(start, end)
#
Create a view of the GraphView including all events between start
(inclusive) and end
(exclusive)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
TimeInput | None
|
The start time of the window (unbounded if |
required |
end
|
TimeInput | None
|
The end time of the window (unbounded if |
required |
Returns:
Type | Description |
---|---|
GraphView
|
|