当前位置: 首页>>代码示例>>Python>>正文


Python StenoDictionaryCollection.reverse_lookup方法代码示例

本文整理汇总了Python中plover.steno_dictionary.StenoDictionaryCollection.reverse_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python StenoDictionaryCollection.reverse_lookup方法的具体用法?Python StenoDictionaryCollection.reverse_lookup怎么用?Python StenoDictionaryCollection.reverse_lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plover.steno_dictionary.StenoDictionaryCollection的用法示例。


在下文中一共展示了StenoDictionaryCollection.reverse_lookup方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dictionary_collection

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
 def test_dictionary_collection(self):
     dc = StenoDictionaryCollection()
     d1 = StenoDictionary()
     d1[('S',)] = 'a'
     d1[('T',)] = 'b'
     d2 = StenoDictionary()
     d2[('S',)] = 'c'
     d2[('W',)] = 'd'
     dc.set_dicts([d1, d2])
     self.assertEqual(dc.lookup(('S',)), 'c')
     self.assertEqual(dc.lookup(('W',)), 'd')
     self.assertEqual(dc.lookup(('T',)), 'b')
     f = lambda k, v: v == 'c'
     dc.add_filter(f)
     self.assertIsNone(dc.lookup(('S',)))
     self.assertEqual(dc.raw_lookup(('S',)), 'c')
     self.assertEqual(dc.lookup(('W',)), 'd')
     self.assertEqual(dc.lookup(('T',)), 'b')
     self.assertEqual(dc.reverse_lookup('c'), [('S',)])
     
     dc.remove_filter(f)
     self.assertEqual(dc.lookup(('S',)), 'c')
     self.assertEqual(dc.lookup(('W',)), 'd')
     self.assertEqual(dc.lookup(('T',)), 'b')
     
     self.assertEqual(dc.reverse_lookup('c'), [('S',)])
     
     dc.set(('S',), 'e')
     self.assertEqual(dc.lookup(('S',)), 'e')
     self.assertEqual(d2[('S',)], 'e')
开发者ID:Achim63,项目名称:plover,代码行数:32,代码来源:test_steno_dictionary.py

示例2: test_dictionary_enabled

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
 def test_dictionary_enabled(self):
     dc = StenoDictionaryCollection()
     d1 = StenoDictionary()
     d1.path = 'd1'
     d1[('TEFT',)] = 'test1'
     d1[('TEFGT',)] = 'Testing'
     d2 = StenoDictionary()
     d2[('TEFT',)] = 'test2'
     d2[('TEFT','-G')] = 'Testing'
     d2.path = 'd2'
     dc.set_dicts([d2, d1])
     self.assertEqual(dc.lookup(('TEFT',)), 'test2')
     self.assertEqual(dc.raw_lookup(('TEFT',)), 'test2')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     assertCountEqual(self, dc.reverse_lookup('Testing'), [('TEFGT',), ('TEFT', '-G')])
     d2.enabled = False
     self.assertEqual(dc.lookup(('TEFT',)), 'test1')
     self.assertEqual(dc.raw_lookup(('TEFT',)), 'test1')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     assertCountEqual(self, dc.reverse_lookup('Testing'), [('TEFGT',)])
     d1.enabled = False
     self.assertEqual(dc.lookup(('TEST',)), None)
     self.assertEqual(dc.raw_lookup(('TEFT',)), None)
     self.assertEqual(dc.casereverse_lookup('testing'), None)
     assertCountEqual(self, dc.reverse_lookup('Testing'), [])
开发者ID:Slotkenov,项目名称:plover,代码行数:27,代码来源:test_steno_dictionary.py

示例3: test_reverse_lookup

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
    def test_reverse_lookup(self):
        dc = StenoDictionaryCollection()

        d1 = StenoDictionary()
        d1[('PWAOUFL',)] = 'beautiful'
        d1[('WAOUFL',)] = 'beautiful'

        d2 = StenoDictionary()
        d2[('PW-FL',)] = 'beautiful'

        d3 = StenoDictionary()
        d3[('WAOUFL',)] = 'not beautiful'

        # Simple test.
        dc.set_dicts([d1])
        self.assertCountEqual(dc.reverse_lookup('beautiful'),
                              [('PWAOUFL',), ('WAOUFL',)])

        # No duplicates.
        d2_copy = StenoDictionary()
        d2_copy.update(d2)
        dc.set_dicts([d2_copy, d2])
        self.assertCountEqual(dc.reverse_lookup('beautiful'),
                              [('PW-FL',)])

        # Don't stop at the first dictionary with matches.
        dc.set_dicts([d2, d1])
        self.assertCountEqual(dc.reverse_lookup('beautiful'),
                              [('PWAOUFL',), ('WAOUFL',), ('PW-FL',)])

        # Ignore keys overriden by a higher precedence dictionary.
        dc.set_dicts([d3, d2, d1])
        self.assertCountEqual(dc.reverse_lookup('beautiful'),
                              [('PWAOUFL',), ('PW-FL',)])
开发者ID:MartyGentillon,项目名称:plover,代码行数:36,代码来源:test_steno_dictionary.py

示例4: test_dictionary_enabled

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
def test_dictionary_enabled():
    dc = StenoDictionaryCollection()
    d1 = StenoDictionary()
    d1.path = 'd1'
    d1[('TEFT',)] = 'test1'
    d1[('TEFGT',)] = 'Testing'
    d2 = StenoDictionary()
    d2[('TEFT',)] = 'test2'
    d2[('TEFT', '-G')] = 'Testing'
    d2.path = 'd2'
    dc.set_dicts([d2, d1])
    assert dc.lookup(('TEFT',)) == 'test2'
    assert dc.raw_lookup(('TEFT',)) == 'test2'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == [('TEFT', '-G'), ('TEFGT',)]
    d2.enabled = False
    assert dc.lookup(('TEFT',)) == 'test1'
    assert dc.raw_lookup(('TEFT',)) == 'test1'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == [('TEFGT',)]
    d1.enabled = False
    assert dc.lookup(('TEST',)) is None
    assert dc.raw_lookup(('TEFT',)) is None
    assert dc.casereverse_lookup('testing') is None
    assert dc.reverse_lookup('Testing') == []
开发者ID:DanLanglois,项目名称:plover,代码行数:27,代码来源:test_steno_dictionary.py

示例5: test_dictionary_collection

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
    def test_dictionary_collection(self):
        dc = StenoDictionaryCollection()
        d1 = StenoDictionary()
        d1[('S',)] = 'a'
        d1[('T',)] = 'b'
        d1.path = 'd1'
        d2 = StenoDictionary()
        d2[('S',)] = 'c'
        d2[('W',)] = 'd'
        d2.path = 'd2'
        dc.set_dicts([d2, d1])
        self.assertEqual(dc.lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')
        f = lambda k, v: v == 'c'
        dc.add_filter(f)
        self.assertIsNone(dc.lookup(('S',)))
        self.assertEqual(dc.raw_lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')
        self.assertEqual(dc.reverse_lookup('c'), [('S',)])

        dc.remove_filter(f)
        self.assertEqual(dc.lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')

        self.assertEqual(dc.reverse_lookup('c'), [('S',)])

        dc.set(('S',), 'e')
        self.assertEqual(dc.lookup(('S',)), 'e')
        self.assertEqual(d2[('S',)], 'e')

        dc.set(('S',), 'f', path='d1')
        self.assertEqual(dc.lookup(('S',)), 'e')
        self.assertEqual(d1[('S',)], 'f')
        self.assertEqual(d2[('S',)], 'e')

        # Iterating on a StenoDictionaryCollection is
        # the same as iterating on its dictionaries' paths.
        self.assertEqual(list(dc), ['d2', 'd1'])

        # Test get and [].
        self.assertEqual(dc.get('d1'), d1)
        self.assertEqual(dc['d1'], d1)
        self.assertEqual(dc.get('invalid'), None)
        with self.assertRaises(KeyError):
            dc['invalid']
开发者ID:Slotkenov,项目名称:plover,代码行数:50,代码来源:test_steno_dictionary.py

示例6: test_dictionary_collection

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]
def test_dictionary_collection():
    d1 = StenoDictionary()
    d1[('S',)] = 'a'
    d1[('T',)] = 'b'
    d1.path = 'd1'
    d2 = StenoDictionary()
    d2[('S',)] = 'c'
    d2[('W',)] = 'd'
    d2.path = 'd2'
    dc = StenoDictionaryCollection([d2, d1])
    assert dc.lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'
    f = lambda k, v: v == 'c'
    dc.add_filter(f)
    assert dc.lookup(('S',)) is None
    assert dc.raw_lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'
    assert dc.reverse_lookup('c') == [('S',)]

    dc.remove_filter(f)
    assert dc.lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'

    assert dc.reverse_lookup('c') == [('S',)]

    dc.set(('S',), 'e')
    assert dc.lookup(('S',)) == 'e'
    assert d2[('S',)] == 'e'

    dc.set(('S',), 'f', path='d1')
    assert dc.lookup(('S',)) == 'e'
    assert d1[('S',)] == 'f'
    assert d2[('S',)] == 'e'

    # Iterating on a StenoDictionaryCollection is
    # the same as iterating on its dictionaries' paths.
    assert list(dc) == ['d2', 'd1']

    # Test get and [].
    assert dc.get('d1') == d1
    assert dc['d1'] == d1
    assert dc.get('invalid') is None
    with pytest.raises(KeyError):
        dc['invalid']
开发者ID:DanLanglois,项目名称:plover,代码行数:49,代码来源:test_steno_dictionary.py

示例7: StenoEngine

# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import reverse_lookup [as 别名]

#.........这里部分代码省略.........

    def start(self):
        self._same_thread_hook(self._start)

    def quit(self, code=0):
        # We need to go through the queue, even when already called
        # from the engine thread so _quit's return code does break
        # the thread out of its main loop.
        self._queue.put((self._quit, (code,), {}))

    def restart(self):
        self.quit(-1)

    def join(self):
        return self.code

    @with_lock
    def machine_specific_options(self, machine_type):
        return self._config.get_machine_specific_options(machine_type)

    @with_lock
    def system_keymap(self, machine_type, system_name):
        return self._config.get_system_keymap(machine_type, system_name)

    @with_lock
    def lookup(self, translation):
        return self._dictionaries.lookup(translation)

    @with_lock
    def raw_lookup(self, translation):
        return self._dictionaries.raw_lookup(translation)

    @with_lock
    def reverse_lookup(self, translation):
        matches = self._dictionaries.reverse_lookup(translation)
        return [] if matches is None else matches

    @with_lock
    def casereverse_lookup(self, translation):
        matches = self._dictionaries.casereverse_lookup(translation)
        return set() if matches is None else matches

    @with_lock
    def add_dictionary_filter(self, dictionary_filter):
        self._dictionaries.add_filter(dictionary_filter)

    @with_lock
    def remove_dictionary_filter(self, dictionary_filter):
        self._dictionaries.remove_filter(dictionary_filter)

    @with_lock
    def get_suggestions(self, translation):
        return Suggestions(self._dictionaries).find(translation)

    @property
    @with_lock
    def translator_state(self):
        return self._translator.get_state()

    @translator_state.setter
    @with_lock
    def translator_state(self, state):
        self._translator.set_state(state)

    @with_lock
    def clear_translator_state(self, undo=False):
开发者ID:ohAitch,项目名称:plover,代码行数:70,代码来源:engine.py


注:本文中的plover.steno_dictionary.StenoDictionaryCollection.reverse_lookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。