muspan.query.query#
- class query(domain, property, relation, comparison_value, bypass_checks=False)#
A helper class to standardise formatting of boolean queries - this does not return the result of the query, only stores the question.
A muspan query contains four key elements:
- Parameters:
- domainmuspan.domain
A muspan domain.
- propertytuple or str
Tuple defining the object property to query against. Options include (‘label’, ‘label_name’), (‘object’, ‘type’), etc. If string, it will be expanded to (‘label’, property). See notes below for the full list of available options.
- relationstr or function
An operation defining the type of comparison to perform. See notes below for all available options for both single value and list comparisons. If a function, this should be a member of python’s standard operator library.
- comparison_valuestr, list, float, int, bool
Value against which to test the object property. This can be a string or a list of strings (for categorical labels values), a numeric value (continuous labels values), or Booleans (True / False) which used to check if an object has a property or not (e.g., if it is in a collection or contained within another object).
- bypass_checksbool, optional
If True, standard checks on whether this query can be interpreted are bypassed. May generate unexpected crashes if objects that can’t be interpreted as a query are passed in, but generates a substantial speed increase for large datasets when we’re confident the query is formatted correctly. Defaults to False.
Notes
- Available options for the property argument of a query are:
‘label_name’ - expanded to (‘label’,’label_name’)
(‘label’,’label_name’) - get object labels for the label ‘label_name’
(‘object’,’type’) - get the type of each object (‘point’,’line’, or ‘shape’)
(‘distance’, (‘centroid’, objects_1, objects_2)) - get the distance between the centroids of each objects_1 and the nearest object in objects_2 (these can be object IDs, or query-like)
(‘distance’, (‘boundary’, objects_1, objects_2)) - get the distance between the boundaries of each objects_1 and the nearest object in objects_2 (if an object is a point, the boundary is taken to be the coordinates of the point)
(‘collection’,) - get the collections associated with each object. Note the comma, which is required (no second argument is required here, but we need MuSpAn to recognise this as a tuple)
(‘contains’, (contained_objects, containing_objects)) - get a boolean (True or False) for each contained_object, which is true if it is inside an element of containing_objects.
- For single value comparsions, available options for the relations argument are:
‘is’, ‘equals’, ‘eq’, ‘=’ or ‘==’.
‘is not’,’not’, ‘not equal’, ‘not equal to’, ‘neq’ or ‘!=’.
‘<’, ‘lt’ or ‘less than’.
‘<=’, ‘leq’ or ‘less than or equal’.
‘>’, ‘gt’ or ‘greater than’.
‘>=’, ‘geq’ or ‘greater than or equal’.
- For list comparisons, available options for the relations argument are:
‘in list’, ‘in’ or ‘contained in’.
‘not in list’, ‘not in’ or ‘not contained in’.
- __init__(domain, property, relation, comparison_value, bypass_checks=False)#
Methods