jmnybl commited on
Commit
2be6a42
1 Parent(s): fee3330

data loader

Browse files
Files changed (1) hide show
  1. turku_hockey_data2text.py +24 -1
turku_hockey_data2text.py CHANGED
@@ -18,6 +18,7 @@
18
  import csv
19
  import json
20
  import os
 
21
 
22
  import datasets
23
 
@@ -100,6 +101,7 @@ class TurkuHockeyData2Text(datasets.GeneratorBasedBuilder):
100
  "time": datasets.Value("string"),
101
  "penalty_minutes": datasets.Value("string"),
102
  "saves": datasets.Value("string"),
 
103
  }
104
  ),
105
  }
@@ -148,7 +150,7 @@ class TurkuHockeyData2Text(datasets.GeneratorBasedBuilder):
148
 
149
  def _generate_features(self, example):
150
  _events = []
151
- for e in example["events"]:
152
  d = {"event_id": e["event_id"],
153
  "event_type": e["event_type"],
154
  "text": e["text"] if e["text"] != None else "",
@@ -164,7 +166,28 @@ class TurkuHockeyData2Text(datasets.GeneratorBasedBuilder):
164
  "time": e.get("time", ""),
165
  "penalty_minutes": e.get("penalty_minutes", ""),
166
  "saves": e.get("saves", ""),
 
167
  }
168
  _events.append(d)
169
  example["events"] = _events
170
  return example
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  import csv
19
  import json
20
  import os
21
+ import re
22
 
23
  import datasets
24
 
 
101
  "time": datasets.Value("string"),
102
  "penalty_minutes": datasets.Value("string"),
103
  "saves": datasets.Value("string"),
104
+ "multi_reference": datasets.Value("bool")
105
  }
106
  ),
107
  }
 
150
 
151
  def _generate_features(self, example):
152
  _events = []
153
+ for i, e in enumerate(example["events"]):
154
  d = {"event_id": e["event_id"],
155
  "event_type": e["event_type"],
156
  "text": e["text"] if e["text"] != None else "",
 
166
  "time": e.get("time", ""),
167
  "penalty_minutes": e.get("penalty_minutes", ""),
168
  "saves": e.get("saves", ""),
169
+ "multi_reference": self._is_multireference(i, example["events"])
170
  }
171
  _events.append(d)
172
  example["events"] = _events
173
  return example
174
+
175
+ def _is_multireference(self, i, events):
176
+ """ Return True if this event is one of the multireference events (multiple events refer to the same text passage)
177
+ Otherwise, return False.
178
+ """
179
+ if events[i]["text"] == None:
180
+ return False
181
+ multireference = re.compile("E[0-9]+")
182
+ if multireference.match(events[i]["text"]):
183
+ return True
184
+ # can be first of the multireference events (the one including the actual text passage)
185
+ multi_events = []
186
+ for event in events:
187
+ if event["text"] == None:
188
+ continue
189
+ if multireference.match(event["text"]):
190
+ multi_events.append(event["text"])
191
+ if events[i]["event_id"] in multi_events:
192
+ return True
193
+ return False