Ejemplo n.º 1
0
class CaseInsensitiveParameterTest(ParameterTest, unittest.TestCase):
    """
    Test if non-default setting of caseInsensitive will yield proper results.
    """
    DICTIONARY = 'EDICT'
    PARAMETER_DESC = 'caseInsensitive'

    INSTALL_CONTENT = [
        (u'東京', u'とうきょう', u'/(n) Tokyo (current capital of Japan)/(P)/'),
        (u'東京語', u'とうきょうご', u'/(n) Tokyo dialect (esp. historical)/'),
        (u'東京都', u'とうきょうと', u'/(n) Tokyo Metropolitan area/'),
        (u'頭胸部', u'とうきょうぶ', u'/(n) cephalothorax/'),
        #(u'', u'', u''),
    ]

    ACCESS_RESULTS = [
        ('getFor', (), [(u'Tokyo', [0])]),
        ('getFor', (), [(u'tokyo', [])]),
        ('getForTranslation', (), [(u'tokyo%', [])]),
        ('getForTranslation', (), [(u'Tokyo%', [0, 1, 2])]),
    ]

    DICTIONARY_OPTIONS = {
        'translationSearchStrategy':
        searchstrategy.SimpleWildcardTranslation(caseInsensitive=False),
    }
Ejemplo n.º 2
0
class WildcardParameterTest(ParameterTest, unittest.TestCase):
    """
    Test if non-default settings of wildcards will yield proper results.
    """
    DICTIONARY = 'EDICT'
    PARAMETER_DESC = 'singleCharacter/multipleCharacters'

    INSTALL_CONTENT = [
        (u'東京', u'とうきょう', u'/(n) Tokyo% (current capital of Japan)/(P)/'),
        (u'東京', u'とうきょう', u'/(n) Tokyo_ (current capital of Japan)/(P)/'),
        (u'東京語', u'とうきょうご', u'/(n) Tokyo dialect (esp. historical)/'),
        (u'東京都', u'とうきょうと', u'/(n) Tokyo Metropolitan area/'),
        (u'頭胸部', u'とうきょうぶ', u'/(n) cephalothorax/'),
        #(u'', u'', u''),
    ]

    ACCESS_RESULTS = [
        ('getFor', (), [(u'Tokyo', [])]),
        ('getForTranslation', (), [(u'Tokyo%', [0])]),
        ('getForTranslation', (), [(u'tokyo%', [0])]),
        ('getForTranslation', (), [(u'Tokyo*', [0, 1, 2, 3])]),
        ('getForTranslation', (), [(u'Tokyo?', [0, 1])]),
        ('getForTranslation', (), [(u'Tokyo_', [1])]),
    ]

    DICTIONARY_OPTIONS = {
        'translationSearchStrategy':
        searchstrategy.SimpleWildcardTranslation(singleCharacter='?',
                                                 multipleCharacters='*'),
    }
Ejemplo n.º 3
0
class EscapeParameterTest(ParameterTest, unittest.TestCase):
    """Test if non-standard escape will yield proper results."""
    DICTIONARY = 'EDICT'
    PARAMETER_DESC = 'escape'

    INSTALL_CONTENT = [
        ('東京', 'とうきょう', '/(n) Tokyo (current capital of Japan)/(P)/'),
        ('東京語', 'とうきょうご', '/(n) Tokyo dialect (esp. historical)/'),
        ('東京都', 'とうきょうと', '/(n) Tokyo Metropolitan area/'),
        ('頭胸部', 'とうきょうぶ', '/(n) cephalothorax/'),
        #(u'', u'', u''),
    ]

    ACCESS_RESULTS = [
        ('getForHeadword', (), [('東京', [0])]),
        ('getFor', (), [('とうきょう_', [1, 2, 3])]),
        ('getForHeadword', (), [('Tokyo', [])]),
        ('getForHeadword', (), [('東%', [0, 1, 2])]),
        ('getFor', (), [('Tokyo', [0])]),
        ('getForTranslation', (), [('Tokyyo', [0])]),
        ('getFor', (), [('_Tokyo', [])]),
        ('getForTranslation', (), [('tokyo%', [0, 1, 2])]),
        ('getForTranslation', (), [('tokyyo%', [0, 1, 2])]),
    ]

    DICTIONARY_OPTIONS = {
        'translationSearchStrategy':
        searchstrategy.SimpleWildcardTranslation(escape='y'),
    }
Ejemplo n.º 4
0
    def __init__(self, **options):
        if 'entryFactory' not in options:
            options['entryFactory'] = entryfactory.NamedTuple()
        if 'translationSearchStrategy' not in options:
            options['translationSearchStrategy'] \
                = searchstrategy.SimpleWildcardTranslation()
        super(EDICTStyleDictionary, self).__init__(**options)

        if not self.available(self.db):
            raise ValueError("Table '%s' for dictionary does not exist"
                % self.DICTIONARY_TABLE)