Orange Forum • View topic - PATCH: Fix name generation in orngTree.dotTree

PATCH: Fix name generation in orngTree.dotTree

Report bugs (or imagined bugs).
(Archived/read-only, please use our ticketing system for reporting bugs and their discussion.)
Forum rules
Archived/read-only, please use our ticketing system for reporting bugs and their discussion.

PATCH: Fix name generation in orngTree.dotTree

Postby yang » Wed Feb 02, 2011 1:52

For certain (somewhat large) trees, the names generated by dotTree start including characters that dot chokes on. Here's a simple fix to properly encode these strings.

BTW, consider moving development to github - this would encourage contributions and may (I believe) also help the project's "public image."

Thanks.

Code: Select all
$ svn diff
Index: orange/orngTree.py
===================================================================
--- orange/orngTree.py   (revision 9741)
+++ orange/orngTree.py   (working copy)
@@ -1,4 +1,5 @@
 import orange
+import base64
 from warnings import warn
 
 class TreeLearner(orange.Learner):
@@ -594,22 +595,22 @@
     def dotTree0(self, node, parent, internalName):
         if node.branches:
             if node.distribution.abs < self.minExamples or len(internalName)-1 > self.maxDepth:
-                self.fle.write('%s [ shape="plaintext" label="..." ]\n' % internalName)
+                self.fle.write('%s [ shape="plaintext" label="..." ]\n' % _quoteName(internalName))
                 return
                 
             label = node.branchSelector.classVar.name
             if self.nodeStr:
                 label += "\\n" + self.formatString(self.nodeStr, node, parent)
-            self.fle.write('%s [ shape=%s label="%s"]\n' % (internalName, self.nodeShape, label))
+            self.fle.write('%s [ shape=%s label="%s"]\n' % (_quoteName(internalName), self.nodeShape, label))
             
             for i, branch in enumerate(node.branches):
                 if branch:
                     internalBranchName = internalName+chr(i+65)
-                    self.fle.write('%s -> %s [ label="%s" ]\n' % (internalName, internalBranchName, node.branchDescriptions[i]))
+                    self.fle.write('%s -> %s [ label="%s" ]\n' % (_quoteName(internalName), _quoteName(internalBranchName), node.branchDescriptions[i]))
                     self.dotTree0(branch, node, internalBranchName)
                     
         else:
-            self.fle.write('%s [ shape=%s label="%s"]\n' % (internalName, self.leafShape, self.formatString(self.leafStr, node, parent)))
+            self.fle.write('%s [ shape=%s label="%s"]\n' % (_quoteName(internalName), self.leafShape, self.formatString(self.leafStr, node, parent)))
 
 
     def dotTree(self, internalName="n"):
@@ -617,6 +618,8 @@
         self.dotTree0(self.tree.tree, None, internalName)
         self.fle.write("}\n")
 
+def _quoteName(x):
+    return '"%s"' % (base64.b64encode(x))
 
 def dumpTree(tree, leafStr = "", nodeStr = "", **argkw):
     return __TreeDumper(leafStr, nodeStr, argkw.get("userFormats", []) + __TreeDumper.defaultStringFormats,

Re: PATCH: Fix name generation in orngTree.dotTree

Postby Mitar » Thu Feb 03, 2011 10:56

Thank you for your patch, we will look it as soon as we can, as we are currently actively involved in re-factoring and restructuring the code, to make it even better to use and work with. Along with it we are also redoing documentation, so it will be easier to use and understand Orange. Together with the release of 2.5 we are planning on on making our site better and our development process more open to contributions as yours. We have just moved to a new server and upgrading the systems we are using.

Because of all this the code and the site is in a state of flux, so please bare with it for a moment, it will be much better soon. In meantime please follow us on Facebook to learn more about what is currently happening with Orange.

Re: PATCH: Fix name generation in orngTree.dotTree

Postby markot » Thu Feb 03, 2011 21:38

Dear Yang,

I have applied your patch. Thank you.

Marko


Return to Bugs