|
"""The Loyola University of Delaware Identifier Splitting Oracle"""
|
|
|
|
import datasets
|
|
import pandas as pd
|
|
from collections import deque
|
|
|
|
_CITATION = """
|
|
@article{hill2014empirical,
|
|
title={An empirical study of identifier splitting techniques},
|
|
author={Hill, Emily and Binkley, David and Lawrie, Dawn and Pollock, Lori and Vijay-Shanker, K},
|
|
journal={Empirical Software Engineering},
|
|
volume={19},
|
|
number={6},
|
|
pages={1754--1780},
|
|
year={2014},
|
|
publisher={Springer}
|
|
}
|
|
"""
|
|
|
|
_DESCRIPTION = """
|
|
In programming languages, identifiers are tokens (also called symbols) which name language entities.
|
|
Some of the kinds of entities an identifier might denote include variables, types, labels, subroutines, and packages.
|
|
|
|
The Loyola University of Delaware Identifier Splitting Oracle is a dataset for identifier segmentation,
|
|
i.e. the task of adding spaces between the words on a identifier.
|
|
"""
|
|
_URL = "https://raw.githubusercontent.com/ruanchaves/hashformers/master/datasets/loyola-udelaware-identifier-splitting-oracle.txt"
|
|
|
|
class Loyola(datasets.GeneratorBasedBuilder):
|
|
|
|
VERSION = datasets.Version("1.0.0")
|
|
|
|
def _info(self):
|
|
return datasets.DatasetInfo(
|
|
description=_DESCRIPTION,
|
|
features=datasets.Features(
|
|
{
|
|
"index": datasets.Value("int32"),
|
|
"identifier": datasets.Value("string"),
|
|
"segmentation": datasets.Value("string"),
|
|
"language": datasets.Value("string"),
|
|
"source": datasets.Value("string")
|
|
}
|
|
),
|
|
supervised_keys=None,
|
|
homepage="http://www.cs.loyola.edu/~binkley/ludiso/",
|
|
citation=_CITATION,
|
|
)
|
|
|
|
def _split_generators(self, dl_manager):
|
|
downloaded_files = dl_manager.download(_URL)
|
|
return [
|
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files}),
|
|
]
|
|
|
|
def _generate_examples(self, filepath):
|
|
|
|
def get_segmentation(needle, haystack, sep="-"):
|
|
counter = 0
|
|
pos = deque()
|
|
iterator = iter(haystack)
|
|
for char in needle:
|
|
if char == sep:
|
|
pos.appendleft(counter)
|
|
continue
|
|
while True:
|
|
try:
|
|
next_char = next(iterator)
|
|
counter += 1
|
|
if next_char == char:
|
|
break
|
|
except StopIteration:
|
|
break
|
|
output = haystack
|
|
while pos:
|
|
next_pos = pos.popleft()
|
|
output = output[:next_pos] + " " + output[next_pos:]
|
|
return output
|
|
|
|
with open(filepath, 'r') as f:
|
|
records = f.read().split("\n")
|
|
records = [x for x in records if x]
|
|
records = [x.split(" ") for x in records]
|
|
|
|
for idx, item in enumerate(records):
|
|
yield idx, {
|
|
"index": idx,
|
|
"identifier": item[1],
|
|
"segmentation": get_segmentation(item[4], item[1]),
|
|
"language": item[2],
|
|
"source": item[3],
|
|
} |