def printCharacters(resources, callback): actorFirstLineIterator = ActorFirstLineIterator() actorFirstLineIterator.loadTranscript(resources['transcript']) phraseLookup = PhraseTimestampLookup() phraseLookup.loadSubtitles(resources['subs']) for actor, line in actorFirstLineIterator.getActorFirstLines(): timestamp = phraseLookup.getTimestamp(line) if timestamp < 0: if DEBUG: print 'ERROR', "couldn't find line \"%s\" said by %s" %(line, actor) pass else: callback(actor, timestamp)
def testActorFirstLineIterator(): actorFirstLineIterator = ActorFirstLineIterator() (actor, line) = actorFirstLineIterator.parseLine_('sduihfsduhfs') assertEquals(actor, None) (actor, phrase) = actorFirstLineIterator.parseLine_('<<Sally: I like farts>>\n') assertEquals(actor, 'Sally') assertEquals(phrase, 'I like farts') (actor, phrase) = actorFirstLineIterator.parseLine_('<<Sally: <farting> I like farts (loudly)>>\n') assertEquals(actor, 'Sally') assertEquals(phrase, 'I like farts') actorFirstLineIterator.loadTranscript('data/test_transcript.txt') results = [result for result in actorFirstLineIterator.getActorFirstLines()] assertEquals(results[0][0], 'Pippin') assertEquals(results[0][1], 'Hey!') assertEquals(results[1][0], 'Merry') assertEquals(results[1][1], 'Over here!') assertEquals(results[2][0], 'Legolas') assertEquals(results[2][1], 'The Horn of Gondor!') assertEquals(results[3][0], 'Aragorn') assertEquals(results[3][1], 'Boromir!') assertEquals(len(results), 4)