Lara Martin commited on
Commit
3320c68
1 Parent(s): 4fbc307

adding corpus reader

Browse files
Files changed (1) hide show
  1. scificorpus.py +170 -0
scificorpus.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the 'License');
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an 'AS IS' BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+
18
+ import json
19
+
20
+ import datasets
21
+
22
+ _CITATION = '''
23
+ @inproceedings{Ammanabrolu2020AAAI,
24
+ title={Story Realization: Expanding Plot Events into Sentences},
25
+ author={Prithviraj Ammanabrolu and Ethan Tien and Wesley Cheung and Zhaochen Luo and William Ma and Lara J. Martin and Mark O. Riedl},
26
+ journal={Proceedings of the AAAI Conference on Artificial Intelligence (AAAI)},
27
+ year={2020},
28
+ volume={34},
29
+ number={05},
30
+ url={https://ojs.aaai.org//index.php/AAAI/article/view/6232}
31
+ }
32
+ '''
33
+
34
+ _DESCRIPTION = 'Loading script for the science fiction TV show plot dataset.'
35
+
36
+ _URLS = {"scifiTVshows":
37
+ 'https://huggingface.co/datasets/lara-martin/Scifi_TV_Shows/tree/main/scifiTVshows.zip'}
38
+
39
+ _INPUT_OUTPUT = ["all-sci-fi-data-test_input.txt", "all-sci-fi-data-test_output.txt", "all-sci-fi-data-train_input.txt", "all-sci-fi-data-train_output.txt", "all-sci-fi-data-val_input.txt", "all-sci-fi-data-val_output.txt"]
40
+
41
+
42
+ class ScifiTV(datasets.GeneratorBasedBuilder):
43
+ BUILDER_CONFIGS = [
44
+ datasets.BuilderConfig(
45
+ version=datasets.Version('1.1.0'),
46
+ name=lang,
47
+ description=f'Mr TyDi dataset in language {lang}.'
48
+ ) for lang in languages
49
+ ]
50
+
51
+ def _info(self):
52
+ features = datasets.Features({
53
+ 'event': datasets.Value('list'),
54
+ 'gen_event': datasets.Value('list'),
55
+ 'sent': datasets.Value('string'),
56
+ 'gen_sent': datasets.Value('string'),
57
+ 'story_num': datasets.Value('int'),
58
+ 'entities': datasets.Value('dict')
59
+ })
60
+
61
+ return datasets.DatasetInfo(
62
+ # This is the description that will appear on the datasets page.
63
+ description=_DESCRIPTION,
64
+ # This defines the different columns of the dataset and their types
65
+ features=features, # Here we define them above because they are different between the two configurations
66
+ supervised_keys=None,
67
+ # Homepage of the dataset for documentation
68
+ homepage='https://github.com/rajammanabrolu/StoryRealization',
69
+ # License for the dataset if available
70
+ license='The Creative Commons Attribution 4.0 International License. https://creativecommons.org/licenses/by/4.0/',
71
+ # Citation for the dataset
72
+ citation=_CITATION,
73
+ )
74
+
75
+ def _split_generators(self, dl_manager):
76
+ lang = self.config.name
77
+ downloaded_files = dl_manager.download_and_extract(_URLS)
78
+
79
+ splits = [
80
+ datasets.SplitGenerator(
81
+ name=datasets.Split.TEST,
82
+ gen_kwargs={
83
+ 'filepath': 'Test-Train-Val/all-sci-fi-data-test.txt',
84
+ },
85
+ ),
86
+ datasets.SplitGenerator(
87
+ name=datasets.Split.VALIDATION,
88
+ gen_kwargs={
89
+ 'filepath': 'Test-Train-Val/all-sci-fi-data-val.txt',
90
+ },
91
+ ),
92
+ datasets.SplitGenerator(
93
+ name=datasets.Split.TRAIN,
94
+ gen_kwargs={
95
+ 'filepath': 'Test-Train-Val/all-sci-fi-data-train.txt',
96
+ },
97
+ ),
98
+ datasets.SplitGenerator(
99
+ name="all",
100
+ gen_kwargs={
101
+ 'filepath': 'all-sci-fi-data.txt',
102
+ },
103
+ ),
104
+ """
105
+ datasets.SplitGenerator(
106
+ name="test-input",
107
+ gen_kwargs={
108
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-test_input.txt',
109
+ },
110
+ ),
111
+ datasets.SplitGenerator(
112
+ name="test-output",
113
+ gen_kwargs={
114
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-test_output.txt',
115
+ },
116
+ ),
117
+ datasets.SplitGenerator(
118
+ name="val-input",
119
+ gen_kwargs={
120
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-val_input.txt',
121
+ },
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name="val-input",
125
+ gen_kwargs={
126
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-val_output.txt',
127
+ },
128
+ ),
129
+ datasets.SplitGenerator(
130
+ name="train-input",
131
+ gen_kwargs={
132
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-train_input.txt',
133
+ },
134
+ ),
135
+ datasets.SplitGenerator(
136
+ name="train-input",
137
+ gen_kwargs={
138
+ 'filepath': 'Input_OutputFiles/all-sci-fi-data-train_output.txt',
139
+ },
140
+ ),
141
+ """
142
+ ]
143
+ return splits
144
+
145
+ def _generate_examples(self, filepath):
146
+ story_count = 0
147
+ with open(filepath, encoding="utf-8") as f:
148
+ story = []
149
+ for id_, line in enumerate(f):
150
+ if "%%%%%%" in line:
151
+ for l in story:
152
+ event, gen_event, sent, gen_sent = l.split("|||")
153
+ line = line.replace("%%%%%%%%%%%%%%%%%", "")
154
+ line = line.replace("defaultdict(<type 'list'>, ", "")[:-1]
155
+ entities = eval(line)
156
+ yield id_, {
157
+ 'event': eval(event),
158
+ 'gen_event': eval(gen_event),
159
+ 'sent': sent,
160
+ 'gen_sent': gen_sent,
161
+ 'story_num': story_count,
162
+ 'entities': entities,
163
+ }
164
+ story = []
165
+ story_count+=1
166
+ elif "<EOS>" in line: continue
167
+ else:
168
+ story.append(line.strip())
169
+
170
+