orionweller
commited on
Add files using upload-large-folder tool
Browse files- create_id_mappings.py +58 -0
- doc_mapping_neuclir_1_fa.pkl +3 -0
- doc_mapping_neuclir_1_ru.pkl +3 -0
- doc_mapping_neuclir_1_zh.pkl +3 -0
create_id_mappings.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pickle
|
3 |
+
from tqdm import tqdm # for progress bar
|
4 |
+
import ir_datasets as irds
|
5 |
+
|
6 |
+
def create_doc_mappings():
|
7 |
+
collections = ['neuclir/1/zh', 'neuclir/1/fa', 'neuclir/1/ru']
|
8 |
+
|
9 |
+
for collection in collections:
|
10 |
+
print(f"Processing {collection}...")
|
11 |
+
|
12 |
+
# Create mapping
|
13 |
+
doc_mapping = {}
|
14 |
+
dataset = irds.load(collection)
|
15 |
+
|
16 |
+
# Use tqdm to show progress
|
17 |
+
for doc in tqdm(dataset.docs):
|
18 |
+
doc_mapping[doc.doc_id] = {
|
19 |
+
'title': doc.title,
|
20 |
+
'text': doc.text
|
21 |
+
}
|
22 |
+
|
23 |
+
# Save to file
|
24 |
+
output_file = f"doc_mapping_{collection.replace('/', '_')}.pkl"
|
25 |
+
with open(output_file, 'wb') as f:
|
26 |
+
pickle.dump(doc_mapping, f, protocol=pickle.HIGHEST_PROTOCOL)
|
27 |
+
|
28 |
+
print(f"Saved mapping to {output_file}")
|
29 |
+
print(f"Number of documents: {len(doc_mapping)}\n")
|
30 |
+
|
31 |
+
# Function to load and use the mapping
|
32 |
+
def get_text_from_id_fast(docid, collection):
|
33 |
+
collection = collection.replace('zho', 'zh').replace('fas', 'fa').replace('rus', 'ru')
|
34 |
+
mapping_file = f"doc_mapping/doc_mapping_{collection.replace('/', '_')}.pkl"
|
35 |
+
|
36 |
+
# Load mapping if not already loaded
|
37 |
+
if not hasattr(get_text_from_id_fast, 'cache'):
|
38 |
+
get_text_from_id_fast.cache = {}
|
39 |
+
|
40 |
+
if collection not in get_text_from_id_fast.cache:
|
41 |
+
with open(mapping_file, 'rb') as f:
|
42 |
+
get_text_from_id_fast.cache[collection] = pickle.load(f)
|
43 |
+
|
44 |
+
doc = get_text_from_id_fast.cache[collection].get(docid)
|
45 |
+
if doc:
|
46 |
+
return doc['title'], doc['text']
|
47 |
+
return None, None
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
# Create the mappings
|
51 |
+
# create_doc_mappings()
|
52 |
+
|
53 |
+
# Example usage
|
54 |
+
docid = "8e45c80f-f63b-4eca-9976-79185811cd7d" # replace with a real doc ID
|
55 |
+
collection = "neuclir/1/fa"
|
56 |
+
title, text = get_text_from_id_fast(docid, collection)
|
57 |
+
print(title)
|
58 |
+
print(text)
|
doc_mapping_neuclir_1_fa.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9e0a95c6b5ef9a32e665b8c041073c6940af975c931d8347c6e6f946bf29d71
|
3 |
+
size 8294219614
|
doc_mapping_neuclir_1_ru.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:887f72f6488e1266c87d9b92dba0981ad90ad7aa452dc0b72d957389fa757246
|
3 |
+
size 14950632244
|
doc_mapping_neuclir_1_zh.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8a81053e94faf4df670091d82545e676322d3a285f56fa4a32c39394de89d7e3
|
3 |
+
size 6560604826
|