def output_cloze_import(infinitive, tense, translation, sound, conj): ''' Combines the output of the output_cloze function with optional translation and sound fields and combines them to produce the format required for Anki's import function ''' cloze = output_cloze(infinitive, tense, conj) if translation: add_trn = [ cz + ('|{}'.format(trn)) for cz, trn in zip(cloze, translation) ] else: add_trn = [cz + '|' for cz in cloze] if sound: add_snd = [ trn + ('|[sound:{}]'.format(snd)) for trn, snd in zip(add_trn, sound) ] else: add_snd = [trn + '|' for trn in add_trn] add_tag = [snd + ('|{}'.format(infinitive)) for snd in add_snd] return Category._make(add_tag)
def construct_compound_tense_subjunctive(infinitive, tense): past_participle = _construct_past_participle(infinitive) inflection = [("qu'" if f(aux)[0] in _VOWELS else 'que', f(aux), aux, past_participle) for f, aux in zip(_PRONOUNS, _COMPOUND_TENSE[tense])] return Category._make(inflection)
def test_cloze_import(self): expected = Category._make([ 'je {{c1::parle::parler, présent}}|I speak|[sound:je parle.mp3]|parler', 'tu {{c1::parles::parler, présent}}|you speak|[sound:tu parles.mp3]|parler', 'il/elle/on {{c1::parle::parler, présent}}|he/she/it speaks|[sound:il parle.mp3]|parler', 'nous {{c1::parlons::parler, présent}}|we speak|[sound:nous parlons.mp3]|parler', 'vous {{c1::parlez::parler, présent}}|you speak|[sound:vous parlez.mp3]|parler', 'ils/elles {{c1::parlent::parler, présent}}|they speak|[sound:ils parlent.mp3]|parler' ]) translation = [ 'I speak', 'you speak', 'he/she/it speaks', 'we speak', 'you speak', 'they speak' ] sound = [ 'je parle.mp3', 'tu parles.mp3', 'il parle.mp3', 'nous parlons.mp3', 'vous parlez.mp3', 'ils parlent.mp3' ] conj = French.construct_inflection('parler', 'présent') actual = French.output_cloze_import('parler', 'présent', translation, sound, conj) with self.subTest(): self.assertEqual(expected.fps, actual.fps) self.assertEqual(expected.sps, actual.sps) self.assertEqual(expected.tps, actual.tps) self.assertEqual(expected.fpp, actual.fpp) self.assertEqual(expected.spp, actual.spp) self.assertEqual(expected.tpp, actual.tpp)
def output_cloze(infinitive, tense, conj): ''' Combines the different parts of a verb conjugation with Anki's required formatting to produce a form suitable for a cloze-deletion card ''' result = [] # TODO - make this pythonic, it's an ugly hack as it is for i, item in enumerate(conj): if i == 0 and infinitive[0] in _VOWELS: result.append( _FPS_CLOZE_FORMAT.format(item[0], item[1], infinitive, tense)) else: result.append( _STD_CLOZE_FORMAT.format(item[0], item[1], infinitive, tense)) return Category._make(result)
def output_cloze(infinitive, tense, conj): ''' Combines the different parts of a verb conjugation with Anki's required formatting to produce a form suitable for a cloze-deletion card ''' result = [] # TODO - make this pythonic, it's an ugly hack as it is for i, item in enumerate(conj): if i == 0 and infinitive[0] in _VOWELS: result.append(_FPS_CLOZE_FORMAT.format(item[0], item[1], infinitive, tense)) else: result.append(_STD_CLOZE_FORMAT.format(item[0], item[1], infinitive, tense)) return Category._make(result)
def test_cloze_verb_begins_with_vowel(self): expected =\ Category._make(["j'{{c1::abandonne::abandonner, présent}}", 'tu {{c1::abandonnes::abandonner, présent}}', 'il/elle/on {{c1::abandonne::abandonner, présent}}', 'nous {{c1::abandonnons::abandonner, présent}}', 'vous {{c1::abandonnez::abandonner, présent}}', 'ils/elles {{c1::abandonnent::abandonner, présent}}']) conj = French.construct_inflection('abandonner', 'présent') actual = French.output_cloze('abandonner', 'présent', conj) with self.subTest(): self.assertEqual(expected.fps, actual.fps) self.assertEqual(expected.sps, actual.sps) self.assertEqual(expected.tps, actual.tps) self.assertEqual(expected.fpp, actual.fpp) self.assertEqual(expected.spp, actual.spp) self.assertEqual(expected.tpp, actual.tpp)
def construct_stem_and_ending(infinitive, tense): ''' Given an infinitive and a tense, looks up the appropriate transformation rules and concatenates the resultant stem and ending ''' stem = _STEM_RULES[tense](infinitive) verb_type = infinitive[-2:] with sqlite3.connect('verb_trainer.db') as con: cur = con.cursor() cur.execute("SELECT fps, sps, tps, fpp, spp, tpp FROM tense_endings" "WHERE verb_type = ? AND tense_id = " "(SELECT tense_id FROM tenses WHERE tense_name = ?)", (verb_type, tense)) endings = cur.fetchone() return Category._make([stem + end for end in endings])
def construct_stem_and_ending(infinitive, tense): ''' Given an infinitive and a tense, looks up the appropriate transformation rules and concatenates the resultant stem and ending ''' stem = _STEM_RULES[tense](infinitive) verb_type = infinitive[-2:] with sqlite3.connect('verb_trainer.db') as con: cur = con.cursor() cur.execute( "SELECT fps, sps, tps, fpp, spp, tpp FROM tense_endings" "WHERE verb_type = ? AND tense_id = " "(SELECT tense_id FROM tenses WHERE tense_name = ?)", (verb_type, tense)) endings = cur.fetchone() return Category._make([stem + end for end in endings])
def test_cloze_normal(self): expected = Category._make([ 'je {{c1::parle::parler, présent}}', 'tu {{c1::parles::parler, présent}}', 'il/elle/on {{c1::parle::parler, présent}}', 'nous {{c1::parlons::parler, présent}}', 'vous {{c1::parlez::parler, présent}}', 'ils/elles {{c1::parlent::parler, présent}}' ]) conj = French.construct_inflection('parler', 'présent') actual = French.output_cloze('parler', 'présent', conj) with self.subTest(): self.assertEqual(expected.fps, actual.fps) self.assertEqual(expected.sps, actual.sps) self.assertEqual(expected.tps, actual.tps) self.assertEqual(expected.fpp, actual.fpp) self.assertEqual(expected.spp, actual.spp) self.assertEqual(expected.tpp, actual.tpp)
def construct_simple_tense_output(inflection): output = [] if inflection.fps.verb[0] in _VOWELS: output.append( _FPS_FORMAT.format(inflection.fps.pronoun, inflection.fps.verb)) else: output.append( _STD_FORMAT.format(inflection.fps.pronoun, inflection.fps.verb)) output.append( _STD_FORMAT.format(inflection.sps.pronoun, inflection.sps.verb)) output.append( _STD_FORMAT.format(inflection.tps.pronoun, inflection.tps.verb)) output.append( _STD_FORMAT.format(inflection.fpp.pronoun, inflection.fpp.verb)) output.append( _STD_FORMAT.format(inflection.spp.pronoun, inflection.spp.verb)) output.append( _STD_FORMAT.format(inflection.tpp.pronoun, inflection.tpp.verb)) return Category._make(output)
def construct_simple_tense_output(inflection): output = [] if inflection.fps.verb[0] in _VOWELS: output.append(_FPS_FORMAT.format(inflection.fps.pronoun, inflection.fps.verb)) else: output.append(_STD_FORMAT.format(inflection.fps.pronoun, inflection.fps.verb)) output.append(_STD_FORMAT.format(inflection.sps.pronoun, inflection.sps.verb)) output.append(_STD_FORMAT.format(inflection.tps.pronoun, inflection.tps.verb)) output.append(_STD_FORMAT.format(inflection.fpp.pronoun, inflection.fpp.verb)) output.append(_STD_FORMAT.format(inflection.spp.pronoun, inflection.spp.verb)) output.append(_STD_FORMAT.format(inflection.tpp.pronoun, inflection.tpp.verb)) return Category._make(output)
def output_cloze_import(infinitive, tense, translation, sound, conj): ''' Combines the output of the output_cloze function with optional translation and sound fields and combines them to produce the format required for Anki's import function ''' cloze = output_cloze(infinitive, tense, conj) if translation: add_trn = [cz + ('|{}'.format(trn)) for cz, trn in zip(cloze, translation)] else: add_trn = [cz + '|' for cz in cloze] if sound: add_snd = [trn + ('|[sound:{}]'.format(snd)) for trn, snd in zip(add_trn, sound)] else: add_snd = [trn + '|' for trn in add_trn] add_tag = [snd + ('|{}'.format(infinitive)) for snd in add_snd] return Category._make(add_tag)
def construct_simple_tense(infinitive, tense): stem_and_ending = construct_stem_and_ending(infinitive, tense) inflection = [(f(c), c) for f, c in zip(_PRONOUNS, stem_and_ending)] return Category._make([SimpleTenseParts._make(inf) for inf in inflection])
def construct_simple_tense_subjunctive(infinitive, tense): stem_and_ending = construct_stem_and_ending(infinitive, tense) return Category._make([("qu'" if f(c)[0] in _VOWELS else 'que', f(c), c) for f, c in zip(_PRONOUNS, stem_and_ending)])
def construct_compound_tense(infinitive, tense): past_participle = _construct_past_participle(infinitive) inflection = [(f(aux), aux, past_participle) for f, aux in zip(_PRONOUNS, _COMPOUND_TENSE[tense])] return Category._make(inflection)