Cartesian Pattern#
- class paspailleur.bip.CartesianPattern(value: PatternValueType)#
A class representing a Cartesian product of multiple dimensions as a pattern.
Attributes#
- PatternValueType:
The type of the pattern’s value, which is a frozendict mapping dimension names to Pattern instances.
- DimensionTypes: dict[str, Type[Pattern]]
Optional mapping from dimension names to specific Pattern types for parsing.
Properties#
- atomic_patterns
Return the set of all less precise patterns that cannot be obtained by intersection of other patterns.
- min_pattern
Return the minimal possible pattern for the Cartesian pattern.
- max_pattern
Return the maximal atomic patterns of the Cartesian pattern.
- maximal_atoms
Return the maximal atomic patterns of the Cartesian pattern.
- classmethod preprocess_value(value) frozendict[str, Pattern] #
Preprocess the value before storing it in the Cartesian pattern.
- Parameters:
value (dict) – A dictionary mapping dimension names to pattern descriptions or Pattern instances.
- Returns:
value – The preprocessed frozendict of dimension names to Pattern instances.
- Return type:
PatternValueType
- Raises:
AssertionError – If required dimension types are missing or unprocessable.
Examples
>>> class PersonPattern(CartesianPattern): ... DimensionTypes = { ... 'age': IntervalPattern, ... 'name': NgramSetPattern, ... 'personal qualities': ItemSetPattern ... } >>> PersonPattern.preprocess_value({ ... 'age': 20, ... 'name': 'Jean-Francois Martin', ... 'personal qualities': ['Ambitious', 'Approachable', 'Articulate'] ... }) frozendict({ 'age': IntervalPattern((20.0, 20.0)), 'name': NgramSetPattern({('Jean-Francois',), ('Martin',)}), 'personal qualities': ItemSetPattern({'Ambitious', 'Approachable', 'Articulate'}) })
- atomise(atoms_configuration: Literal['min', 'max'] = 'min') set[Self] #
Split the pattern into atomic patterns, i.e. the union of atomic patterns computed for each dimension
- Parameters:
atoms_configuration (Literal['min', 'max']) – Whether to output the maximal set of atomic patterns for each dimension (if set to ‘max’) or the minimal set of atomic patterns for each dimension (if set to ‘min’). Defaults to ‘min’.
- Returns:
atomic_patterns – The set of atomic patterns, i.e. the set of unsplittable patterns whose join equals to the pattern.
- Return type:
set[Self]
Notes
Speaking in terms of Ordered Set Theory: We say that every pattern can be represented as the join of a subset of atomic patterns, that are join-irreducible elements of the lattice of all patterns.
Considering the set of atomic patterns as a partially ordered set (where the order follows the order on patterns), every pattern can be represented by an _antichain_ of atomic patterns (when atoms_configuration = ‘min’), and by an order ideal of atomic patterns (when atoms_configuration = ‘max’).
- property atomic_patterns: set[Self]#
Return the set of atomic patterns of a CartesianPattern which is the union of sets of atomic patterns per its every dimension
- Returns:
atoms – A set of atomic Cartesian patterns.
- Return type:
set[Self]
Examples
>>> class PersonPattern(CartesianPattern): ... DimensionTypes = { ... 'age': IntervalPattern, ... 'name': NgramSetPattern ... } >>> p1 = PersonPattern({'age': "[20, 40]", 'name': "John Smith"}) >>> atoms = p1.atomic_patterns >>> for atom in atoms: ... print(atom) {'name': {'John Smith'}} {'name': {'Smith'}} {'name': {'John'}} {'age': <= 40.0} {'age': >= 20.0} {} {'name': {'John Smith'}}
- classmethod get_min_pattern() Self | None #
Return the minimal possible pattern for the Cartesian pattern that contains min patterns per every dimension.
- Returns:
min – The minimal Cartesian pattern or None if any subpattern has no minimum.
- Return type:
Optional[Self]
Examples
>>> class PersonPattern(CartesianPattern): ... DimensionTypes = { ... 'age': IntervalPattern, ... 'name': NgramSetPattern ... } >>> PersonPattern.get_min_pattern() {} # Stands for `PersonPattern({'age': '[-inf, +inf]', 'name': set()})`
- classmethod get_max_pattern() Self | None #
Return the maximal possible pattern for the Cartesian pattern that contains max patterns per every dimension
- Returns:
max – The maximal Cartesian pattern or None if any subpattern has no maximum.
- Return type:
Optional[Self]
Examples
>>> class PersonPattern(CartesianPattern): ... DimensionTypes = { ... 'age': IntervalPattern, ... 'name': NgramSetPattern ... } >>> PersonPattern.get_max_pattern() None # because max_pattern for dimension 'name' is not defined
- property maximal_atoms: set[Self] | None#
Return the maximal atomic patterns of the Cartesian pattern.
- Returns:
max_atoms – A set of maximal atomic Cartesian patterns.
- Return type:
Optional[set[Self]]
Examples
>>> class PersonPattern(CartesianPattern): ... DimensionTypes = { ... 'age': IntervalPattern, ... 'name': NgramSetPattern, ... 'personal qualities': ItemSetPattern ... } >>> p = PersonPattern({ ... 'age': "[25, 35]", ... 'name': "Alice Johnson", ... 'personal qualities': ['Thoughtful', 'Curious'] ... }) >>> for atom in p.maximal_atoms: ... print(atom) {'age': ø}