3 | 3 |
# TODO
|
4 | 4 |
|
5 | 5 |
# Diction:
|
6 | |
# - At the start of a paragraph, as well as telling us where a character
|
7 | |
# is if it's not obvious, also include significant memories they
|
8 | |
# acquired in the last paragraph -- such as finding a revolver in the bed
|
9 | 6 |
# - use indef art when they have no memory of an item that they see
|
10 | 7 |
# - dramatic irony would be really nice, but hard to pull off. Well, a certain
|
11 | 8 |
# amount happens naturally now, with character pov. but more could be done
|
|
172 | 169 |
self.events = list(reversed(collector.events))
|
173 | 170 |
self.main_characters = main_characters
|
174 | 171 |
self.pov_index = 0
|
|
172 |
self.transformers = []
|
175 | 173 |
# maps main characters to where they currently are (omnisciently)
|
176 | 174 |
self.character_location = {}
|
177 | 175 |
# maps main characters to where the reader last saw them
|
178 | 176 |
self.last_seen_at = {}
|
179 | |
self.transformers = []
|
180 | 177 |
# maps characters to things that happened to them while not narrated
|
181 | 178 |
self.exciting_developments = {}
|
182 | 179 |
|
|
184 | 181 |
self.transformers.append(transformer)
|
185 | 182 |
|
186 | 183 |
def publish(self):
|
|
184 |
paragraph_num = 1
|
187 | 185 |
while len(self.events) > 0:
|
188 | 186 |
pov_actor = self.main_characters[self.pov_index]
|
189 | 187 |
paragraph_events = self.generate_paragraph_events(pov_actor)
|
190 | 188 |
for transformer in self.transformers:
|
191 | 189 |
if paragraph_events:
|
192 | |
paragraph_events = transformer.transform(self, paragraph_events)
|
|
190 |
paragraph_events = transformer.transform(
|
|
191 |
self, paragraph_events, paragraph_num
|
|
192 |
)
|
193 | 193 |
self.publish_paragraph(paragraph_events)
|
194 | 194 |
self.pov_index += 1
|
195 | 195 |
if self.pov_index >= len(self.main_characters):
|
196 | 196 |
self.pov_index = 0
|
|
197 |
paragraph_num += 1
|
197 | 198 |
|
198 | 199 |
def generate_paragraph_events(self, pov_actor):
|
199 | 200 |
quota = random.randint(10, 25)
|
|
247 | 248 |
# you have two characters, Bob Jones and Bob Smith, and both are
|
248 | 249 |
# named 'Bob', and they are actually two different events... but...
|
249 | 250 |
# for now that is an edge case.
|
250 | |
def transform(self, editor, incoming_events):
|
|
251 |
def transform(self, editor, incoming_events, paragraph_num):
|
251 | 252 |
events = []
|
252 | 253 |
for event in incoming_events:
|
253 | 254 |
if events:
|
|
266 | 267 |
|
267 | 268 |
class UsePronounsTransformer(Transformer):
|
268 | 269 |
# replace repeated proper nouns with pronouns
|
269 | |
def transform(self, editor, incoming_events):
|
|
270 |
def transform(self, editor, incoming_events, paragraph_num):
|
270 | 271 |
events = []
|
271 | 272 |
for event in incoming_events:
|
272 | 273 |
if events:
|
|
279 | 280 |
|
280 | 281 |
|
281 | 282 |
class MadeTheirWayToTransformer(Transformer):
|
282 | |
def transform(self, editor, incoming_events):
|
|
283 |
def transform(self, editor, incoming_events, paragraph_num):
|
283 | 284 |
events = []
|
284 | 285 |
for event in incoming_events:
|
285 | 286 |
if (events and
|
|
307 | 308 |
return events
|
308 | 309 |
|
309 | 310 |
|
|
311 |
# well well well
|
|
312 |
from swallows.engine.objects import Actor
|
|
313 |
weather = Actor('the weather')
|
|
314 |
|
|
315 |
|
|
316 |
class AddWeatherFrifferyTransformer(Transformer):
|
|
317 |
def transform(self, editor, incoming_events, paragraph_num):
|
|
318 |
events = []
|
|
319 |
if paragraph_num == 1:
|
|
320 |
choice = random.randint(0, 3)
|
|
321 |
if choice == 0:
|
|
322 |
events.append(Event("It was raining", [weather]))
|
|
323 |
if choice == 1:
|
|
324 |
events.append(Event("It was snowing", [weather]))
|
|
325 |
if choice == 2:
|
|
326 |
events.append(Event("The sun was shining", [weather]))
|
|
327 |
if choice == 3:
|
|
328 |
events.append(Event("The day was overcast and humid", [weather]))
|
|
329 |
return events + incoming_events
|
|
330 |
|
|
331 |
|
|
332 |
class AddParagraphStartFrifferyTransformer(Transformer):
|
|
333 |
def transform(self, editor, incoming_events, paragraph_num):
|
|
334 |
first_event = incoming_events[0]
|
|
335 |
if paragraph_num == 1:
|
|
336 |
return incoming_events
|
|
337 |
if str(first_event).startswith("'"):
|
|
338 |
return incoming_events
|
|
339 |
if " had found " in str(first_event):
|
|
340 |
return incoming_events
|
|
341 |
if " was in " in str(first_event):
|
|
342 |
return incoming_events
|
|
343 |
choice = random.randint(0, 8)
|
|
344 |
if choice == 0:
|
|
345 |
first_event = first_event.rephrase(
|
|
346 |
"Later on, " + first_event.phrase
|
|
347 |
)
|
|
348 |
if choice == 1:
|
|
349 |
first_event = first_event.rephrase(
|
|
350 |
"Suddenly, " + first_event.phrase
|
|
351 |
)
|
|
352 |
if choice == 2:
|
|
353 |
first_event = first_event.rephrase(
|
|
354 |
"After a moment's consideration, " + first_event.phrase
|
|
355 |
)
|
|
356 |
if choice == 3:
|
|
357 |
first_event = first_event.rephrase(
|
|
358 |
"Feeling anxious, " + first_event.phrase
|
|
359 |
)
|
|
360 |
return [first_event] + incoming_events[1:]
|
|
361 |
|
|
362 |
|
310 | 363 |
class AggregateEventsTransformer(Transformer):
|
311 | 364 |
# replace "Bob went to the kitchen. Bob saw the toaster"
|
312 | 365 |
# with "Bob went to the kitchen, where he saw the toaster"
|
313 | |
def transform(self, editor, incoming_events):
|
|
366 |
def transform(self, editor, incoming_events, paragraph_num):
|
314 | 367 |
events = []
|
315 | 368 |
for event in incoming_events:
|
316 | 369 |
if events:
|
|
334 | 387 |
class DetectWanderingTransformer(Transformer):
|
335 | 388 |
# not used yet
|
336 | 389 |
# if they 'made their way' to their current location...
|
337 | |
def transform(self, editor, incoming_events):
|
|
390 |
def transform(self, editor, incoming_events, paragraph_num):
|
338 | 391 |
events = []
|
339 | 392 |
for event in incoming_events:
|
340 | 393 |
if (event.phrase == '<1> made <his-1> way to <2>' and
|
|
395 | 448 |
editor.add_transformer(AggregateEventsTransformer())
|
396 | 449 |
editor.add_transformer(DetectWanderingTransformer())
|
397 | 450 |
# this one should be last, so prior transformers don't
|
398 | |
# have to worry themselved about looking for pronouns
|
|
451 |
# have to worry themselves about looking for pronouns
|
399 | 452 |
editor.add_transformer(UsePronounsTransformer())
|
|
453 |
# this should be a matter of configuring what transformers
|
|
454 |
# to use, when you instantiate a Publisher
|
|
455 |
if self.friffery:
|
|
456 |
editor.add_transformer(AddWeatherFrifferyTransformer())
|
|
457 |
editor.add_transformer(AddParagraphStartFrifferyTransformer())
|
400 | 458 |
editor.publish()
|
401 | 459 |
|
402 | 460 |
def publish(self):
|