spmviz.data.as_pattern#
- spmviz.data.as_pattern(p, alphabet=None)[source]#
Normalize a pattern given as tuple of tuples, list or string.
- Parameters:
- p
tuple,listorstr (("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.- alphabet
mapping,optional Maps the string form of the items of a database to the items themselves, so that
"1 2"resolves to integer items.SequenceDatabase.patternpasses its own alphabet.
- p
- Returns:
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'))