Below is the file 'branchdiv.py' from this revision. You can also download the file.
# Copyright (C) 2005 Grahame Bowland <grahame@angrygoats.net> # # This program is made available under the GNU GPL version 2.0 or # greater. See the accompanying file COPYING for details. # # This program is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. from mk2 import MarkovChain import sys # it's hardly worth doing anything in this case.. min_to_divide = 20 class BranchDivisions(object): def __init__ (self): self.divisions = None def calculate_divisions (self, branches): if not self.divisions is None: return if len(branches) < 20: self.divisions = [] return chain = MarkovChain (2, join_token='.', cutoff_func=MarkovChain.log_chunkable) for branch in branches: chain.update (branch.name.split ('.')) chain.upchunk () divisions = set () for branch in branches: for chunk in chain.upchunked: idx = branch.name.find (chunk) if idx != -1: divisions.add (branch.name[idx:idx+len(chunk)]) self.divisions = list(divisions) self.divisions.sort ()