1515# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1616#
1717
18+ from __future__ import print_function
19+
1820
1921class Cluster (object ):
2022 """
@@ -34,16 +36,13 @@ def __init__(self, level, *args):
3436 """
3537 Constructor
3638
37- PARAMETERS
38- level - The level of this cluster. This is used in hierarchical
39- clustering to retrieve a specific set of clusters. The
40- higher the level, the smaller the count of clusters
41- returned. The level depends on the difference function
42- used.
43- *args - every additional argument passed following the level value
44- will get added as item to the cluster. You could also pass
45- a list as second parameter to initialise the cluster with
46- that list as content
39+ :param level: The level of this cluster. This is used in hierarchical
40+ clustering to retrieve a specific set of clusters. The higher the
41+ level, the smaller the count of clusters returned. The level depends
42+ on the difference function used.
43+ :param *args: every additional argument passed following the level value
44+ will get added as item to the cluster. You could also pass a list as
45+ second parameter to initialise the cluster with that list as content
4746 """
4847 self .__level = level
4948 if len (args ) == 0 :
@@ -55,18 +54,16 @@ def append(self, item):
5554 """
5655 Appends a new item to the cluster
5756
58- PARAMETERS
59- item - The item that is to be appended
57+ :param item: The item that is to be appended.
6058 """
6159 self .__items .append (item )
6260
6361 def items (self , new_items = None ):
6462 """
6563 Sets or gets the items of the cluster
6664
67- PARAMETERS
68- new_items (optional) - if set, the items of the cluster will be
69- replaced with that argument.
65+ :param new_items: if set, the items of the cluster will be replaced with
66+ that argument.
7067 """
7168 if new_items is None :
7269 return self .__items
@@ -80,8 +77,7 @@ def fullyflatten(self, *args):
8077 some items of the cluster are clusters in their own right and you only
8178 want the items.
8279
83- PARAMETERS
84- *args - only used for recursion.
80+ :param *args: only used for recursion.
8581 """
8682 flattened_items = []
8783 if len (args ) == 0 :
@@ -99,39 +95,41 @@ def fullyflatten(self, *args):
9995
10096 def level (self ):
10197 """
102- Returns the level associated with this cluster
98+ Returns the level associated with this cluster.
10399 """
104100 return self .__level
105101
106102 def display (self , depth = 0 ):
107103 """
108- Pretty-prints this cluster. Useful for debuging
104+ Pretty-prints this cluster. Useful for debuging.
109105 """
110- print depth * " " + "[level %s]" % self .__level
106+ print ( depth * " " + "[level %s]" % self .__level )
111107 for item in self .__items :
112108 if isinstance (item , Cluster ):
113109 item .display (depth + 1 )
114110 else :
115- print depth * " " + "%s" % item
111+ print ( depth * " " + "%s" % item )
116112
117113 def topology (self ):
118114 """
119115 Returns the structure (topology) of the cluster as tuples.
120116
121- Output from cl.data:
122- 123- 124- 125- <[email protected] (['ChangeLog', 'ChangeLog.txt'])>])>, 126- <[email protected] (['20060730.py', 127- 128- 129- '.pylint.d'])>])>])>])>])>])>])>]
117+ Output from cl.data::
118+
119+ 120+ 121+ 122+ <[email protected] (['ChangeLog', 'ChangeLog.txt'])>])>, 123+ <[email protected] (['20060730.py', 124+ 125+ 126+ '.pylint.d'])>])>])>])>])>])>])>]
127+
128+ Corresponding output from cl.topo()::
130129
131- Corresponding output from cl.topo():
132- ('CVS', ('34.xls', (('0.txt', ('ChangeLog', 'ChangeLog.txt')),
133- ('20060730.py', ('.cvsignore', ('About.py',
134- ('.idlerc', '.pylint.d')))))))
130+ ('CVS', ('34.xls', (('0.txt', ('ChangeLog', 'ChangeLog.txt')),
131+ ('20060730.py', ('.cvsignore', ('About.py',
132+ ('.idlerc', '.pylint.d')))))))
135133 """
136134
137135 left = self .__items [0 ]
@@ -157,10 +155,9 @@ def getlevel(self, threshold):
157155 receive and the higher you set it, you will receive less but bigger
158156 clusters.
159157
160- PARAMETERS
161- threshold - The level threshold
158+ :param threshold: The level threshold:
162159
163- NOTE
160+ .. note::
164161 It is debatable whether the value passed into this method should
165162 really be as strongly linked to the real cluster-levels as it is
166163 right now. The end-user will not know the range of this value
0 commit comments