spmviz.data.as_pattern#

spmviz.data.as_pattern(p, alphabet=None)[source]#

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

Parameters:
ptuple, list or str

(("a",), ("b", "c")), ["a", ["b", "c"]], "a (b c)", arrow notation "a -> b -> (c, d)" (items between arrows may contain spaces) or SPMF notation "1 -1 2 3 -1". Without arrows, whitespace separates items.

alphabetmapping, optional

Maps the string form of the items of a database to the items themselves, so that "1 2" resolves to integer items. SequenceDatabase.pattern passes its own alphabet.

Returns:
tuple of tuple

The pattern in canonical form (items of an itemset in natural order).

Examples

>>> as_pattern("a (c b) d")
(('a',), ('b', 'c'), ('d',))
>>> as_pattern(["x", "y"])
(('x',), ('y',))
>>> as_pattern("wake up -> coffee -> (tv, read)")
(('wake up',), ('coffee',), ('read', 'tv'))