Revision 2029
Added by Aaron Marcuse-Kubitza almost 13 years ago
map | ||
---|---|---|
175 | 175 |
|
176 | 176 |
for row in reader: |
177 | 177 |
in_, out = row[:2] |
178 |
if out != '': |
|
179 |
if out_is_xpaths: out = xpath.parse(out_root+out) |
|
180 |
mappings.append((in_, out)) |
|
178 |
if out != '': mappings.append([in_, out_root+out]) |
|
181 | 179 |
|
182 | 180 |
stream.close() |
183 | 181 |
|
... | ... | |
185 | 183 |
in_is_xml = in_is_xpaths and not in_is_db |
186 | 184 |
out_is_xml_ref[0] = out_is_xpaths and not out_is_db |
187 | 185 |
|
186 |
# Prevent collisions if multiple inputs mapping to same output |
|
187 |
outputs_idxs = dict() |
|
188 |
for i, mapping in enumerate(mappings): |
|
189 |
in_, out = mapping |
|
190 |
default = util.NamedTuple(count=1, first=i) |
|
191 |
idxs = outputs_idxs.setdefault(out, default) |
|
192 |
if idxs is not default: # key existed, so there was a collision |
|
193 |
if idxs.count == 1: # first key does not yet have /_alt/# |
|
194 |
mappings[idxs.first][1] += '/_alt/0' |
|
195 |
mappings[i][1] += '/_alt/'+str(idxs.count) |
|
196 |
idxs.count += 1 |
|
197 |
|
|
188 | 198 |
def process_rows(process_row, rows, rows_start=0): |
189 | 199 |
'''Processes input rows |
190 | 200 |
@param process_row(in_row, i) |
... | ... | |
238 | 248 |
col_names_ct = len(col_names) |
239 | 249 |
col_idxs = util.list_flip(col_names) |
240 | 250 |
|
251 |
# Resolve prefixes |
|
241 | 252 |
mappings_orig = mappings[:] # save a copy |
242 | 253 |
mappings[:] = [] # empty existing elements |
243 | 254 |
for in_, out in mappings_orig: |
244 | 255 |
if metadata_value(in_) == None: |
245 | 256 |
try: names = get_with_prefix(col_idxs, prefixes, in_) |
246 | 257 |
except KeyError: pass |
247 |
else: mappings.append((names, out))
|
|
258 |
else: mappings.append([names, out])
|
|
248 | 259 |
|
249 | 260 |
def get_value(in_, row): |
250 | 261 |
return util.coalesce(*util.list_subset(row.list, in_)) |
Also available in: Unified diff
bin/map: Prevent collisions if multiple inputs mapping to same output