amylonidis commited on
Commit
ad3021c
·
verified ·
1 Parent(s): cdb3d46

Update clefip2011.py

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