Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
networkx_query
project code.
networkx-query.
Evaluator = Callable[[Any], bool]
module-attribute
Predicate function.
ParserException
Bases: RuntimeError
Define a parser exception with stack of expression.
Source code in networkx_query/definition.py
133 134 135 136 137 138 |
|
PathCriteria
Bases: NamedTuple
Defines path criteria.
Note
With target={}, egde=...
you could wrote a criteria based on egde constraint only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Dict
|
target node query constraint.
|
required |
edge
|
Dict
|
optional edge query constraint |
required |
Source code in networkx_query/relationship.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
prepare_query(query)
Transform expression query as a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Dict
|
expression query as dictionary |
required |
Returns:
Type | Description |
---|---|
Evaluator
|
evaluator function |
Raises:
Type | Description |
---|---|
ParserException
|
if a parse error occurs |
Source code in networkx_query/parser.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
search_direct_relationships(graph, source=None, edge=None, target=None)
Search direct relation ship.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
graph instance |
required |
source
|
Optional[Dict]
|
optional source node query constraint |
None
|
edge
|
Optional[Dict]
|
optional edge query constraint |
None
|
target
|
Optional[Dict]
|
optional target node query constraint |
None
|
Returns:
Type | Description |
---|---|
Iterable[Tuple]
|
itrable tuple of edge |
Source code in networkx_query/relationship.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
search_edges(graph, query)
Search edges in specified graph which match query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
networkx graph instance |
required |
query
|
Dict
|
query expression |
required |
Returns:
Type | Description |
---|---|
Iterable[Tuple]
|
results as an iterable of edge identifier (tuple). |
Raises:
Type | Description |
---|---|
ParserException
|
if a parse error occurs |
Source code in networkx_query/query.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
search_nodes(graph, query)
Search nodes in specified graph which match query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
networkx graph instance |
required |
query
|
Dict
|
query expression |
required |
Returns:
Type | Description |
---|---|
Iterable[Any]
|
results as an iterable of node identifier. |
Raises:
Type | Description |
---|---|
ParserException
|
if a parse error occurs |
Source code in networkx_query/query.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
search_relationships(graph, source, *nodes)
Search all valid path according specified template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
graph instance |
required |
source
|
Dict
|
source node query constraint |
required |
nodes
|
PathCriteria
|
ordered list of path criteria |
()
|
Returns:
Type | Description |
---|---|
Iterable[Tuple]
|
all path which validate specification |
Raises:
Type | Description |
---|---|
RuntimeError
|
if a path criteria have no constraint |
Source code in networkx_query/relationship.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|