Sequence databases and patterns#

Sequence databases, sequential patterns and containment.

A sequence is an ordered list of non-empty itemsets (elements); most event logs have exactly one item per element. A pattern has the same structure and is written as a tuple of tuples: (("a",), ("b", "c")) is the pattern \(\langle a\,(bc)\rangle\). Every public function of the package also accepts patterns as strings ("a b c", "a (b c)", "a -> b") or lists.

SequenceDatabase, pattern parsing and formatting, containment under gap, span and time constraints.

Classes#

Constraints([min_gap, max_gap, max_span, ...])

Gap and span constraints of an occurrence.

SequenceDatabase(sequences[, times, ids, ...])

A database of sequences of itemsets with optional timestamps and attributes.

Functions#

as_pattern(p[, alphabet])

Normalize a pattern given as tuple of tuples, list or string.

contains(sequence, pattern[, constraints, times])

Whether a sequence contains a pattern under the given constraints.

find_occurrence(sequence, pattern[, ...])

Element indices of the earliest-ending occurrence of a pattern, or None.

format_pattern(p[, style, labels])

Format a pattern as text.

is_subpattern(p, q)

Whether pattern p is contained in pattern q (no gap constraints).

item_key(x)

Sort key giving a total order over mixed items: numbers first, then strings.

parent_pattern(p)

The pattern with its last item removed (the empty tuple for single items).

pattern_items(p)

Items of a pattern in order of appearance (with repetitions).

pattern_length(p)

Number of items of a pattern.