wefe.query.Query

class wefe.query.Query(target_sets: list[Any], attribute_sets: list[Any], target_sets_names: list[str] | None = None, attribute_sets_names: list[str] | None = None)[source]

Bases: object

A container for attribute and target word sets.

__init__(target_sets: list[Any], attribute_sets: list[Any], target_sets_names: list[str] | None = None, attribute_sets_names: list[str] | None = None) None[source]

Initializes the container. It could include a name for each word set.

Parameters:
  • target_sets (Union[np.ndarray, list]) – Array or list that contains the target word sets.

  • attribute_sets (Union[np.ndarray, Iterable]) – Array or list that contains the attribute word sets.

  • target_sets_names (Union[np.ndarray, Iterable], optional) – Array or list that contains the word sets names, by default None

  • attribute_sets_names (Union[np.ndarray, Iterable], optional) – Array or list that contains the attribute sets names, by default None

target_sets

Array or list with the lists of target words.

Type:

list

attribute_sets

Array or list with the lists of target words.

Type:

list

template

A tuple that contains the template: the cardinality of the target and attribute sets respectively.

Type:

tuple

target_sets_names

Array or list with the names of target sets.

Type:

list

attribute_sets_names

Array or list with the lists of target words.

Type:

list

query_name

A string that contains the auto-generated name of the query.

Type:

str

Raises:
  • TypeError – if target_sets are not an iterable or np.ndarray instance.

  • TypeError – if attribute_sets are not an iterable or np.ndarray instance.

  • Exception – if the length of target_sets is 0.

  • TypeError – if some element of target_sets is not an array or list.

  • TypeError – if some element of some target set is not an string.

  • TypeError – if some element of attribute_sets is not an array or list.

  • TypeError – if some element of some attribute set is not an string.

Examples

Construct a Query with 2 sets of target words and one set of attribute words.

>>> male_terms = ['male', 'man', 'boy']
>>> female_terms = ['female', 'woman', 'girl']
>>> science_terms = ['science','technology','physics']
>>> query = Query([male_terms, female_terms], [science_terms],
...               ['Male terms', 'Female terms'], ['Science terms'])
>>> query.target_sets
[['male', 'man', 'boy'], ['female', 'woman', 'girl']]
>>> query.attribute_sets
[['science', 'technology', 'physics']]
>>> query.query_name
'Male terms and Female terms wrt Science terms'
dict() dict[str, Any][source]

Generate a dictionary from the Query data.

This includes the target and attribute sets, as well as their names, the query name generated from them and the query template.

Returns:

The dictionary generated with the query data.

Return type:

Dict[str, Any]

get_subqueries(new_template: tuple) list[source]

Generate the subqueries from this query using the given template.