6 from random import randint
9 #pathout = '/home/pierre/fac/lerass/charlie/charliehebdo-0107-0112-corpus_fr_com_corpus_3/charlie_0712_religion_1/charliehebdo-0107-0112-corpus_fr_com_simitxt_1'
10 #edgesfile = os.path.join(pathout, 'edges.csv')
11 #nodesfile = os.path.join(pathout,'nodes.csv')
12 #jsonout = os.path.join(pathout,'network.json')
15 def __init__(self, nodesfile, edgesfile, jsonout, parametres = {}):
17 with codecs.open(edgesfile, 'r', 'utf8') as f :
19 content = content.replace('"', '')
20 content = content.splitlines()
22 titles_edges = content.pop(0)
23 titles_edges = titles_edges.split('\t')
24 edges = [line.split('\t') for line in content]
28 with codecs.open(nodesfile, 'r', 'utf8') as f :
30 content = content.replace('"','')
31 content = content.splitlines()
32 titles = content.pop(0)
33 titles = titles.split('\t')
36 xr = titles.index('x')
37 yr = titles.index('y')
39 zr = titles.index('z')
42 wr = titles.index('weight')
49 ni = titles.index('name')
51 nodes = [line.split('\t') for line in content]
53 graph = {'edges': [], 'nodes' : {}}
55 we = titles_edges.index('weight')
56 if edges is not None :
58 graph['edges'].append({'source' : edge[0], 'target' : edge[1], 'weight' : edge[we]})
61 coefcoord = parametres.get('coefcoord', 1)
62 coefweight = parametres.get('coefweight', 1)
67 graph['nodes'][node[ni]] = {"location" : [float(node[xr])*coefcoord, float(node[yr])*coefcoord, float(node[zr])*coefcoord], 'weight' : float(node[wr])/coefweight, 'color': (int(node[r]),int(node[g]),int(node[b]))}
69 x = parametres.get('randomx', 0)
72 graph['nodes'][node[ni]] = {"location" : [ x, float(node[xr]), float(node[yr])], 'weight' : float(node[wr]), 'color': (int(node[r]),int(node[g]),int(node[b]))}
74 with open(jsonout, 'w') as f :
77 if __name__ == '__main__' :
78 GraphToJson('/home/pierre/workspace/iramuteq/dev/blender-graphs/nodes.csv', '/home/pierre/workspace/iramuteq/dev/blender-graphs/edges.csv', '/home/pierre/workspace/iramuteq/dev/blender-graphs/L2_L2.json', {})