yawning_titan.networks.network_db.NetworkQuery#
- class yawning_titan.networks.network_db.NetworkQuery[source]#
Bases:
YawningTitanQuery
Methods
Check if a condition is met by all documents in a list, where a condition can also be a sequence (e.g.
Check if a condition is met by any document in a list, where a condition can also be a sequence (e.g.
Tests the value of a field.
Test for a dict where a provided key exists.
Tests the length of a field.
Tests the length of a field.
Tests the length of a field.
Tests the length of a field.
Tests the length of a field.
Tests the length of a field.
Add a function to the query path.
Run a regex test against a dict value (whole string has to match).
Always evaluate to
True
.Returns all Networks with n number of entry nodes.
Returns all Networks with between min and max number of entry nodes.
Returns all Networks with n number of high_value nodes.
Returns all Networks with between min and max number of high value nodes.
Returns all Networks with n number of nodes.
Returns all Networks with between min and max number of nodes.
Check if the value is contained in a list or generator.
Run a regex test against a dict value (only substring string has to match).
Run a user-defined test function against a dict value.
- static num_of_nodes(n)[source]#
Returns all Networks with n number of nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_nodes(18))
- Parameters:
n – The target number of nodes in a Network.
- Returns:
A list of Networks.
- static num_of_nodes_between(min, max)[source]#
Returns all Networks with between min and max number of nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_nodes(18))
- Parameters:
min – The minimum number of nodes in a Network.
max – The maximum number of nodes in a Network.
- Returns:
A list of Networks.
- static num_of_entry_nodes(n)[source]#
Returns all Networks with n number of entry nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_entry_nodes(3))
- Parameters:
n – The target number of entry nodes.
- Returns:
A List of Nodes.
- static num_of_entry_nodes_between(min, max)[source]#
Returns all Networks with between min and max number of entry nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_entry_nodes_between(3,6))
- Parameters:
n – The target number of entry nodes.
- Returns:
A List of Nodes.
- static num_of_high_value_nodes(n)[source]#
Returns all Networks with n number of high_value nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_high_value_nodes(3))
- Parameters:
min – The minimum number of high_value nodes.
max – The maximum number of high_value nodes.
- Returns:
A List of Nodes.
- static num_of_high_value_nodes_between(min, max)[source]#
Returns all Networks with between min and max number of high value nodes.
- Example:
>>> from yawning_titan.networks.network_db import NetworkDB, NetworkQuery >>> db = NetworkDB() >>> networks = db.search(NetworkQuery.num_of_high_value_nodes_between(3,6))
- Parameters:
min – The minimum number of high_value nodes.
max – The minimum number of high_value nodes.
- Returns:
A List of Nodes.
- __call__(value)#
Evaluate the query to check if it matches a specified value.
- Parameters:
value – The value to check.
- Returns:
Whether the value matches this query.
- all(cond)#
Check if a condition is met by all documents in a list, where a condition can also be a sequence (e.g. list).
>>> Query().f1.all(Query().f2 == 1)
Matches:
{'f1': [{'f2': 1}, {'f2': 1}]}
>>> Query().f1.all([1, 2, 3])
Matches:
{'f1': [1, 2, 3, 4, 5]}
- Parameters:
cond – Either a query that all documents have to match or a list which has to be contained in the tested document.
- any(cond)#
Check if a condition is met by any document in a list, where a condition can also be a sequence (e.g. list).
>>> Query().f1.any(Query().f2 == 1)
Matches:
{'f1': [{'f2': 1}, {'f2': 0}]}
>>> Query().f1.any([1, 2, 3])
Matches:
{'f1': [1, 2]} {'f1': [3, 4, 5]}
- Parameters:
cond – Either a query that at least one document has to match or a list of which at least one document has to be contained in the tested document.
- bt(i, j)#
Tests the value of a field. This could be the value of a string or an array field.
Fields whose value is greater than or equal to
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_bt(1,18)))
- Parameters:
i – The minimum value of a field as an int.
j – The maximum value of a field as an int.
- Returns:
True
if it does exist, otherwiseFalse
. if the field value is greater than or equal toi
and less than or equal toj
, otherwiseFalse
.- Raises:
TypeError – When the field
len_bt()
is called on does not have alen()
function.
- exists()#
Test for a dict where a provided key exists.
>>> Query().f1.exists()
- fragment(document)#
- is_cacheable()#
- len_bt(i, j)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length is greater than or equal to
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_bt(1,18)))
- Parameters:
i – The minimum length of a field as an int.
j – The maximum length of a field as an int.
- Returns:
True
if it does exist, otherwiseFalse
. if the field length is greater than or equal toi
and less than or equal toj
, otherwiseFalse
.- Raises:
TypeError – When the field
len_bt()
is called on does not have alen()
function.
- len_eq(i)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length matches
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_eq(18)))
- len_ge(i)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length is greater than or equal to
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_ge(18)))
- len_gt(i)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length is greater than
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_gt(18)))
- len_le(i)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length is less than or equal to
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_le(18)))
- len_lt(i)#
Tests the length of a field. This could be the length of a string or an array field.
Fields whose length is less than
i
are returned in the search.- Example:
>>> from yawning_titan.networks.network_db import NetworkDB >>> from yawning_titan.db.query import YawningTitanQuery >>> db = NetworkDB() >>> db.search(YawningTitanQuery.matrix.len_lt(18)))
- map(fn)#
Add a function to the query path. Similar to __getattr__ but for arbitrary functions.
- matches(regex, flags=0)#
Run a regex test against a dict value (whole string has to match).
>>> Query().f1.matches(r'^\w+$')
- Parameters:
regex – The regular expression to use for matching
flags – regex flags to pass to
re.match
- noop()#
Always evaluate to
True
.Useful for having a base value when composing queries dynamically.
- one_of(items)#
Check if the value is contained in a list or generator.
>>> Query().f1.one_of(['value 1', 'value 2'])
- Parameters:
items – The list of items to check with
- search(regex, flags=0)#
Run a regex test against a dict value (only substring string has to match).
>>> Query().f1.search(r'^\w+$')
- Parameters:
regex – The regular expression to use for matching
flags – regex flags to pass to
re.match
- test(func, *args)#
Run a user-defined test function against a dict value.
>>> def test_func(val): ... return val == 42 ... >>> Query().f1.test(test_func)
Warning
The test fuction provided needs to be deterministic (returning the same value when provided with the same arguments), otherwise this may mess up the query cache that
Table
implements.- Parameters:
func – The function to call, passing the dict as the first argument
args – Additional arguments to pass to the test function