Revision 1484
Added by Aaron Marcuse-Kubitza almost 13 years ago
bin/map | ||
---|---|---|
25 | 25 |
import xml_func |
26 | 26 |
|
27 | 27 |
def get_with_prefix(map_, prefixes, key): |
28 |
'''Gets all entries for the given key with any of the given prefixes''' |
|
29 |
values = [] |
|
28 | 30 |
for prefix in ['']+prefixes: # also lookup with no prefix |
29 |
try: return map_[prefix+key] |
|
30 |
except KeyError, e: pass # keep going |
|
31 |
raise e # re-raise last KeyError |
|
31 |
try: value = map_[prefix+key] |
|
32 |
except KeyError, e: continue # keep going |
|
33 |
values.append(value) |
|
34 |
|
|
35 |
if values != []: return values |
|
36 |
else: raise e # re-raise last KeyError |
|
32 | 37 |
|
33 | 38 |
def metadata_value(name): return None # this feature has been removed |
34 | 39 |
|
... | ... | |
184 | 189 |
i += 1 |
185 | 190 |
|
186 | 191 |
def get_value(in_, row): |
187 |
try: return row.list[in_] |
|
188 |
except IndexError: return None |
|
192 |
return util.coalesce(*util.list_subset(row.list, in_)) |
|
189 | 193 |
def wrap_row(row): |
190 | 194 |
return util.ListDict(util.list_as_length(row, col_names_ct), |
191 | 195 |
col_names, col_idxs) # handle CSV rows of different lengths |
Also available in: Unified diff
bin/map: Deal with fields that may be in the dataset under more than one prefix by getting all fields and coalesce()ing them (e.g. SpeciesLink has dwcore* and darwin1* columns for the same DwC field)