|
1 | 1 | import pandas as pd |
2 | 2 | import json |
3 | 3 | from collections import defaultdict |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 |
|
6 | 7 | # these functions are used to cache various results |
|
10 | 11 | # can be changed. |
11 | 12 |
|
12 | 13 |
|
| 14 | +def _load_json(path): |
| 15 | + with Path(path).open('rt') as f: |
| 16 | + return json.load(f) |
| 17 | + |
| 18 | + |
| 19 | +def _save_json(obj, path): |
| 20 | + with Path(path).open('wt') as f: |
| 21 | + json.dump(obj, f) |
| 22 | + |
| 23 | + |
| 24 | +def load_references(path): |
| 25 | + return _load_json(path) |
| 26 | + |
| 27 | + |
| 28 | +def save_references(references, path): |
| 29 | + _save_json(references, path) |
| 30 | + |
| 31 | + |
13 | 32 | def load_tags(path): |
14 | | - with open(path, 'rt') as f: |
15 | | - tags = json.load(f) |
16 | | - return tags |
| 33 | + return _load_json(path) |
17 | 34 |
|
18 | 35 |
|
19 | 36 | def save_tags(tags, path): |
20 | | - with open(path, 'wt') as f: |
21 | | - json.dump(tags, f) |
| 37 | + _save_json(tags, path) |
22 | 38 |
|
23 | 39 |
|
24 | 40 | def load_structure(path): |
25 | | - with open(path, 'rt') as f: |
26 | | - structure = json.load(f) |
27 | | - return structure |
| 41 | + return _load_json(path) |
28 | 42 |
|
29 | 43 |
|
30 | 44 | def save_structure(structure, path): |
31 | | - with open(path, 'wt') as f: |
32 | | - json.dump(structure, f) |
| 45 | + _save_json(structure, path) |
33 | 46 |
|
34 | 47 |
|
35 | 48 | def load_proposals(path): |
|
0 commit comments