for each item in the directory, and then do a product to generate
a result list with all combinations (A Product).
+ For a directory with a magic '$' file, we generate a list of all
+ items that we will randomly choose from.
+
The final description (after recursion) for each item will look
like a relative path. If there was a % product, that path
component will appear as a file with braces listing the selection
(mincyclicity + mat.cyclicity() - 1) / mat.cyclicity(), mat
)
return mat
+ elif '$' in files:
+ # pick a random item
+ files.remove('$')
+ submats = []
+ for fn in sorted(files):
+ submat = _build_matrix(
+ os.path.join(path, fn),
+ mincyclicity,
+ fn)
+ if submat is not None:
+ submats.append(submat)
+ return matrix.PickRandom(item, submats)
else:
# list items
submats = []
import os
+import random
import heapq
from fractions import gcd
ret = '\t'*depth + "Concat({item}):\n".format(item=self.item)
return ret + ''.join([i[1].tostr(depth+1) for i in self.submats])
+class PickRandom(Matrix):
+ """
+ Select a random item from the child matrices.
+ """
+ def __init__(self, item, submats):
+ self.submats = submats
+ self.item = item
+
+ def size(self):
+ return 1
+
+ def minscanlen(self):
+ return 1
+
+ def index(self, i):
+ indx = random.randint(0, len(self.submats) - 1)
+ submat = self.submats[indx]
+ out = frozenset([submat.index(indx)])
+ return (self.item, out)
+
+ def tostr(self, depth):
+ ret = '\t'*depth + "PickRandom({item}):\n".format(item=self.item)
+ return ret + ''.join([i[1].tostr(depth+1) for i in self.submats])
+
class Sum(Matrix):
"""
We want to mix the subsequences proportionately to their size.