Revision 199
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/util/format_for_review | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
# Converts a map spreadsheet to human-readable (but machine unusable) form |
|
3 |
# Usage: self <in_map >out_ma |
|
4 |
|
|
5 |
import csv |
|
6 |
import re |
|
7 |
import sys |
|
8 |
|
|
9 |
def sub_nested(regex, repl, str_): |
|
10 |
while True: |
|
11 |
str_, n = re.subn(regex, repl, str_) |
|
12 |
if n == 0: return str_ |
|
13 |
|
|
14 |
def cleanup(xpath): |
|
15 |
truncated = False |
|
16 |
|
|
17 |
# Remove attrs |
|
18 |
xpath = sub_nested(r':\[[^\[\]]*?\]', r'', xpath) |
|
19 |
|
|
20 |
# Remove lookahead assertions |
|
21 |
xpath = sub_nested(r'\((/[^\)]*?)\)(?=/)', r'\1', xpath) |
|
22 |
|
|
23 |
# Remove pointers |
|
24 |
xpath, n = re.subn(r'^.*->', r'', xpath) |
|
25 |
if n > 0: truncated = True |
|
26 |
|
|
27 |
# Remove part of path before first key list, XML function, or path end |
|
28 |
# Leave enough to include the table of a user-defined value |
|
29 |
xpath, n = re.subn(r'^(?:/(?!_)[\w*]+)*(?=(?:/(?!_)[\w*]+){2}(?:\[|/_|$))', |
|
30 |
r'', xpath) |
|
31 |
# Prepend / to show truncation |
|
32 |
if n > 0: truncated = True |
|
33 |
|
|
34 |
# Remove backward (child-to-parent) pointer's target ID attr |
|
35 |
xpath = re.sub(r'\[[\w*]+\]|(?<=\[)[\w*]+,', r'', xpath) |
|
36 |
|
|
37 |
# Remove negative keys |
|
38 |
xpath = re.sub(r',?!(?:[\w*]+/)*@?[\w*]+', r'', xpath) |
|
39 |
|
|
40 |
# Remove path before key |
|
41 |
xpath = re.sub(r'(?:[\w*]+/)*(@?[\w*]+)(?==)', r'\1', xpath) |
|
42 |
|
|
43 |
# Prepend / to show truncation |
|
44 |
if truncated: xpath = '/'+xpath |
|
45 |
|
|
46 |
return xpath |
|
47 |
|
|
48 |
def main(): |
|
49 |
# Convert map |
|
50 |
reader = csv.reader(sys.stdin) |
|
51 |
writer = csv.writer(sys.stdout) |
|
52 |
writer.writerow(reader.next()) |
|
53 |
for row in reader: |
|
54 |
for i in xrange(2): row[i] = cleanup(row[i]) |
|
55 |
writer.writerow(row) |
|
56 |
|
|
57 |
main() |
|
58 | 0 |
mappings/format_all_for_review | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
# Converts all *.csv to human-readable (but machine unusable) form in for_review |
|
3 |
|
|
4 |
selfDir="$(dirname -- "$0")" |
|
5 |
cd "$selfDir" |
|
6 |
|
|
7 |
for in in *.csv; do |
|
8 |
../scripts/util/format_for_review <"$in" >"for_review/$in" |
|
9 |
done |
|
10 | 0 |
scripts/util/review | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
# Converts a map spreadsheet to human-readable (but machine unusable) form |
|
3 |
# Usage: self <in_map >out_ma |
|
4 |
|
|
5 |
import csv |
|
6 |
import re |
|
7 |
import sys |
|
8 |
|
|
9 |
def sub_nested(regex, repl, str_): |
|
10 |
while True: |
|
11 |
str_, n = re.subn(regex, repl, str_) |
|
12 |
if n == 0: return str_ |
|
13 |
|
|
14 |
def cleanup(xpath): |
|
15 |
truncated = False |
|
16 |
|
|
17 |
# Remove attrs |
|
18 |
xpath = sub_nested(r':\[[^\[\]]*?\]', r'', xpath) |
|
19 |
|
|
20 |
# Remove lookahead assertions |
|
21 |
xpath = sub_nested(r'\((/[^\)]*?)\)(?=/)', r'\1', xpath) |
|
22 |
|
|
23 |
# Remove pointers |
|
24 |
xpath, n = re.subn(r'^.*->', r'', xpath) |
|
25 |
if n > 0: truncated = True |
|
26 |
|
|
27 |
# Remove part of path before first key list, XML function, or path end |
|
28 |
# Leave enough to include the table of a user-defined value |
|
29 |
xpath, n = re.subn(r'^(?:/(?!_)[\w*]+)*(?=(?:/(?!_)[\w*]+){2}(?:\[|/_|$))', |
|
30 |
r'', xpath) |
|
31 |
# Prepend / to show truncation |
|
32 |
if n > 0: truncated = True |
|
33 |
|
|
34 |
# Remove backward (child-to-parent) pointer's target ID attr |
|
35 |
xpath = re.sub(r'\[[\w*]+\]|(?<=\[)[\w*]+,', r'', xpath) |
|
36 |
|
|
37 |
# Remove negative keys |
|
38 |
xpath = re.sub(r',?!(?:[\w*]+/)*@?[\w*]+', r'', xpath) |
|
39 |
|
|
40 |
# Remove path before key |
|
41 |
xpath = re.sub(r'(?:[\w*]+/)*(@?[\w*]+)(?==)', r'\1', xpath) |
|
42 |
|
|
43 |
# Prepend / to show truncation |
|
44 |
if truncated: xpath = '/'+xpath |
|
45 |
|
|
46 |
return xpath |
|
47 |
|
|
48 |
def main(): |
|
49 |
# Convert map |
|
50 |
reader = csv.reader(sys.stdin) |
|
51 |
writer = csv.writer(sys.stdout) |
|
52 |
writer.writerow(reader.next()) |
|
53 |
for row in reader: |
|
54 |
for i in xrange(2): row[i] = cleanup(row[i]) |
|
55 |
writer.writerow(row) |
|
56 |
|
|
57 |
main() |
|
0 | 58 |
mappings/review | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
# Converts all *.csv to human-readable (but machine unusable) form in for_review |
|
3 |
|
|
4 |
selfDir="$(dirname -- "$0")" |
|
5 |
cd "$selfDir" |
|
6 |
|
|
7 |
mkdir -p for_review |
|
8 |
|
|
9 |
for in in *.csv; do |
|
10 |
../scripts/util/review <"$in" >"for_review/$in" |
|
11 |
done |
|
0 | 12 |
mappings/Makefile | ||
---|---|---|
2 | 2 |
$(MAKE) plots |
3 | 3 |
./join VegX VegBank |
4 | 4 |
./join VegX VegBIEN |
5 |
./format_all_for_review
|
|
5 |
./review |
|
6 | 6 |
|
7 | 7 |
FORCE: |
8 | 8 |
|
9 |
all = $(filter-out VegX-% VegBank-%,$(wildcard *-VegBank.*.csv)) \ |
|
9 |
all =\ |
|
10 |
$(wildcard for_review/*.csv) \ |
|
11 |
$(filter-out VegX-% VegBank-%,$(wildcard *-VegBank.*.csv)) \ |
|
10 | 12 |
VegX-*.plots.csv VegX-VegBIEN.organisms.csv |
11 | 13 |
|
12 | 14 |
clean: FORCE |
Also available in: Unified diff
Renamed format*_for_review to review and added for_review to make clean