-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker_main.py
94 lines (83 loc) · 3.04 KB
/
docker_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
from pywikimm import reader
from pywikimm import preprocessor
################################################################################
## Please refer to data_collection_demo.ipynb for documentation
################################################################################
# TODO: change the filepath to your input file, if needed
filename = 'docker_input.txt'
invalidate_headings_cache = False
invalidate_parsed_titles_cache = False
invalidate_visual_features_cache = False
query_params = reader.QueryParams(
# if you need to change out_dir, please do so via docker run params.
# this path is relative to image filesystem and should stay the same.
# for more details please refer to installation guide in repo.
out_dir = 'data/',
debug_info = True,
offset = 0,
limit = 5,
invalidate_cache = reader.InvalidateCacheParams(
img_cache = False,
text_cache = False,
caption_cache = False,
img_meta_cache = False,
oudated_img_meta_cache = True,
),
only_update_cached_pages = False,
fill_property= reader.FillPropertyParams(
img_caption = True,
img_description = True,
text_wikitext = True,
text_html = True,
),
language_code = 'en',
early_icons_removal = True,
)
################################################################################
print("Data Collection\n")
reader.query(filename=filename, params=query_params)
print("Data Preprocessing 1. Removing images not available on Commons\n")
preprocessor.filter_img_metadata(
data_path=query_params.out_dir,
offset=query_params.offset,
limit=query_params.limit,
debug_info=query_params.debug_info,
field_to_remove='on_commons',
predicate=lambda x: ('on_commons' not in x) or x['on_commons']
)
print("Data Preproccesing 2. Removing icons\n")
preprocessor.filter_img_metadata(
data_path=query_params.out_dir,
offset=query_params.offset,
limit=query_params.limit,
debug_info=query_params.debug_info,
field_to_remove='is_icon',
predicate=lambda x: ('is_icon' not in x) or (not x['is_icon'])
)
print("Data Preprocessing 3. Parsing Image Headings\n")
preprocessor.parse_image_headings(
data_path=query_params.out_dir,
offset=query_params.offset,
limit=query_params.limit,
invalidate_cache=invalidate_headings_cache,
debug_info=query_params.debug_info,
language_code=query_params.language_code,
)
print("Data Preprocessing 4. Generating visual features\n")
preprocessor.generate_visual_features(
data_path=query_params.out_dir,
offset=query_params.offset,
limit=query_params.limit,
invalidate_cache=invalidate_visual_features_cache,
debug_info=query_params.debug_info,
)
print("Data Preprocessing 5. Parse image titles\n")
preprocessor.tokenize_image_titles(
data_path=query_params.out_dir,
offset=query_params.offset,
limit=query_params.limit,
invalidate_cache=invalidate_parsed_titles_cache,
debug_info=query_params.debug_info,
)
print("Dataset collection has completed.")