Revision 1170
Added by Aaron Marcuse-Kubitza almost 13 years ago
bin/join | ||
---|---|---|
34 | 34 |
writer.writerow(maps.merge_mappings(map_0_cols, map_1_cols)) |
35 | 35 |
for row in reader: |
36 | 36 |
if row[1] != '': |
37 |
try: out_row = map_1[row[1]] |
|
38 |
except KeyError: |
|
37 |
# Look for a match |
|
38 |
out_row = None |
|
39 |
suffix = '' |
|
40 |
while True: |
|
41 |
try: |
|
42 |
out_row = map_1[row[1]] |
|
43 |
break |
|
44 |
except KeyError: |
|
45 |
# Heuristically look for a match on a parent path. |
|
46 |
# If this produces a syntactically invalid parent path (e.g. |
|
47 |
# there is a / within []), it will be ignored since there |
|
48 |
# wouldn't be a an entry in map_1. |
|
49 |
row[1], sep, new_suffix = row[1].rpartition('/') |
|
50 |
if sep == '': break |
|
51 |
suffix = sep+new_suffix+suffix # prepend new suffix |
|
52 |
|
|
53 |
# Write new mapping |
|
54 |
if out_row != None: |
|
55 |
row = maps.merge_mappings(row, out_row) |
|
56 |
row[1] += suffix # don't modify out_row! |
|
57 |
else: |
|
39 | 58 |
msg = 'No join mapping for '+row[1] |
40 | 59 |
warnings.warn(UserWarning(msg)) |
41 | 60 |
row[2] = '** '+msg+' ** '+row[2] |
42 | 61 |
row[1] = '' |
43 |
else: row = maps.merge_mappings(row, out_row) |
|
44 | 62 |
writer.writerow(row) |
45 | 63 |
|
46 | 64 |
main() |
Also available in: Unified diff
join: Added heuristic search for a match on a parent path, so that every XML func suffix of a path doesn't need its own mapping