Datasets:

Languages:
code
Multilinguality:
monolingual
Size Categories:
unknown
Language Creators:
machine-generated
Annotations Creators:
expert-generated
Source Datasets:
original
Tags:
word-segmentation
License:
ruanchaves commited on
Commit
e34d40c
1 Parent(s): a6ed06a

Upload bt11.py

Browse files
Files changed (1) hide show
  1. bt11.py +87 -0
bt11.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """BT11"""
2
+
3
+ import datasets
4
+ import pandas as pd
5
+ from collections import deque
6
+
7
+ _CITATION = """
8
+ @inproceedings{li2018helpful,
9
+ title={Helpful or Not? An investigation on the feasibility of identifier splitting via CNN-BiLSTM-CRF.},
10
+ author={Li, Jiechu and Du, Qingfeng and Shi, Kun and He, Yu and Wang, Xin and Xu, Jincheng},
11
+ booktitle={SEKE},
12
+ pages={175--174},
13
+ year={2018}
14
+ }
15
+ """
16
+
17
+ _DESCRIPTION = """
18
+ In programming languages, identifiers are tokens (also called symbols) which name language entities.
19
+ Some of the kinds of entities an identifier might denote include variables, types, labels, subroutines, and packages.
20
+
21
+ BT11 is a dataset for identifier segmentation,
22
+ i.e. the task of adding spaces between the words on a identifier.
23
+ """
24
+ _URL = "https://raw.githubusercontent.com/ruanchaves/hashformers/master/datasets/bt11.csv"
25
+
26
+ class BT11(datasets.GeneratorBasedBuilder):
27
+
28
+ VERSION = datasets.Version("1.0.0")
29
+
30
+ def _info(self):
31
+ return datasets.DatasetInfo(
32
+ description=_DESCRIPTION,
33
+ features=datasets.Features(
34
+ {
35
+ "index": datasets.Value("int32"),
36
+ "identifier": datasets.Value("string"),
37
+ "segmentation": datasets.Value("string")
38
+ }
39
+ ),
40
+ supervised_keys=None,
41
+ homepage="",
42
+ citation=_CITATION,
43
+ )
44
+
45
+ def _split_generators(self, dl_manager):
46
+ downloaded_files = dl_manager.download(_URL)
47
+ return [
48
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files}),
49
+ ]
50
+
51
+ def _generate_examples(self, filepath):
52
+
53
+ def get_segmentation(needle, haystack, sep="-"):
54
+ print(needle, haystack)
55
+ output = haystack
56
+ needle = needle.lower()
57
+ haystack = haystack.lower()
58
+ counter = 0
59
+ pos = deque()
60
+ iterator = iter(haystack)
61
+ for char in needle:
62
+ if char == sep:
63
+ pos.appendleft(counter)
64
+ continue
65
+ while True:
66
+ try:
67
+ next_char = next(iterator)
68
+ counter += 1
69
+ if next_char == char:
70
+ break
71
+ except StopIteration:
72
+ break
73
+ while pos:
74
+ next_pos = pos.popleft()
75
+ output = output[:next_pos] + " " + output[next_pos:]
76
+ return output
77
+
78
+ df = pd.read_csv(filepath, header=None)[[0,1]]
79
+ df = df.dropna()
80
+ records = df.to_dict("records")
81
+
82
+ for idx, item in enumerate(records):
83
+ yield idx, {
84
+ "index": idx,
85
+ "identifier": item[0],
86
+ "segmentation": get_segmentation(item[1], item[0])
87
+ }