コード例 #1
0
    def test_08_join_meanings(self):
        """
        Join two meanings.
        """
        s1 = Sentence.objects.create(text=u'violin sonata')
        s2 = Sentence.objects.create(text=u'sonaatti viululle')

        m1s = Meaning.objects.lookup_exact(u'sonata')
        self.assertEqual(len(m1s), 1)
        m1 = m1s[0]
        self.assertEqual(repr(m1), '<Meaning: 7: None:sonata>')

        m2s = Meaning.objects.lookup_exact(u'sonaatti')
        self.assertEqual(len(m2s), 1)
        m2 = m2s[0]
        self.assertEqual(repr(m2), '<Meaning: 8: None:sonaatti>')

        assert_meanings(['en:mold', 'fi:home'],
                        ['en:home', 'fi:koti'],
                        ['de:klavier', 'en:piano', 'fi:piano'],
                        ['de:konzert', 'en:concerto', 'fi:konsertto'],
                        ['?:goethe'],
                        ['?:violin'],
                        ['?:sonata'],
                        ['?:sonaatti'],
                        ['?:viululle'])
        assert_index(s1, [1, '?:violin'], [2, '?:sonata'])
        assert_index(s2, [1, '?:sonaatti'], [2, '?:viululle'])

        Meaning.objects.join(m1, m2)

        assert_meanings(['en:mold', 'fi:home'],
                        ['en:home', 'fi:koti'],
                        ['de:klavier', 'en:piano', 'fi:piano'],
                        ['de:konzert', 'en:concerto', 'fi:konsertto'],
                        ['?:goethe'],
                        ['?:violin'],
                        ['?:sonaatti', '?:sonata'],
                        ['?:viululle'])
        assert_index(s1, [1, '?:violin'], [2, '?:sonaatti', '?:sonata'])
        assert_index(s2, [1, '?:sonaatti', '?:sonata'], [2, '?:viululle'])

        self.assertEqual(repr(m1), '<Meaning: 7: None:sonaatti,None:sonata>')
        self.assertEqual(m2.pk, None)
        s1.delete()
        s2.delete()
コード例 #2
0
    def test_01_build_vocabulary(self):
        # meanings Capitalized
        # sentences in_lower_case

        assert_meanings_diff = self.assert_meaning_changes
        
        assert_meanings()  # no meanings initially

        string_quartet = self.new_sentence('string quartet')
        assert_index(string_quartet, [1, '?:string'], [2, '?:quartet'])
        assert_meanings_diff(added=[['?:string'],
                                    ['?:quartet']])

        jousikvartetto = self.new_sentence('jousikvartetto')
        assert_index(jousikvartetto, [1, '?:jousikvartetto'])
        assert_meanings_diff(added=[['?:jousikvartetto']])

        String = self.create_meaning('fi:jousi', 'en:string')
        assert_meanings_diff(added=[['en:string', 'fi:jousi']])
        IndexEntry.objects.index_instance(jousikvartetto)
        assert_index(jousikvartetto, [1, '?:jousikvartetto'])

        # longest match used: not jousi-kvartetto but jousikvartetto
        Quartet = self.create_meaning('fi:kvartetto', 'en:quartet')
        assert_meanings_diff(added=[['en:quartet', 'fi:kvartetto']])
        IndexEntry.objects.index_instance(jousikvartetto)
        assert_index(jousikvartetto, [1, '?:jousikvartetto'])

        # reindex jousikvartetto as jousi-kvartetto
        Meaning.objects.split(self.lookup_one_meaning(u'jousikvartetto'),
                              String, Quartet)
        assert_index(jousikvartetto,
                     [1, 'en:string', 'fi:jousi'],
                     [1, 'en:quartet', 'fi:kvartetto'])
        assert_meanings_diff(removed=[['?:jousikvartetto']])

        quartet_in_g_str = self.new_sentence('Quartet in g (str)')
        assert_index(quartet_in_g_str,
                     [1, '?:quartet'],
                     [1, 'en:quartet', 'fi:kvartetto'],
                     [2, '?:in'],
                     [3, '?:g'],
                     [4, '?:str'])
        assert_meanings_diff(added=[['?:g'], ['?:in'], ['?:str']])

        string_quintet = self.new_sentence('string quintet')
        assert_index(string_quintet,
                     [1, '?:string'], [1, 'en:string', 'fi:jousi'],
                     [2, '?:quintet'])
        assert_meanings_diff(added=[['?:quintet']])

        gintonic = self.new_sentence('gintonic')
        assert_index(gintonic,
                     [1, '?:gintonic'])
        assert_meanings_diff(added=[['?:gintonic']])