@@ -57,8 +57,8 @@ def vis_hierarchy(corexes, column_label=None, max_edges=100, prefix='topics', n_
57
57
# inds = np.where(alpha[j] * mis[j] > 0)[0]
58
58
inds = np .where (alpha [j ] >= 1. )[0 ]
59
59
inds = inds [np .argsort (- alpha [j , inds ] * mis [j , inds ])]
60
- group_number = u" red_" + unicode (j ) if j < n_anchors else unicode (j )
61
- label = group_number + u ':' + u ' ' .join ([annotate (column_label [ind ], corexes [0 ].sign [j ,ind ]) for ind in inds [:6 ]])
60
+ group_number = str ( ' red_' ) + str (j ) if j < n_anchors else str (j )
61
+ label = group_number + ':' + ' ' .join ([annotate (column_label [ind ], corexes [0 ].sign [j ,ind ]) for ind in inds [:6 ]])
62
62
label = textwrap .fill (label , width = 25 )
63
63
l1_labels .append (label )
64
64
@@ -79,7 +79,8 @@ def vis_hierarchy(corexes, column_label=None, max_edges=100, prefix='topics', n_
79
79
# Output JSON files
80
80
try :
81
81
import os
82
- copyfile (os .path .dirname (os .path .realpath (__file__ )) + '/tests/d3_files/force.html' , prefix + '/graphs/force.html' )
82
+ #copyfile(os.path.dirname(os.path.realpath(__file__)) + '/tests/d3_files/force.html', prefix + '/graphs/force.html')
83
+ copyfile (os .path .dirname (os .path .realpath ('tests' )) + '/tests/d3_files/force.html' , prefix + '/graphs/force.html' )
83
84
except :
84
85
print ("Couldn't find 'force.html' file for visualizing d3 output" )
85
86
import json
@@ -156,7 +157,8 @@ def trim(g, max_parents=False, max_children=False):
156
157
for node in g :
157
158
if max_parents :
158
159
parents = list (g .successors (node ))
159
- weights = [g .edge [node ][parent ]['weight' ] for parent in parents ]
160
+ #weights = [g.edge[node][parent]['weight'] for parent in parents]
161
+ weights = [g .adj [node ][parent ]['weight' ] for parent in parents ]
160
162
for weak_parent in np .argsort (weights )[:- max_parents ]:
161
163
g .remove_edge (node , parents [weak_parent ])
162
164
if max_children :
@@ -290,42 +292,46 @@ def edge2pdf(g, filename, threshold=0, position=None, labels=None, connected=Tru
290
292
def cnn (node ):
291
293
#change node names for dot format
292
294
if type (node ) is tuple or type (node ) is list :
293
- return u'n' + u'_' .join (list (map (unicode , node )))
295
+ #return u'n' + u'_'.join(list(map(unicode, node)))
296
+ return u'n' + u'_' .join (list (map (str , node )))
294
297
else :
295
- return unicode ( node )
298
+ return node
296
299
297
300
if connected :
298
301
touching = list (set (sum ([[a , b ] for a , b in g .edges ()], [])))
299
302
g = nx .subgraph (g , touching )
300
303
print ('non-isolated nodes,edges' , len (list (g .nodes ())), len (list (g .edges ())))
301
304
f = safe_open (filename + '.dot' , 'w+' )
305
+ #print('f1->',f)
306
+ #print('directed->',directed)
302
307
if directed :
303
- f .write ("strict digraph {\n " .encode ('utf-8' ))
308
+ f .write ("strict digraph {\n " )#.decode("utf-8")
309
+ #f.write('strict digraph {')
304
310
else :
305
- f .write ("strict graph {\n " . encode ( 'utf-8' ) )
311
+ f .write ("strict graph {" )
306
312
#f.write("\tgraph [overlap=scale];\n".encode('utf-8'))
307
- f .write ("\t node [shape=point];\n " . encode ( 'utf-8' ) )
313
+ f .write ("\t node [shape=point];\n " )
308
314
for a , b , d in g .edges (data = True ):
309
- if d . has_key ( 'weight' ) :
315
+ if 'weight' in d :
310
316
if directed :
311
317
f .write (("\t " + cnn (a ) + ' -> ' + cnn (b ) + ' [penwidth=%.2f' % float (
312
- np .clip (d ['weight' ], 0 , 9 )) + '];\n ' ). encode ( 'utf-8' ) )
318
+ np .clip (d ['weight' ], 0 , 9 )) + '];\n ' ))
313
319
else :
314
320
if d ['weight' ] > threshold :
315
- f .write (("\t " + cnn (a ) + ' -- ' + cnn (b ) + ' [penwidth=' + str (3 * d ['weight' ]) + '];\n ' ).encode (
316
- 'utf-8' ))
321
+ f .write (("\t " + cnn (a ) + ' -- ' + cnn (b ) + ' [penwidth=' + str (3 * d ['weight' ]) + '];\n ' ))
317
322
else :
318
323
if directed :
319
- f .write (("\t " + cnn (a ) + ' -> ' + cnn (b ) + ';\n ' ). encode ( 'utf-8' ) )
324
+ f .write (("\t " + cnn (a ) + ' -> ' + cnn (b ) + ';\n ' ))
320
325
else :
321
- f .write (("\t " + cnn (a ) + ' -- ' + cnn (b ) + ';\n ' ). encode ( 'utf-8' ) )
326
+ f .write (("\t " + cnn (a ) + ' -- ' + cnn (b ) + ';\n ' ))
322
327
for n in g .nodes ():
323
328
if labels is not None :
324
329
if type (labels ) == dict or type (labels ) == list :
325
330
thislabel = labels [n ].replace (u'"' , u'\\ "' )
326
331
lstring = u'label="' + thislabel + u'",shape=none'
327
332
elif type (labels ) == str :
328
- if g .node [n ].has_key ('label' ):
333
+ #if g.node[n].has_key('label'):
334
+ if 'label' in g .node [n ]:
329
335
thislabel = g .node [n ][labels ].replace (u'"' , u'\\ "' )
330
336
# combine dupes
331
337
#llist = thislabel.split(',')
@@ -341,7 +347,7 @@ def cnn(node):
341
347
lstring = u'shape=point,height=%0.2f' % weight
342
348
else :
343
349
lstring = 'label="' + str (n ) + '",shape=none'
344
- lstring = unicode (lstring )
350
+ lstring = str (lstring )
345
351
else :
346
352
lstring = False
347
353
if position is not None :
@@ -353,7 +359,7 @@ def cnn(node):
353
359
finalstring = u' [' + u',' .join ([ts for ts in [posstring , lstring ] if ts ]) + u']\n '
354
360
#finalstring = u' ['+lstring+u']\n'
355
361
f .write (u'\t ' + cnn (n ) + finalstring )
356
- f .write ("}" . encode ( 'utf-8' ) )
362
+ f .write ("}" )
357
363
f .close ()
358
364
if makepdf :
359
365
neato (filename , position = position , directed = directed )
0 commit comments