Exemplo n.º 1
0
 def test_get_template(self):
     analysis = Analysis()
     
     self.assertEqual(analysis.get_template('aristoteles'), 'vcvccvcvcvc')
     self.assertEqual(analysis.get_template('oedipus'), 'vvcvcvc')
     self.assertEqual(analysis.get_template('socrates'), 'cvccvcvc')
     self.assertEqual(analysis.get_template('odysseus'), 'vccccvvc')
Exemplo n.º 2
0
    def test_get_template(self):
        analysis = Analysis()

        self.assertEqual(analysis.get_template('aristoteles'), 'vcvccvcvcvc')
        self.assertEqual(analysis.get_template('oedipus'), 'vvcvcvc')
        self.assertEqual(analysis.get_template('socrates'), 'cvccvcvc')
        self.assertEqual(analysis.get_template('odysseus'), 'vccccvvc')
Exemplo n.º 3
0
 def test_only_vowels(self):
     analysis = Analysis()
     
     word = 'aeiou'
     
     self.assertTrue(analysis.only_vowels(word))
     
     for char in 'bcdfghjklnmpqrstvwxyz':
         self.assertFalse(analysis.only_vowels(word + char))
Exemplo n.º 4
0
 def test_only_consonants(self):
     analysis = Analysis()
     
     self.assertTrue(analysis.only_consonants('bcdfghjklnmpqrstvwxyz'))
     self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyza'))
     self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyze'))
     self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzi'))
     self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzo'))
     self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzu'))
Exemplo n.º 5
0
 def test_reduce_template(self):
     analysis = Analysis()
     
     self.assertEqual(analysis.reduce_template('cvcv'), 'cvcv')
     self.assertEqual(analysis.reduce_template('ccvcv'), 'cvcv')
     self.assertEqual(analysis.reduce_template('cvvcv'), 'cvcv')
     self.assertEqual(analysis.reduce_template('cvccv'), 'cvcv')
     self.assertEqual(analysis.reduce_template('cvcvv'), 'cvcv')
     self.assertEqual(analysis.reduce_template('cvvvvcv'), 'cvcv')
Exemplo n.º 6
0
    def test_only_vowels(self):
        analysis = Analysis()

        word = 'aeiou'

        self.assertTrue(analysis.only_vowels(word))

        for char in 'bcdfghjklnmpqrstvwxyz':
            self.assertFalse(analysis.only_vowels(word + char))
    def test_analyse_word(self):
        analysis = Analysis()

        analysis.analyse_ending('Aristoteles')
        analysis.analyse_ending('Heracles')
        analysis.analyse_ending('Oedipus')
        analysis.analyse_ending('Socrates')
        analysis.analyse_ending('Odysseus')

        self.assertEqual(analysis.endings['es'], 3)
        self.assertEqual(analysis.endings['les'], 2)
        self.assertEqual(analysis.endings['tes'], 1)
        self.assertEqual(analysis.endings['us'], 2)
        self.assertEqual(analysis.endings['pus'], 1)
        self.assertEqual(analysis.endings['eus'], 1)
 def test_analyse_word(self):
     analysis = Analysis()
     
     analysis.analyse_ending('Aristoteles')
     analysis.analyse_ending('Heracles')
     analysis.analyse_ending('Oedipus')
     analysis.analyse_ending('Socrates')
     analysis.analyse_ending('Odysseus')
     
     self.assertEqual(analysis.endings['es'], 3)
     self.assertEqual(analysis.endings['les'], 2)
     self.assertEqual(analysis.endings['tes'], 1)
     self.assertEqual(analysis.endings['us'], 2)
     self.assertEqual(analysis.endings['pus'], 1)
     self.assertEqual(analysis.endings['eus'], 1)
Exemplo n.º 9
0
 def test_invalid_word(self):
     analysis = Analysis()
     
     self.assertFalse(analysis.analyse_word(None))
     self.assertFalse(analysis.analyse_word('a'))
     self.assertFalse(analysis.analyse_word('ab'))
     self.assertFalse(analysis.analyse_word('ab2'))
Exemplo n.º 10
0
    def test_only_consonants(self):
        analysis = Analysis()

        self.assertTrue(analysis.only_consonants('bcdfghjklnmpqrstvwxyz'))
        self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyza'))
        self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyze'))
        self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzi'))
        self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzo'))
        self.assertFalse(analysis.only_consonants('bcdfghjklnmpqrstvwxyzu'))
Exemplo n.º 11
0
    def test_reduce_template(self):
        analysis = Analysis()

        self.assertEqual(analysis.reduce_template('cvcv'), 'cvcv')
        self.assertEqual(analysis.reduce_template('ccvcv'), 'cvcv')
        self.assertEqual(analysis.reduce_template('cvvcv'), 'cvcv')
        self.assertEqual(analysis.reduce_template('cvccv'), 'cvcv')
        self.assertEqual(analysis.reduce_template('cvcvv'), 'cvcv')
        self.assertEqual(analysis.reduce_template('cvvvvcv'), 'cvcv')
Exemplo n.º 12
0
from name.analysis import Analysis
from name.generator import Generator
from name.template import Template

if __name__ == "__main__":
    analysis = Analysis()

    filename = 'greek_m'

    analysis.analyse_file('../data/' + filename + '.txt')
    analysis.calculate()

    print 'Vowels: count=%d' % (analysis.vowels_n)
    print 'Consonants: count=%d' % (analysis.consonants_n)
    print 'Endings: max=%d avg=%d' % (analysis.endings_max,
                                      analysis.endings_avg)
    print 'Groups: max=%d avg=%d' % (analysis.groups_max, analysis.groups_avg)
    print 'Templates: max=%d avg=%d' % (analysis.templates_max,
                                        analysis.templates_avg)
    print 'Reduced Templates: max=%d avg=%d' % (analysis.reduced_templates_max,
                                                analysis.reduced_templates_avg)

    analysis.save('../data/analysis/' + filename + '.txt')

    c_combs = {'th': 21, 'st': 17, 'ph': 16, 'ch': 11}
    v_combs = {
        'eu': 48,
        'io': 32,
        'ia': 28,
        'oo': 26,
        'ai': 26,
Exemplo n.º 13
0
 def test_analyse_word(self):
     analysis = Analysis()
     
     self.assertTrue(analysis.analyse_word('vbnm'))
     
     self.assertEqual(analysis.consonants_n, 4)
     self.assertEqual(analysis.consonants['b'], 1)
     self.assertEqual(analysis.consonants['c'], 0)
     self.assertEqual(analysis.consonants['d'], 0)
     self.assertEqual(analysis.consonants['f'], 0)
     self.assertEqual(analysis.consonants['g'], 0)
     self.assertEqual(analysis.consonants['h'], 0)
     self.assertEqual(analysis.consonants['j'], 0)
     self.assertEqual(analysis.consonants['k'], 0)
     self.assertEqual(analysis.consonants['l'], 0)
     self.assertEqual(analysis.consonants['m'], 1)
     self.assertEqual(analysis.consonants['n'], 1)
     self.assertEqual(analysis.consonants['p'], 0)
     self.assertEqual(analysis.consonants['q'], 0)
     self.assertEqual(analysis.consonants['r'], 0)
     self.assertEqual(analysis.consonants['s'], 0)
     self.assertEqual(analysis.consonants['t'], 0)
     self.assertEqual(analysis.consonants['v'], 1)
     self.assertEqual(analysis.consonants['w'], 0)
     self.assertEqual(analysis.consonants['x'], 0)
     self.assertEqual(analysis.consonants['y'], 0)
     self.assertEqual(analysis.consonants['z'], 0)
     
     self.assertEqual(analysis.vowels_n, 0)
     self.assertEqual(analysis.vowels['a'], 0)
     self.assertEqual(analysis.vowels['e'], 0)
     self.assertEqual(analysis.vowels['i'], 0)
     self.assertEqual(analysis.vowels['o'], 0)
     self.assertEqual(analysis.vowels['u'], 0)
     
     self.assertEqual(len(analysis.start), 1)
     self.assertEqual(analysis.number, 1)
     self.assertEqual(analysis.start['v'], 1)
     
     self.assertTrue(analysis.analyse_word('aeiou'))
     
     self.assertEqual(analysis.consonants_n, 4)
     self.assertEqual(analysis.consonants['b'], 1)
     self.assertEqual(analysis.consonants['c'], 0)
     self.assertEqual(analysis.consonants['d'], 0)
     self.assertEqual(analysis.consonants['f'], 0)
     self.assertEqual(analysis.consonants['g'], 0)
     self.assertEqual(analysis.consonants['h'], 0)
     self.assertEqual(analysis.consonants['j'], 0)
     self.assertEqual(analysis.consonants['k'], 0)
     self.assertEqual(analysis.consonants['l'], 0)
     self.assertEqual(analysis.consonants['m'], 1)
     self.assertEqual(analysis.consonants['n'], 1)
     self.assertEqual(analysis.consonants['p'], 0)
     self.assertEqual(analysis.consonants['q'], 0)
     self.assertEqual(analysis.consonants['r'], 0)
     self.assertEqual(analysis.consonants['s'], 0)
     self.assertEqual(analysis.consonants['t'], 0)
     self.assertEqual(analysis.consonants['v'], 1)
     self.assertEqual(analysis.consonants['w'], 0)
     self.assertEqual(analysis.consonants['x'], 0)
     self.assertEqual(analysis.consonants['y'], 0)
     self.assertEqual(analysis.consonants['z'], 0)
     
     self.assertEqual(analysis.vowels_n, 5)
     self.assertEqual(analysis.vowels['a'], 1)
     self.assertEqual(analysis.vowels['e'], 1)
     self.assertEqual(analysis.vowels['i'], 1)
     self.assertEqual(analysis.vowels['o'], 1)
     self.assertEqual(analysis.vowels['u'], 1)
     
     self.assertEqual(len(analysis.start), 2)
     self.assertEqual(analysis.number, 2)
     self.assertEqual(analysis.start['a'], 1)
     self.assertEqual(analysis.start['v'], 1)
     
     self.assertTrue(analysis.analyse_word('analysis'))
     
     self.assertEqual(analysis.consonants_n, 9)
     self.assertEqual(analysis.consonants['b'], 1)
     self.assertEqual(analysis.consonants['c'], 0)
     self.assertEqual(analysis.consonants['d'], 0)
     self.assertEqual(analysis.consonants['f'], 0)
     self.assertEqual(analysis.consonants['g'], 0)
     self.assertEqual(analysis.consonants['h'], 0)
     self.assertEqual(analysis.consonants['j'], 0)
     self.assertEqual(analysis.consonants['k'], 0)
     self.assertEqual(analysis.consonants['l'], 1)
     self.assertEqual(analysis.consonants['m'], 1)
     self.assertEqual(analysis.consonants['n'], 2)
     self.assertEqual(analysis.consonants['p'], 0)
     self.assertEqual(analysis.consonants['q'], 0)
     self.assertEqual(analysis.consonants['r'], 0)
     self.assertEqual(analysis.consonants['s'], 2)
     self.assertEqual(analysis.consonants['t'], 0)
     self.assertEqual(analysis.consonants['v'], 1)
     self.assertEqual(analysis.consonants['w'], 0)
     self.assertEqual(analysis.consonants['x'], 0)
     self.assertEqual(analysis.consonants['y'], 1)
     self.assertEqual(analysis.consonants['z'], 0)
     
     self.assertEqual(analysis.vowels_n, 8)
     self.assertEqual(analysis.vowels['a'], 3)
     self.assertEqual(analysis.vowels['e'], 1)
     self.assertEqual(analysis.vowels['i'], 2)
     self.assertEqual(analysis.vowels['o'], 1)
     self.assertEqual(analysis.vowels['u'], 1)
     
     self.assertEqual(len(analysis.start), 2)
     self.assertEqual(analysis.number, 3)
     self.assertEqual(analysis.start['a'], 2)
     self.assertEqual(analysis.start['v'], 1)
     
     self.assertTrue(analysis.analyse_word('UPPERCASE'))
     
     self.assertEqual(analysis.consonants_n, 14)
     self.assertEqual(analysis.consonants['b'], 1)
     self.assertEqual(analysis.consonants['c'], 1)
     self.assertEqual(analysis.consonants['d'], 0)
     self.assertEqual(analysis.consonants['f'], 0)
     self.assertEqual(analysis.consonants['g'], 0)
     self.assertEqual(analysis.consonants['h'], 0)
     self.assertEqual(analysis.consonants['j'], 0)
     self.assertEqual(analysis.consonants['k'], 0)
     self.assertEqual(analysis.consonants['l'], 1)
     self.assertEqual(analysis.consonants['m'], 1)
     self.assertEqual(analysis.consonants['n'], 2)
     self.assertEqual(analysis.consonants['p'], 2)
     self.assertEqual(analysis.consonants['q'], 0)
     self.assertEqual(analysis.consonants['r'], 1)
     self.assertEqual(analysis.consonants['s'], 3)
     self.assertEqual(analysis.consonants['t'], 0)
     self.assertEqual(analysis.consonants['v'], 1)
     self.assertEqual(analysis.consonants['w'], 0)
     self.assertEqual(analysis.consonants['x'], 0)
     self.assertEqual(analysis.consonants['y'], 1)
     self.assertEqual(analysis.consonants['z'], 0)
     
     self.assertEqual(analysis.vowels_n, 12)
     self.assertEqual(analysis.vowels['a'], 4)
     self.assertEqual(analysis.vowels['e'], 3)
     self.assertEqual(analysis.vowels['i'], 2)
     self.assertEqual(analysis.vowels['o'], 1)
     self.assertEqual(analysis.vowels['u'], 2)
     
     self.assertEqual(len(analysis.start), 3)
     self.assertEqual(analysis.number, 4)
     self.assertEqual(analysis.start['a'], 2)
     self.assertEqual(analysis.start['u'], 1)
     self.assertEqual(analysis.start['v'], 1)
     
     self.assertTrue(analysis.analyse_word('group'))
     
     self.assertEqual(analysis.groups['ou'], 2)
     self.assertEqual(analysis.v_combs['ou'], 2)
     
     self.assertTrue(analysis.analyse_word('great'))
     
     self.assertEqual(analysis.c_combs['gr'], 2)
Exemplo n.º 14
0
from name.analysis import Analysis
from name.generator import Generator
from name.template import Template


if __name__ == "__main__":
    analysis = Analysis()
    
    filename = 'greek_m'
    
    analysis.analyse_file('../data/' + filename + '.txt')
    analysis.calculate()
    
    print 'Vowels: count=%d' % (analysis.vowels_n)        
    print 'Consonants: count=%d' % (analysis.consonants_n)       
    print 'Endings: max=%d avg=%d' % (analysis.endings_max, analysis.endings_avg)    
    print 'Groups: max=%d avg=%d' % (analysis.groups_max, analysis.groups_avg)
    print 'Templates: max=%d avg=%d' % (analysis.templates_max, analysis.templates_avg)
    print 'Reduced Templates: max=%d avg=%d' % (analysis.reduced_templates_max, analysis.reduced_templates_avg)
    
    analysis.save('../data/analysis/' + filename + '.txt')
    
    c_combs = {'th':21, 'st':17, 'ph':16, 'ch':11}
    v_combs = {'eu':48, 'io':32, 'ia':28, 'oo':26, 'ai':26, 'ae':26, 'oe':25, 
        'ei':25, 'eo':24, 'iu':23, 'au':22, 'ao':22}
    
    generator = Generator(analysis.consonants, analysis.vowels, c_combs, v_combs)
    template = Template('<CVC|CVCVC|VCVC|VCVCVC>(es|on|os|us|as)') 
    
    for i in range(10):
        print generator.generate(template)