コード例 #1
0
ファイル: test_query.py プロジェクト: rphilander/proteus
    def test_many(self):
        self.maxDiff = None
        pattern = QueryPattern('the_table',
                               [qcreq('animal'),
                                qcopt('adverb'),
                                qcreq('verb'),
                                qcreq('object'),
                                qcopt('ftw')])
        fox = Phrase('animal', { 'english' : 'the fox' }, [])
        mermaid = Phrase('animal', { 'english' : 'the mermaid' }, [])
        really = Phrase('adverb', { 'english' : 'really' }, [])
        totally = Phrase('adverb', { 'english' : 'totally' }, [])
        eats = Phrase('verb', { 'english' : 'eats' }, [])
        consumes = Phrase('verb', { 'english' : 'consumes' }, [])
        coconut = Phrase('object', { 'english' : 'a coconut' }, [])
        lamb = Phrase('object', { 'english' : 'a lamb' }, [])
        ftw = Phrase('ftw', { 'english' : 'FOR THE WIN' }, [])

        self.assertEqual(pattern.resolve([fox, mermaid, ftw]), [])
        self.assertEqual(pattern.resolve([fox, eats, lamb]), [Query('the_table', [fox, eats, lamb])])
        self.assertEqual(pattern.resolve([fox, mermaid, eats, coconut]), [Query('the_table', [fox, eats, coconut]),
                                                                          Query('the_table', [mermaid, eats, coconut])])

        result = pattern.resolve([fox, consumes, really, totally, lamb, ftw])
        target = [Query('the_table', [fox, really, consumes, lamb]),
                  Query('the_table', [fox, consumes, lamb]),
                  Query('the_table', [fox, totally, consumes, lamb]),
                  Query('the_table', [fox, consumes, lamb, ftw]),
                  Query('the_table', [fox, really, consumes, lamb, ftw]),
                  Query('the_table', [fox, totally, consumes, lamb, ftw])]
        self.assertEqual(len(result), len(target))
        for t in target:
            self.assertTrue(t in result)
コード例 #2
0
ファイル: test_query.py プロジェクト: rphilander/proteus
 def test_two(self):
     pattern = QueryPattern('the table', [qcreq('t1'), qcopt('t2')])
     t1 = Phrase('t1', {}, [])
     t2 = Phrase('t2', {}, [])
     self.assertEqual(pattern.resolve([t1]), [Query('the table', [t1])])
     self.assertEqual(pattern.resolve([t2]), [])
     self.assertEqual(pattern.resolve([t1, t2]), [Query('the table', [t1, t2]),
                                                  Query('the table', [t1])])
コード例 #3
0
ファイル: test_query.py プロジェクト: rphilander/proteus
 def test_empty_phrases_required(self):
     pattern = QueryPattern('the_table', [qcreq('t')])
     self.assertEqual(pattern.resolve([]), [])
コード例 #4
0
ファイル: test_query.py プロジェクト: rphilander/proteus
 def test_single_required(self):
     pattern = QueryPattern('the_table', [qcreq('t')])
     phrase = Phrase('t', {}, [])
     self.assertEqual(pattern.resolve([phrase]), [Query('the_table', [phrase])])
コード例 #5
0
ファイル: test_query.py プロジェクト: rphilander/proteus
 def test_required(self):
     required = qcreq('the type')
     self.assertEqual(required.get_phrase_type(), 'the type')
     self.assertEqual(required.get_required(), True)