Datasets:
ruanchaves
commited on
Commit
·
da6c6fa
1
Parent(s):
18eba7f
Upload loyola.py
Browse files
loyola.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""The Loyola University of Delaware Identifier Splitting Oracle"""
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import pandas as pd
|
5 |
+
from collections import deque
|
6 |
+
|
7 |
+
_CITATION = """
|
8 |
+
@article{hill2014empirical,
|
9 |
+
title={An empirical study of identifier splitting techniques},
|
10 |
+
author={Hill, Emily and Binkley, David and Lawrie, Dawn and Pollock, Lori and Vijay-Shanker, K},
|
11 |
+
journal={Empirical Software Engineering},
|
12 |
+
volume={19},
|
13 |
+
number={6},
|
14 |
+
pages={1754--1780},
|
15 |
+
year={2014},
|
16 |
+
publisher={Springer}
|
17 |
+
}
|
18 |
+
"""
|
19 |
+
|
20 |
+
_DESCRIPTION = """
|
21 |
+
In programming languages, identifiers are tokens (also called symbols) which name language entities.
|
22 |
+
Some of the kinds of entities an identifier might denote include variables, types, labels, subroutines, and packages.
|
23 |
+
|
24 |
+
The Loyola University of Delaware Identifier Splitting Oracle is a dataset for identifier segmentation,
|
25 |
+
i.e. the task of adding spaces between the words on a identifier.
|
26 |
+
"""
|
27 |
+
_URL = "https://raw.githubusercontent.com/ruanchaves/hashformers/master/datasets/loyola-udelaware-identifier-splitting-oracle.txt"
|
28 |
+
|
29 |
+
class Loyola(datasets.GeneratorBasedBuilder):
|
30 |
+
|
31 |
+
VERSION = datasets.Version("1.0.0")
|
32 |
+
|
33 |
+
def _info(self):
|
34 |
+
return datasets.DatasetInfo(
|
35 |
+
description=_DESCRIPTION,
|
36 |
+
features=datasets.Features(
|
37 |
+
{
|
38 |
+
"index": datasets.Value("int32"),
|
39 |
+
"identifier": datasets.Value("string"),
|
40 |
+
"segmentation": datasets.Value("string"),
|
41 |
+
"language": datasets.Value("string"),
|
42 |
+
"source": datasets.Value("string")
|
43 |
+
}
|
44 |
+
),
|
45 |
+
supervised_keys=None,
|
46 |
+
homepage="http://www.cs.loyola.edu/~binkley/ludiso/",
|
47 |
+
citation=_CITATION,
|
48 |
+
)
|
49 |
+
|
50 |
+
def _split_generators(self, dl_manager):
|
51 |
+
downloaded_files = dl_manager.download(_URL)
|
52 |
+
return [
|
53 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files}),
|
54 |
+
]
|
55 |
+
|
56 |
+
def _generate_examples(self, filepath):
|
57 |
+
|
58 |
+
def get_segmentation(needle, haystack, sep="-"):
|
59 |
+
counter = 0
|
60 |
+
pos = deque()
|
61 |
+
iterator = iter(haystack)
|
62 |
+
for char in needle:
|
63 |
+
if char == sep:
|
64 |
+
pos.appendleft(counter)
|
65 |
+
continue
|
66 |
+
while True:
|
67 |
+
try:
|
68 |
+
next_char = next(iterator)
|
69 |
+
counter += 1
|
70 |
+
if next_char == char:
|
71 |
+
break
|
72 |
+
except StopIteration:
|
73 |
+
break
|
74 |
+
output = haystack
|
75 |
+
while pos:
|
76 |
+
next_pos = pos.popleft()
|
77 |
+
output = output[:next_pos] + " " + output[next_pos:]
|
78 |
+
return output
|
79 |
+
|
80 |
+
with open(filepath, 'r') as f:
|
81 |
+
records = f.read().split("\n")
|
82 |
+
records = [x for x in records if x]
|
83 |
+
records = [x.split(" ") for x in records]
|
84 |
+
|
85 |
+
for idx, item in enumerate(records):
|
86 |
+
yield idx, {
|
87 |
+
"index": idx,
|
88 |
+
"identifier": item[1],
|
89 |
+
"segmentation": get_segmentation(item[4], item[1]),
|
90 |
+
"language": item[2],
|
91 |
+
"source": item[3],
|
92 |
+
}
|