Upload CodeSwitching-TE-EN.py
Browse files- CodeSwitching-TE-EN.py +55 -36
CodeSwitching-TE-EN.py
CHANGED
@@ -48,18 +48,33 @@ class TeEnCodeSwitch(datasets.GeneratorBasedBuilder):
|
|
48 |
"ner_tags": datasets.Sequence(
|
49 |
datasets.features.ClassLabel(
|
50 |
names=[
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
]
|
61 |
)
|
62 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
),
|
65 |
supervised_keys=None,
|
@@ -85,30 +100,34 @@ class TeEnCodeSwitch(datasets.GeneratorBasedBuilder):
|
|
85 |
]
|
86 |
|
87 |
def _generate_examples(self, filepath):
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
48 |
"ner_tags": datasets.Sequence(
|
49 |
datasets.features.ClassLabel(
|
50 |
names=[
|
51 |
+
"NOUN",
|
52 |
+
"PUNCT",
|
53 |
+
"ADP",
|
54 |
+
"NUM",
|
55 |
+
"SYM",
|
56 |
+
"SCONJ",
|
57 |
+
"ADJ",
|
58 |
+
"PART",
|
59 |
+
"DET",
|
60 |
+
"CCONJ",
|
61 |
+
"PROPN",
|
62 |
+
"PRON",
|
63 |
+
"X",
|
64 |
+
"_",
|
65 |
+
"ADV",
|
66 |
+
"INTJ",
|
67 |
+
"VERB",
|
68 |
+
"AUX",
|
69 |
]
|
70 |
)
|
71 |
),
|
72 |
+
"xpos": datasets.Sequence(datasets.Value("string")),
|
73 |
+
"feats": datasets.Sequence(datasets.Value("string")),
|
74 |
+
"head": datasets.Sequence(datasets.Value("string")),
|
75 |
+
"deprel": datasets.Sequence(datasets.Value("string")),
|
76 |
+
"deps": datasets.Sequence(datasets.Value("string")),
|
77 |
+
"misc": datasets.Sequence(datasets.Value("string")),
|
78 |
}
|
79 |
),
|
80 |
supervised_keys=None,
|
|
|
100 |
]
|
101 |
|
102 |
def _generate_examples(self, filepath):
|
103 |
+
id = 0
|
104 |
+
for path in filepath:
|
105 |
+
with open(path, "r", encoding="utf-8") as data_file:
|
106 |
+
tokenlist = list(conllu.parse_incr(data_file))
|
107 |
+
for sent in tokenlist:
|
108 |
+
if "sent_id" in sent.metadata:
|
109 |
+
idx = sent.metadata["sent_id"]
|
110 |
+
else:
|
111 |
+
idx = id
|
112 |
+
|
113 |
+
tokens = [token["form"] for token in sent]
|
114 |
+
|
115 |
+
if "text" in sent.metadata:
|
116 |
+
txt = sent.metadata["text"]
|
117 |
+
else:
|
118 |
+
txt = " ".join(tokens)
|
119 |
+
|
120 |
+
yield id, {
|
121 |
+
"idx": str(idx),
|
122 |
+
"text": txt,
|
123 |
+
"tokens": [token["form"] for token in sent],
|
124 |
+
"lemmas": [token["lemma"] for token in sent],
|
125 |
+
"upos": [token["upos"] for token in sent],
|
126 |
+
"xpos": [token["xpos"] for token in sent],
|
127 |
+
"feats": [str(token["feats"]) for token in sent],
|
128 |
+
"head": [str(token["head"]) for token in sent],
|
129 |
+
"deprel": [str(token["deprel"]) for token in sent],
|
130 |
+
"deps": [str(token["deps"]) for token in sent],
|
131 |
+
"misc": [str(token["misc"]) for token in sent],
|
132 |
+
}
|
133 |
+
id += 1
|