Ignore:
Timestamp:
02/23/11 10:58:57 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
bd5672210fe37caeded5bd7323ae7ad08a102696
Message:

Orange/classification/tree.TreeDumper - limited width to 80 chars.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/classification/tree.py

    r7660 r7707  
    27762776 
    27772777 
    2778 # This class is more a collection of function, merged into a class so that they don't 
    2779 # need to transfer too many arguments. It will be constructed, used and discarded, 
    2780 # it is not meant to store any information. 
     2778# This class is more a collection of function, merged into a class so  
     2779# that they don't need to transfer too many arguments. It will be  
     2780# constructed, used and discarded, it is not meant to store any information. 
    27812781class __TreeDumper: 
    2782     defaultStringFormats = [(re_V, replaceV), (re_N, replaceN), (re_M, replaceM), (re_m, replacem), 
    2783                               (re_Cdisc, replaceCdisc), (re_cdisc, replacecdisc), 
    2784                               (re_Ccont, replaceCcont), (re_ccont, replaceccont), 
    2785                               (re_Cconti, replaceCconti), (re_cconti, replacecconti), 
    2786                               (re_D, replaceD), (re_d, replaced), 
    2787                               (re_AE, replaceAE), (re_I, replaceI) 
    2788                              ] 
    2789  
    2790     def __init__(self, leafStr, nodeStr, stringFormats, minExamples, maxDepth, simpleFirst, tree, **kw): 
     2782    defaultStringFormats = [(re_V, replaceV), (re_N, replaceN), 
     2783         (re_M, replaceM), (re_m, replacem),  
     2784         (re_Cdisc, replaceCdisc), (re_cdisc, replacecdisc), 
     2785         (re_Ccont, replaceCcont), (re_ccont, replaceccont), 
     2786         (re_Cconti, replaceCconti), (re_cconti, replacecconti), 
     2787         (re_D, replaceD), (re_d, replaced), (re_AE, replaceAE),  
     2788         (re_I, replaceI) ] 
     2789 
     2790    def __init__(self, leafStr, nodeStr, stringFormats, minExamples,  
     2791        maxDepth, simpleFirst, tree, **kw): 
    27912792        self.stringFormats = stringFormats 
    27922793        self.minExamples = minExamples 
     
    28342835    def showBranch(self, node, parent, lev, i): 
    28352836        bdes = node.branchDescriptions[i] 
    2836         bdes = node.branchSelector.classVar.name + (bdes[0] not in "<=>" and "=" or "") + bdes 
     2837        bdes = node.branchSelector.classVar.name + \ 
     2838            (bdes[0] not in "<=>" and "=" or "") + bdes 
    28372839        if node.branches[i]: 
    2838             nodedes = self.nodeStr and ": "+self.formatString(self.nodeStr, node.branches[i], node) or "" 
     2840            nodedes = self.nodeStr and ": " + \ 
     2841                self.formatString(self.nodeStr, node.branches[i], node) or "" 
    28392842        else: 
    28402843            nodedes = "<null node>" 
     
    28442847    def dumpTree0(self, node, parent, lev): 
    28452848        if node.branches: 
    2846             if node.distribution.abs < self.minExamples or lev > self.maxDepth: 
     2849            if node.distribution.abs < self.minExamples or \ 
     2850                lev > self.maxDepth: 
    28472851                return "|    "*lev + ". . .\n" 
    28482852             
     
    28562860                    if not branch or not branch.branches: 
    28572861                        if self.leafStr == self.nodeStr: 
    2858                             res += "%s\n" % self.showBranch(node, parent, lev, i) 
     2862                            res += "%s\n" % \ 
     2863                                self.showBranch(node, parent, lev, i) 
    28592864                        else: 
    2860                             res += "%s: %s\n" % (self.showBranch(node, parent, lev, i), 
    2861                                                  leafsep + self.formatString(self.leafStr, branch, node)) 
     2865                            res += "%s: %s\n" % \ 
     2866                                (self.showBranch(node, parent, lev, i), 
     2867                                 leafsep +  
     2868                                 self.formatString(self.leafStr, branch, node)) 
    28622869            for i, branch in enumerate(node.branches): 
    28632870                if branch and branch.branches: 
     
    28682875                        res += "%s\n" % self.showBranch(node, parent, lev, i) 
    28692876                    else: 
    2870                         res += "%s: %s\n" % (self.showBranch(node, parent, lev, i), 
    2871                                              leafsep+self.formatString(self.leafStr, branch, node)) 
     2877                        res += "%s: %s\n" % \ 
     2878                            (self.showBranch(node, parent, lev, i), 
     2879                             leafsep +  
     2880                             self.formatString(self.leafStr, branch, node)) 
    28722881            return res 
    28732882        else: 
     
    28772886    def dumpTree(self): 
    28782887        if self.nodeStr: 
    2879             lev, res = 1, "root: %s\n" % self.formatString(self.nodeStr, self.tree.tree, None) 
     2888            lev, res = 1, "root: %s\n" % \ 
     2889                self.formatString(self.nodeStr, self.tree.tree, None) 
    28802890            self.maxDepth += 1 
    28812891        else: 
     
    28862896    def dotTree0(self, node, parent, internalName): 
    28872897        if node.branches: 
    2888             if node.distribution.abs < self.minExamples or len(internalName)-1 > self.maxDepth: 
    2889                 self.fle.write('%s [ shape="plaintext" label="..." ]\n' % _quoteName(internalName)) 
     2898            if node.distribution.abs < self.minExamples or \ 
     2899                len(internalName)-1 > self.maxDepth: 
     2900                self.fle.write('%s [ shape="plaintext" label="..." ]\n' % \ 
     2901                    _quoteName(internalName)) 
    28902902                return 
    28912903                 
     
    28932905            if self.nodeStr: 
    28942906                label += "\\n" + self.formatString(self.nodeStr, node, parent) 
    2895             self.fle.write('%s [ shape=%s label="%s"]\n' % (_quoteName(internalName), self.nodeShape, label)) 
     2907            self.fle.write('%s [ shape=%s label="%s"]\n' % \ 
     2908                (_quoteName(internalName), self.nodeShape, label)) 
    28962909             
    28972910            for i, branch in enumerate(node.branches): 
    28982911                if branch: 
    28992912                    internalBranchName = internalName+chr(i+65) 
    2900                     self.fle.write('%s -> %s [ label="%s" ]\n' % (_quoteName(internalName), _quoteName(internalBranchName), node.branchDescriptions[i])) 
     2913                    self.fle.write('%s -> %s [ label="%s" ]\n' % \ 
     2914                        (_quoteName(internalName),  
     2915                         _quoteName(internalBranchName),  
     2916                         node.branchDescriptions[i])) 
    29012917                    self.dotTree0(branch, node, internalBranchName) 
    29022918                     
    29032919        else: 
    2904             self.fle.write('%s [ shape=%s label="%s"]\n' % (internalName, self.leafShape, self.formatString(self.leafStr, node, parent))) 
     2920            self.fle.write('%s [ shape=%s label="%s"]\n' % \ 
     2921                (internalName, self.leafShape,  
     2922                self.formatString(self.leafStr, node, parent))) 
    29052923 
    29062924 
     
    29592977""" An alias for :func:`printTree`. Left for compatibility. """ 
    29602978 
    2961  
    29622979def printDot(tree, fileName, leafStr = "", nodeStr = "", leafShape="plaintext", nodeShape="plaintext", **argkw): 
    29632980    """ Prints the tree to a file in a format used by  
Note: See TracChangeset for help on using the changeset viewer.