MCPcopy Create free account
hub / github.com/alibaba/graph-learn / gen_node_data

Function gen_node_data

graphlearn/python/tests/utils.py:44–73  ·  view source on GitHub ↗
(id_type, id_range, schema, mask="")

Source from the content-addressed store, hash-verified

42
43
44def gen_node_data(id_type, id_range, schema, mask=""):
45 def write_meta(f, schema):
46 meta = 'id:int64'
47 if WEIGHTED in schema:
48 meta += '\tweight:float'
49 if LABELED in schema:
50 meta += '\tlabel:int64'
51 if ATTRIBUTED in schema:
52 meta += '\tfeature:string'
53 meta += '\n'
54 f.write(meta)
55
56 def write_data(f, value, schema):
57 line = '%d' % value
58 if WEIGHTED in schema:
59 line = '%s\t%f' % (line, value / 10.0)
60 if LABELED in schema:
61 line = '%s\t%d' % (line, value)
62 if ATTRIBUTED in schema:
63 attr = '%d:%f:%d:%s' % (value, value / 1.0, value, 'hehe')
64 line = '%s\t%s' % (line, attr)
65 line += '\n'
66 f.write(line)
67
68 path = '%s/%s_%d_%s' % (DATA_PATH, id_type, int(time.time() * 1000), mask)
69 with open(path, 'w') as f:
70 write_meta(f, schema)
71 for value in range(id_range[0], id_range[1]):
72 write_data(f, value, schema)
73 return path
74
75
76def gen_edge_data(src_type, dst_type, src_range,

Callers

nothing calls this directly

Calls 2

write_metaFunction · 0.85
write_dataFunction · 0.85

Tested by

no test coverage detected