Update semi-text-c.py
Browse files- semi-text-c.py +40 -4
semi-text-c.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import datasets
|
3 |
import pandas as pd
|
4 |
-
|
5 |
|
6 |
class semiTextcConfig(datasets.BuilderConfig):
|
7 |
def __init__(self, features, data_url, **kwargs):
|
@@ -21,6 +21,21 @@ class semiTextc(datasets.GeneratorBasedBuilder):
|
|
21 |
},
|
22 |
data_url="https://huggingface.co/datasets/matchbench/semi-Text-c/resolve/main/",
|
23 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
]
|
25 |
|
26 |
def _info(self):
|
@@ -41,11 +56,32 @@ class semiTextc(datasets.GeneratorBasedBuilder):
|
|
41 |
)
|
42 |
for split in ["train", "valid", "test"]
|
43 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
def _generate_examples(self, path_file, split):
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
yield i, {
|
50 |
"ltable_id": row["ltable_id"],
|
51 |
"rtable_id": row["rtable_id"],
|
|
|
1 |
import os
|
2 |
import datasets
|
3 |
import pandas as pd
|
4 |
+
import json
|
5 |
|
6 |
class semiTextcConfig(datasets.BuilderConfig):
|
7 |
def __init__(self, features, data_url, **kwargs):
|
|
|
21 |
},
|
22 |
data_url="https://huggingface.co/datasets/matchbench/semi-Text-c/resolve/main/",
|
23 |
),
|
24 |
+
semiTextcConfig(
|
25 |
+
name="source",
|
26 |
+
features={
|
27 |
+
"content": datasets.Value("string"),
|
28 |
+
},
|
29 |
+
data_url="https://huggingface.co/datasets/matchbench/semi-homo/resolve/main/left.json",
|
30 |
+
),
|
31 |
+
|
32 |
+
semiTextcConfig(
|
33 |
+
name="target",
|
34 |
+
features={
|
35 |
+
"content": datasets.Value("string"),
|
36 |
+
},
|
37 |
+
data_url="https://huggingface.co/datasets/matchbench/semi-homo/resolve/main/right.txt",
|
38 |
+
),
|
39 |
]
|
40 |
|
41 |
def _info(self):
|
|
|
56 |
)
|
57 |
for split in ["train", "valid", "test"]
|
58 |
]
|
59 |
+
if self.config.name == "source":
|
60 |
+
return [datasets.SplitGenerator(name="source", gen_kwargs={
|
61 |
+
"path_file": dl_manager.download_and_extract(self.config.data_url), "split": "source", })]
|
62 |
+
|
63 |
+
if self.config.name == "target":
|
64 |
+
return [datasets.SplitGenerator(name="target", gen_kwargs={
|
65 |
+
"path_file": dl_manager.download_and_extract(self.config.data_url), "split": "target", })]
|
66 |
|
67 |
def _generate_examples(self, path_file, split):
|
68 |
+
if split in ['target']:
|
69 |
+
with open(path_file, "r") as f:
|
70 |
+
file = json.load(f)
|
71 |
+
for i in range(len(file)):
|
72 |
+
yield i, {
|
73 |
+
"content": file[i]
|
74 |
+
}
|
75 |
+
elif split in ['source']:
|
76 |
+
with open(path_file, "r") as f:
|
77 |
+
file = json.load(f)
|
78 |
+
for i in range(len(file)):
|
79 |
+
yield i, {
|
80 |
+
"content": file[i]
|
81 |
+
}
|
82 |
+
else:
|
83 |
+
file = pd.read_csv(path_file)
|
84 |
+
for i, row in file.iterrows():
|
85 |
yield i, {
|
86 |
"ltable_id": row["ltable_id"],
|
87 |
"rtable_id": row["rtable_id"],
|