(src_type, dst_type, src_range,
dst_range, schema, mixed=False, func=None, mask="")
| 74 | |
| 75 | |
| 76 | def gen_edge_data(src_type, dst_type, src_range, |
| 77 | dst_range, schema, mixed=False, func=None, mask=""): |
| 78 | if not func: |
| 79 | func = fixed_dst_ids |
| 80 | |
| 81 | def write_meta(f, schema): |
| 82 | meta = 'src_id:int64\tdst_id:int64' |
| 83 | |
| 84 | if WEIGHTED in schema: |
| 85 | meta += '\tweight:float' |
| 86 | if LABELED in schema: |
| 87 | meta += '\tlabel:int64' |
| 88 | if ATTRIBUTED in schema: |
| 89 | meta += '\tfeature:string' |
| 90 | meta += '\n' |
| 91 | f.write(meta) |
| 92 | |
| 93 | def write_data(f, src_type, dst_type, src_id, dst_id, edge_type, schema): |
| 94 | line = '%d\t%d' % (src_id, dst_id) |
| 95 | if WEIGHTED in schema: |
| 96 | line = '%s\t%f' % (line, (src_id + 0.1 * dst_id) / 10.0) |
| 97 | if LABELED in schema: |
| 98 | line = '%s\t%d' % (line, src_id) |
| 99 | if ATTRIBUTED in schema: |
| 100 | attr = '%d:%f:%d:%s' % (src_id, src_id / 1.0, dst_id, 'hehe') |
| 101 | line = '%s\t%s' % (line, attr) |
| 102 | line += '\n' |
| 103 | f.write(line) |
| 104 | |
| 105 | path = '%s/%s_%s_%d_%s' % (DATA_PATH, src_type, |
| 106 | dst_type, int(time.time() * 1000), mask) |
| 107 | with open(path, 'w') as f: |
| 108 | write_meta(f, schema) |
| 109 | src = range(src_range[0], src_range[1]) |
| 110 | # dst = range(dst_range[0], dst_range[1]) |
| 111 | |
| 112 | index = 0 |
| 113 | for src_id in src: |
| 114 | for dst_id in func(src_id, dst_range): |
| 115 | if index < src_range[1] / 2: |
| 116 | edge_type = 'first' |
| 117 | elif not mixed: |
| 118 | edge_type = 'first' |
| 119 | else: |
| 120 | edge_type = 'second' |
| 121 | write_data(f, src_type, dst_type, src_id, dst_id, edge_type, schema) |
| 122 | index += 1 |
| 123 | return path |
| 124 | |
| 125 | |
| 126 | def fixed_dst_ids(src_ids, dst_range): |
nothing calls this directly
no test coverage detected