GraphView
#
Bases: object
Graph view is a read-only version of a graph at a certain point in time.
earliest_time
property
#
Time entry of the earliest activity in the graph
Returns:
| Type | Description |
|---|---|
OptionalEventTime
|
the time entry of the earliest activity in the graph |
end
property
#
Gets the latest time that this GraphView is valid.
Returns:
| Type | Description |
|---|---|
OptionalEventTime
|
The latest time that this GraphView is valid or None if the GraphView is valid for all times. |
latest_time
property
#
Time entry of the latest activity in the graph
Returns:
| Type | Description |
|---|---|
OptionalEventTime
|
the time entry 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 |
|---|---|
OptionalEventTime
|
The earliest time 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, alignment_unit=None)
#
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:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int | str
|
The step size of the window. |
required |
alignment_unit
|
str | None
|
If no alignment_unit is passed, aligns the start of the first window to the smallest unit of time passed to step. For example, if the step is "1 month and 1 day", the windows will be aligned on days (00:00:00 to 23:59:59). If set to "unaligned", the first window will begin at the first time event. If any other alignment unit is passed, the windows will be aligned to that unit. alignment_unit defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
WindowSet
|
A |
filter(filter)
#
Return a filtered view that only includes nodes and edges that satisfy the filter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
FilterExpr
|
The filter to apply to the nodes and edges. |
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, alignment_unit=None)
#
Creates a WindowSet with the given window size and optional step using a rolling window.
If alignment_unit is not "unaligned" and a step larger than window is provided, some time entries
may appear before the start of the first window and/or after the end of the last window (i.e. not included in any 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
|
alignment_unit
|
str | None
|
If no alignment_unit is passed, aligns the start of the first window to the smallest unit of time passed to step (or window if no step is passed). For example, if the step is "1 month and 1 day", the first window will begin at the start of the day of the first time event. If set to "unaligned", the first window will begin at the first time event. If any other alignment unit is passed, the windows will be aligned to that unit. alignment_unit defaults to None. |
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(model, nodes=True, edges=True, verbose=False)
#
Create a VectorisedGraph from the current graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
|
Callable[[list], list]
|
Specify the embedding function used to vectorise documents into embeddings. |
required |
nodes
|
bool | str
|
Enable for nodes to be embedded, disable for nodes to not be embedded or specify a custom document property to use if a string is provided. Defaults to True. |
True
|
edges
|
bool | str
|
Enable for edges to be embedded, disable for edges to not be embedded or specify a custom document property to use if a string is provided. Defaults to True. |
True
|
cache
|
str
|
Path used to store the cache of embeddings. |
required |
verbose
|
bool
|
Enable to print logs reporting progress. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
VectorisedGraph
|
A VectorisedGraph with all the documents and their embeddings, with an initial empty selection. |