GFQL Chain¶
-
class
graphistry.compute.chain.Chain(chain)¶ Bases:
graphistry.compute.ASTSerializable.ASTSerializable- Parameters
chain (
List[ASTObject]) –
-
classmethod
from_json(d)¶ Convert a JSON AST into a list of ASTObjects
- Parameters
d (
Dict[str,Union[None,bool,str,float,int,List[Union[None,bool,str,float,int,List[ForwardRef],Dict[str,ForwardRef]]],Dict[str,Union[None,bool,str,float,int,List[ForwardRef],Dict[str,ForwardRef]]]]]) –- Return type
-
to_json(validate=True)¶ Convert a list of ASTObjects into a JSON AST
- Return type
Dict[str,Union[None,bool,str,float,int,List[Union[None,bool,str,float,int,List[ForwardRef],Dict[str,ForwardRef]]],Dict[str,Union[None,bool,str,float,int,List[ForwardRef],Dict[str,ForwardRef]]]]]
-
validate()¶ - Return type
None
-
graphistry.compute.chain.chain(self, ops, engine=<EngineAbstract.AUTO: 'auto'>)¶ Chain a list of ASTObject (node/edge) traversal operations
Return subgraph of matches according to the list of node & edge matchers If any matchers are named, add a correspondingly named boolean-valued column to the output
For direct calls, exposes convenience List[ASTObject]. Internal operational should prefer Chain.
Use engine=’cudf’ to force automatic GPU acceleration mode
- Parameters
ops (
Union[List[ASTObject],Chain]) – List[ASTObject] Various node and edge matchersself (graphistry.Plottable.Plottable) –
engine (Union[graphistry.Engine.EngineAbstract, str]) –
- Returns
Plotter
- Return type
Plotter
Example: Find nodes of some type
from graphistry.ast import n people_nodes_df = g.chain([ n({"type": "person"}) ])._nodes
Example: Find 2-hop edge sequences with some attribute
from graphistry.ast import e_forward g_2_hops = g.chain([ e_forward({"interesting": True}, hops=2) ]) g_2_hops.plot()
Example: Find any node 1-2 hops out from another node, and label each hop
from graphistry.ast import n, e_undirected g_2_hops = g.chain([ n({g._node: "a"}), e_undirected(name="hop1"), e_undirected(name="hop2") ]) print('# first-hop edges:', len(g_2_hops._edges[ g_2_hops._edges.hop1 == True ]))
Example: Transaction nodes between two kinds of risky nodes
from graphistry.ast import n, e_forward, e_reverse g_risky = g.chain([ n({"risk1": True}), e_forward(to_fixed=True), n({"type": "transaction"}, name="hit"), e_reverse(to_fixed=True), n({"risk2": True}) ]) print('# hits:', len(g_risky._nodes[ g_risky._nodes.hit ]))
Example: Filter by multiple node types at each step using is_in
from graphistry.ast import n, e_forward, e_reverse, is_in g_risky = g.chain([ n({"type": is_in(["person", "company"])}), e_forward({"e_type": is_in(["owns", "reviews"])}, to_fixed=True), n({"type": is_in(["transaction", "account"])}, name="hit"), e_reverse(to_fixed=True), n({"risk2": True}) ]) print('# hits:', len(g_risky._nodes[ g_risky._nodes.hit ]))
Example: Run with automatic GPU acceleration
import cudf import graphistry e_gdf = cudf.from_pandas(df) g1 = graphistry.edges(e_gdf, 's', 'd') g2 = g1.chain([ ... ])
Example: Run with automatic GPU acceleration, and force GPU mode
import cudf import graphistry e_gdf = cudf.from_pandas(df) g1 = graphistry.edges(e_gdf, 's', 'd') g2 = g1.chain([ ... ], engine='cudf')
- Parameters
self (
Plottable) –engine (
Union[EngineAbstract,str]) –ops (Union[List[graphistry.compute.ast.ASTObject], graphistry.compute.chain.Chain]) –
- Return type
graphistry.Plottable.Plottable
-
graphistry.compute.chain.combine_steps(g, kind, steps, engine)¶ Collect nodes and edges, taking care to deduplicate and tag any names
- Parameters
g (
Plottable) –kind (
str) –steps (
List[Tuple[ASTObject,Plottable]]) –engine (
Engine) –
- Return type
Any