amylonidis commited on
Commit
c4a4c76
·
verified ·
1 Parent(s): acd5d56

Upload clefip2011.py

Browse files
Files changed (1) hide show
  1. clefip2011.py +137 -0
clefip2011.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import datasets
4
+
5
+
6
+ class CLEFIP2011Config(datasets.BuilderConfig):
7
+ """Custom Config for CLEFIP2011"""
8
+
9
+ def __init__(self, dataset_type=None, **kwargs):
10
+ super(CLEFIP2011Config, self).__init__(**kwargs)
11
+ self.dataset_type = dataset_type
12
+
13
+
14
+ class CLEFIP2011(datasets.GeneratorBasedBuilder):
15
+ """Custom Dataset Loader"""
16
+
17
+ BUILDER_CONFIGS = [
18
+ CLEFIP2011Config(
19
+ name="bibliographic",
20
+ version=datasets.Version("1.0.0"),
21
+ description="CLEF-IP 2011 Bibliographic Data",
22
+ dataset_type="bibliographic",
23
+ ),
24
+ ]
25
+
26
+ def _info(self):
27
+
28
+ if self.config.dataset_type == "bibliographic":
29
+ features = datasets.Features(
30
+ {
31
+ "ucid": datasets.Value("string"),
32
+ "country": datasets.Value("string"),
33
+ "doc_number": datasets.Value("string"),
34
+ "kind": datasets.Value("string"),
35
+ "lang": datasets.Value("string"),
36
+ "corrected_lang": datasets.Value("string"),
37
+ "date": datasets.Value("string"),
38
+ "family_id": datasets.Value("string"),
39
+ "date_produced": datasets.Value("string"),
40
+ "status": datasets.Value("string"),
41
+ "ecla_list": datasets.Value("string"),
42
+ "applicant_name_list": datasets.Value("string"),
43
+ "inventor_name_list": datasets.Value("string"),
44
+ "title_de_text": datasets.Value("string"),
45
+ "title_fr_text": datasets.Value("string"),
46
+ "title_en_text": datasets.Value("string"),
47
+ "abstract_de_exist": datasets.Value("bool"),
48
+ "abstract_fr_exist": datasets.Value("bool"),
49
+ "abstract_en_exist": datasets.Value("bool"),
50
+ "description_de_exist": datasets.Value("bool"),
51
+ "description_fr_exist": datasets.Value("bool"),
52
+ "description_en_exist": datasets.Value("bool"),
53
+ "claims_de_exist": datasets.Value("bool"),
54
+ "claims_fr_exist": datasets.Value("bool"),
55
+ "claims_en_exist": datasets.Value("bool"),
56
+ }
57
+ )
58
+ return datasets.DatasetInfo(
59
+ description="CLEF-IP 2011 Bibliographic dataset.",
60
+ features=features,
61
+ supervised_keys=None,
62
+ )
63
+
64
+ def _split_generators(self, dl_manager):
65
+
66
+ archive_path = dl_manager.download_and_extract(
67
+ "https://huggingface.co/datasets/amylonidis/PatClass2011/resolve/main/clefip2011_bibliographic_clean.tar.gz"
68
+ )
69
+
70
+ bibliographic_file = os.path.join(archive_path, "clefip2011_bibliographic.csv")
71
+
72
+ return [
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.TRAIN,
75
+ gen_kwargs={
76
+ "filepaths": [bibliographic_file],
77
+ "split": "train",
78
+ },
79
+ ),
80
+ ]
81
+
82
+ def _generate_examples(self, filepaths, split):
83
+
84
+ for filepath in filepaths:
85
+ df = pd.read_csv(filepath, header=None)
86
+
87
+ column_names = [
88
+ "ucid",
89
+ "country",
90
+ "doc_number",
91
+ "kind",
92
+ "lang",
93
+ "corrected_lang",
94
+ "date",
95
+ "family_id",
96
+ "date_produced",
97
+ "status",
98
+ "ecla_list",
99
+ "applicant_name_list",
100
+ "inventor_name_list",
101
+ "title_de_text",
102
+ "title_fr_text",
103
+ "title_en_text",
104
+ "abstract_de_exist",
105
+ "abstract_fr_exist",
106
+ "abstract_en_exist",
107
+ "description_de_exist",
108
+ "description_fr_exist",
109
+ "description_en_exist",
110
+ "claims_de_exist",
111
+ "claims_fr_exist",
112
+ "claims_en_exist",
113
+ ]
114
+ df.columns = column_names
115
+
116
+ df["date"] = pd.to_datetime(df["date"], format="%Y%m%d").astype(str)
117
+
118
+ df["date_produced"] = pd.to_datetime(
119
+ df["date_produced"], format="%Y%m%d"
120
+ ).astype(str)
121
+
122
+ boolean_columns = [
123
+ "abstract_de_exist",
124
+ "abstract_fr_exist",
125
+ "abstract_en_exist",
126
+ "description_de_exist",
127
+ "description_fr_exist",
128
+ "description_en_exist",
129
+ "claims_de_exist",
130
+ "claims_fr_exist",
131
+ "claims_en_exist",
132
+ ]
133
+ for col in boolean_columns:
134
+ df[col] = df[col].astype(bool)
135
+
136
+ for idx, row in df.iterrows():
137
+ yield idx, row.to_dict()