Changeset 7712:44b2d8b33fcf in orange


Ignore:
Timestamp:
02/28/11 10:06:18 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
31f3329800da487959e426276e7281c0d76eaffd
Message:

classification/tree.py fixed backward compatibility for printing and node counting.

Location:
orange
Files:
2 edited

Legend:

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

    r7710 r7712  
    29302930        Return a string representation of a tree. 
    29312931 
    2932         :arg tree: The tree to dump to string. 
    2933         :type tree: class:`TreeClassifier` 
    29342932        :arg leafStr: The format string for printing the tree leaves. If  
    29352933          left empty, "%V (%^.2m%)" will be used for classification trees 
     
    29892987        Return the number of nodes of tree. 
    29902988        """ 
    2991         return _countNodes(self.tree if isinstance(self, _TreeClassifier) or \ 
    2992             isinstance(self, TreeClassifier) else self) 
     2989        return _countNodes(self.tree) 
    29932990 
    29942991    def count_leaves(self): 
     
    29962993        Return the number of leaves in the tree. 
    29972994        """ 
    2998         return _countLeaves(self.tree if isinstance(self, _TreeClassifier) or \ 
    2999             isinstance(self, TreeClassifier) else self) 
    3000  
    3001 dumpTree = TreeClassifier.dump 
    3002 """ An alias for :obj:`TreeClassifier.dump`. """ 
    3003  
    3004 def printTree(*a, **aa): 
    3005     """ 
    3006     Print out the tree (call :func:`dumpTree` with the same 
    3007     arguments and print out the result). 
    3008     """ 
    3009     print dumpTree(*a, **aa) 
    3010  
    3011 printTxt = printTree 
    3012 """ An alias for :func:`printTree`. Left for compatibility. """ 
    3013  
    3014 printDot = TreeClassifier.dot 
    3015 """ An alias for :obj:`TreeClassifier.dot` """ 
    3016  
    3017 dotTree = printDot 
    3018 """ An alias for :func:`printDot`. Left for compatibility. """ 
    3019  
    3020 countNodes = TreeClassifier.count_nodes 
    3021 countLeaves = TreeClassifier.count_leaves 
     2995        return _countLeaves(self.tree) 
    30222996 
    30232997def _countNodes(node): 
  • orange/orngTree.py

    r7522 r7712  
    11from Orange.classification.tree import * 
     2 
     3from Orange.classification.tree import _countNodes, _countLeaves,\ 
     4    _TreeClassifier, _TreeDumper 
     5 
     6def countNodes(self): 
     7    """ 
     8    DEPRECATED. Return the number of nodes of tree. 
     9    """ 
     10    return _countNodes(self.tree if isinstance(self, _TreeClassifier) or \ 
     11        isinstance(self, TreeClassifier) else self) 
     12 
     13def countLeaves(self): 
     14    """ 
     15    DEPRECATED. Return the number of leaves in the tree. 
     16    """ 
     17    return _countLeaves(self.tree if isinstance(self, _TreeClassifier) or \ 
     18        isinstance(self, TreeClassifier) else self) 
     19 
     20def dump(self, leafStr = "", nodeStr = "", **argkw):   
     21    """ 
     22    DEPRECATED. Replaced by :obj:`TreeClassifier.dump`. 
     23    """ 
     24    return _TreeDumper(leafStr, nodeStr, argkw.get("userFormats", []) +  
     25        _TreeDumper.defaultStringFormats, argkw.get("minExamples", 0),  
     26        argkw.get("maxDepth", 1e10), argkw.get("simpleFirst", True), 
     27        self).dumpTree() 
     28 
     29def dot(self, fileName, leafStr = "", nodeStr = "", leafShape="plaintext", nodeShape="plaintext", **argkw): 
     30    """ 
     31    DEPRECATED. Replaced by :obj:`TreeClassifier.dump`. 
     32    """ 
     33    fle = type(fileName) == str and file(fileName, "wt") or fileName 
     34 
     35    _TreeDumper(leafStr, nodeStr, argkw.get("userFormats", []) +  
     36        _TreeDumper.defaultStringFormats, argkw.get("minExamples", 0),  
     37        argkw.get("maxDepth", 1e10), argkw.get("simpleFirst", True), self, 
     38        leafShape=leafShape, nodeShape=nodeShape, fle=fle).dotTree() 
     39 
     40dumpTree = dump 
     41""" DEPRECATED: Replaced by :obj:`TreeClassifier.dump`. """ 
     42 
     43def printTree(*a, **aa): 
     44    """ 
     45    DEPRECATED Print out the tree (call :func:`dumpTree` with the same 
     46    arguments and print out the result). 
     47    """ 
     48    print dumpTree(*a, **aa) 
     49 
     50printTxt = printTree 
     51""" DEPRECATED. Replaced by :obj:`TreeClassifier.dump` """ 
     52 
     53printDot = dot 
     54""" DEPRECATED. Replaced by :obj:`TreeClassifier.dot` """ 
     55 
     56dotTree = printDot 
     57""" DEPRECATED. Replaced by :obj:`TreeClassifier.dot` """ 
     58 
Note: See TracChangeset for help on using the changeset viewer.