Commit
·
dfc54ec
1
Parent(s):
5fba3cb
Update lynx.py
Browse files
lynx.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
"""
|
2 |
|
3 |
import datasets
|
4 |
import pandas as pd
|
@@ -34,7 +34,8 @@ class Lynx(datasets.GeneratorBasedBuilder):
|
|
34 |
{
|
35 |
"index": datasets.Value("int32"),
|
36 |
"identifier": datasets.Value("string"),
|
37 |
-
"segmentation": datasets.Value("string")
|
|
|
38 |
}
|
39 |
),
|
40 |
supervised_keys=None,
|
@@ -50,14 +51,31 @@ class Lynx(datasets.GeneratorBasedBuilder):
|
|
50 |
|
51 |
def _generate_examples(self, filepath):
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
with open(filepath, "r") as f:
|
54 |
|
55 |
for idx, line in enumerate(f):
|
56 |
fields = line.split(":")
|
57 |
identifier = fields[0].strip()
|
58 |
-
|
59 |
yield idx, {
|
60 |
"index": idx,
|
61 |
"identifier": identifier,
|
62 |
-
"segmentation":
|
|
|
63 |
}
|
|
|
1 |
+
"""BT11"""
|
2 |
|
3 |
import datasets
|
4 |
import pandas as pd
|
|
|
34 |
{
|
35 |
"index": datasets.Value("int32"),
|
36 |
"identifier": datasets.Value("string"),
|
37 |
+
"segmentation": datasets.Value("string"),
|
38 |
+
"expansion": datasets.Value("string")
|
39 |
}
|
40 |
),
|
41 |
supervised_keys=None,
|
|
|
51 |
|
52 |
def _generate_examples(self, filepath):
|
53 |
|
54 |
+
def get_segmentation(needle, haystack):
|
55 |
+
output = ""
|
56 |
+
haystack = iter(haystack)
|
57 |
+
for char in needle:
|
58 |
+
while True:
|
59 |
+
try:
|
60 |
+
next_char = next(haystack)
|
61 |
+
if next_char == char:
|
62 |
+
output += next_char
|
63 |
+
break
|
64 |
+
elif next_char.isspace():
|
65 |
+
output += next_char
|
66 |
+
except StopIteration:
|
67 |
+
break
|
68 |
+
return output
|
69 |
+
|
70 |
with open(filepath, "r") as f:
|
71 |
|
72 |
for idx, line in enumerate(f):
|
73 |
fields = line.split(":")
|
74 |
identifier = fields[0].strip()
|
75 |
+
expansion = fields[1].strip()
|
76 |
yield idx, {
|
77 |
"index": idx,
|
78 |
"identifier": identifier,
|
79 |
+
"segmentation": get_segmentation(identifier, expansion),
|
80 |
+
"expansion": expansion
|
81 |
}
|