Patterns API#

Pattern Class#

class paspailleur.pattern_structures.pattern.Pattern(value: PatternValueType)#

A class representing a pattern with various operations for pattern manipulation. It is the entry point of every other pattern class/subclass in Paspailleur project

This class allows for the creation and manipulation of patterns, including operations such as intersection, union, and difference. It also provides properties to check the characteristics of the pattern, such as whether it can be met, joined, or atomized.

Attributes#

PatternValueType:

A type variable representing the type of the pattern’s value.

Private Attributes#

_value:

The processed value of the pattern.

Properties#

value

Return the value of the pattern.

meetable

Check if meet (intersection) operation is defined for this Pattern class.

joinable

Check if join (union) operation is defined for this Pattern class.

atomisable

Check if the pattern can be atomized.

substractable

Check if subtract (difference) operation is defined for this Pattern class.

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, the sole one per Pattern class.

max_pattern

Return the maximal possible pattern, the sole one per Pattern class.

maximal_atoms

Return the maximal atomic patterns.

Values’ Encapsulation#

Pattern.value()#

Return the value of the pattern.

Returns:

value – The value of the pattern.

Return type:

PatternValueType

Examples

>>> p = Pattern("42")
>>> p.value
42
classmethod Pattern.parse_string_description(value: str) PatternValueType#

Parse a string description into a pattern value.

Parameters:

value (str) – The string description of the pattern.

Returns:

parsed – The parsed pattern value.

Return type:

PatternValueType

Examples

>>> Pattern.parse_string_description("3 + 4")
7
classmethod Pattern.preprocess_value(value) PatternValueType#

Preprocess the value before storing it in the pattern.

Parameters:

value – The value to preprocess.

Returns:

value – The preprocessed value.

Return type:

PatternValueType

Examples

>>> Pattern.preprocess_value("raw_value")
'raw_value'

Patterns’ Order#

Pattern.issubpattern(other: Self) bool#

Check if self is less precise or equal to another pattern.

Parameters:

other (Self) – Another pattern to compare with.

Returns:

sub – True if self is less precise or equal to other.

Return type:

Self

Examples

>>> p1 = Pattern("A")
>>> p2 = Pattern("A | B")
>>> p1.issubpattern(p2)
True
Pattern.min_pattern()#

Return the minimal possible pattern, the sole one per Pattern class.

Returns:

min – The minimal pattern or None if undefined.

Return type:

Optional[Self]

Examples

>>> p = Pattern("A")
>>> p.min_pattern
None  # Assuming no minimal pattern is defined
Pattern.max_pattern()#

Return the maximal possible pattern, the sole one per Pattern class.

Returns:

max – The maximal pattern or None if undefined.

Return type:

Optional[Self]

Examples

>>> p = Pattern("A")
>>> p.max_pattern
None  # Assuming no maximal pattern is defined

Patterns’ Merge#

Pattern.meet(other: Self) Self#

Returns the meeting (intersection) of self and another pattern.

Parameters:

other (Self) – Another pattern to meet with.

Returns:

The most precise pattern that is less precise than both self and other.

Return type:

Self

Examples

>>> p1 = Pattern("A")
>>> p2 = Pattern("A & B")
>>> p3 = p1.meet(p2)
>>> p3.value
'A'
Pattern.join(other: Self) Self#

Return the joining (union) of self and another pattern.

Parameters:

other (Self) – Another pattern to join with.

Returns:

The least precise pattern that is more precise than both self and other.

Return type:

Self

Examples

>>> p1 = Pattern("A")
>>> p2 = Pattern("B")
>>> p3 = p1.union(p2)
>>> p3.value
'A | B'
Pattern.intersection(other: Self) Self#

Return the intersection of self and another pattern.

Parameters:

other (Self) – Another pattern to intersect with.

Returns:

The most precise pattern that is less precise than both self and other.

Return type:

Self

Examples

>>> p1 = Pattern("A")
>>> p2 = Pattern("A & B")
>>> p3 = p1.intersection(p2)
>>> p3.value
'A'
Pattern.union(other: Self) Self#

Return the union of self and another pattern.

Parameters:

other (Self) – Another pattern to union with.

Returns:

The least precise pattern that is more precise than both self and other.

Return type:

Self

Examples

>>> p1 = Pattern("A")
>>> p2 = Pattern("B")
>>> p3 = p1.union(p2)
>>> p3.value
'A | B'
Pattern.difference(other: Self) Self#

Return the difference between self and another pattern.

Parameters:

other (Self) – Another pattern to subtract from self.

Returns:

The least precise pattern such that (self - other) | other == self.

Return type:

Self

Notes

this function should only be used to simplify the way the patterns are printed. and not with trust-requiring algorithms.

Examples

>>> p1 = Pattern("A | B")
>>> p2 = Pattern("B")
>>> p3 = p1.difference(p2)
>>> p3.value
'A'
Pattern.meetable()#

Check if meet (intersection) operation is defined for this Pattern class.

Returns:

flag – True if the pattern can be met, False otherwise.

Return type:

bool

Examples

>>> p = Pattern("example")
>>> p.meetable
True
Pattern.joinable()#

Check if join (union) operation is defined for this Pattern class.

Returns:

flag – True if the pattern can be joined, False otherwise.

Return type:

bool

Examples

>>> p = Pattern("example")
>>> p.joinable
True
Pattern.substractable()#

Check if subtract (difference) operation is defined for this Pattern class.

Returns:

flag – True if the pattern can be subtracted, False otherwise.

Return type:

bool

Examples

>>> p = Pattern("a")
>>> p.substractable
True

Atomic Representations#

Pattern.atomic_patterns()#

Return the set of all less precise patterns that cannot be obtained by intersection of other patterns.

Returns:

atoms – A set of atomic patterns.

Return type:

set[Self]

Raises:

NotImplementedError – This method should be implemented in subclasses.

Examples

>>> p = Pattern("A & B")
>>> p.atomic_patterns
{'A', 'B'} # Assuming A and B are atomic patterns
Pattern.maximal_atoms()#

Return the maximal atomic patterns.

Returns:

max_atoms – The set of maximal atomic patterns or None if undefined.

Return type:

Optional[set[Self]]

Examples

>>> p = Pattern("A & B")
>>> p.maximal_atoms
None  # Assuming no maximal atomic patterns are defined
Pattern.atomisable()#

Check if the pattern can be atomized.

Returns:

flag – True if the pattern can be atomized, False otherwise.

Return type:

bool

Examples

>>> p = Pattern("example")
>>> p.atomisable
True

Built-in Patterns#

Pattern Structure#

Basic operations on a context#

Initialisation of the Pattern Structure#

Properties that are easy to compute#

Pattern Iterators#

High-level FCA API#

Measures of Patterns#

Helping Functions#