ruanchaves commited on
Commit
d421e49
1 Parent(s): 8d3e782

Upload snap.py

Browse files
Files changed (1) hide show
  1. snap.py +53 -0
snap.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SNAP dataset"""
2
+
3
+ import datasets
4
+
5
+ _CITATION = """
6
+ @inproceedings{celebi2016segmenting,
7
+ title={Segmenting hashtags using automatically created training data},
8
+ author={Celebi, Arda and {\"O}zg{\"u}r, Arzucan},
9
+ booktitle={Proceedings of the Tenth International Conference on Language Resources and Evaluation (LREC'16)},
10
+ pages={2981--2985},
11
+ year={2016}
12
+ }
13
+ """
14
+
15
+ _DESCRIPTION = """
16
+ Automatically segmented 803K SNAP Twitter Data Set hashtags with the heuristic described in the paper "Segmenting hashtags using automatically created training data".
17
+ """
18
+ _URL = "https://raw.githubusercontent.com/ruanchaves/hashformers/master/datasets/SNAP.Hashtags.Segmented.w.Heuristics.txt"
19
+
20
+ class Snap(datasets.GeneratorBasedBuilder):
21
+
22
+ VERSION = datasets.Version("1.0.0")
23
+
24
+ def _info(self):
25
+ return datasets.DatasetInfo(
26
+ description=_DESCRIPTION,
27
+ features=datasets.Features(
28
+ {
29
+ "index": datasets.Value("int32"),
30
+ "hashtag": datasets.Value("string"),
31
+ "segmentation": datasets.Value("string")
32
+ }
33
+ ),
34
+ supervised_keys=None,
35
+ homepage="https://github.com/ardax/hashtag-segmentor",
36
+ citation=_CITATION,
37
+ )
38
+
39
+ def _split_generators(self, dl_manager):
40
+ downloaded_files = dl_manager.download(_URL)
41
+ return [
42
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
43
+ ]
44
+
45
+ def _generate_examples(self, filepath):
46
+
47
+ with open(filepath, 'r') as f:
48
+ for idx, line in enumerate(f):
49
+ yield idx, {
50
+ "index": idx,
51
+ "hashtag": line.strip().replace(" ", ""),
52
+ "segmentation": line.strip()
53
+ }