本文整理汇总了Python中plover.steno_dictionary.StenoDictionaryCollection.set_dicts方法的典型用法代码示例。如果您正苦于以下问题:Python StenoDictionaryCollection.set_dicts方法的具体用法?Python StenoDictionaryCollection.set_dicts怎么用?Python StenoDictionaryCollection.set_dicts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plover.steno_dictionary.StenoDictionaryCollection
的用法示例。
在下文中一共展示了StenoDictionaryCollection.set_dicts方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dictionary_enabled
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [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'), [])
示例2: test_dictionary_collection
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [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')
示例3: test_dictionary_enabled
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [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') == []
示例4: TranslatorStateSizeTestCase
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
class TranslatorStateSizeTestCase(unittest.TestCase):
class FakeState(_State):
def __init__(self):
_State.__init__(self)
self.restrict_calls = []
def restrict_size(self, n):
self.restrict_calls.append(n)
def assert_size_call(self, size):
self.assertEqual(self.s.restrict_calls[-1], size)
def assert_no_size_call(self):
self.assertEqual(self.s.restrict_calls, [])
def clear(self):
self.s.restrict_calls = []
def setUp(self):
self.t = Translator()
self.s = type(self).FakeState()
self.t._state = self.s
self.d = StenoDictionary()
self.dc = StenoDictionaryCollection()
self.dc.set_dicts([self.d])
self.t.set_dictionary(self.dc)
def test_dictionary_update_grows_size1(self):
self.d[('S',)] = '1'
self.assert_size_call(1)
def test_dictionary_update_grows_size4(self):
self.d[('S', 'PT', '-Z', 'TOP')] = 'hi'
self.assert_size_call(4)
def test_dictionary_update_no_grow(self):
self.t.set_min_undo_length(4)
self.assert_size_call(4)
self.clear()
self.d[('S', 'T')] = 'nothing'
self.assert_size_call(4)
def test_dictionary_update_shrink(self):
self.d[('S', 'T', 'P', '-Z', '-D')] = '1'
self.assert_size_call(5)
self.clear()
self.d[('A', 'P')] = '2'
self.assert_no_size_call()
del self.d[('S', 'T', 'P', '-Z', '-D')]
self.assert_size_call(2)
def test_dictionary_update_no_shrink(self):
self.t.set_min_undo_length(7)
self.d[('S', 'T', 'P', '-Z', '-D')] = '1'
del self.d[('S', 'T', 'P', '-Z', '-D')]
self.assert_size_call(7)
def test_translation_calls_restrict(self):
self.t.translate(stroke('S'))
self.assert_size_call(0)
示例5: test_dictionary_collection_longest_key
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
def test_dictionary_collection_longest_key(self):
k1 = ('S',)
k2 = ('S', 'T')
k3 = ('S', 'T' , 'R')
dc = StenoDictionaryCollection()
self.assertEqual(dc.longest_key, 0)
d1 = StenoDictionary()
d1._path = 'd1'
d1.save = lambda: None
d1[k1] = 'a'
dc.set_dicts([d1])
self.assertEqual(dc.longest_key, 1)
d1[k2] = 'a'
self.assertEqual(dc.longest_key, 2)
d2 = StenoDictionary()
d2._path = 'd2'
d2[k3] = 'c'
dc.set_dicts([d1, d2])
self.assertEqual(dc.longest_key, 3)
del d1[k2]
self.assertEqual(dc.longest_key, 3)
dc.set_dicts([d1])
self.assertEqual(dc.longest_key, 1)
dc.set_dicts([])
self.assertEqual(dc.longest_key, 0)
示例6: test_dictionary_collection_writeable
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
def test_dictionary_collection_writeable(self):
dc = StenoDictionaryCollection()
d1 = StenoDictionary()
d1[('S',)] = 'a'
d1[('T',)] = 'b'
d2 = StenoDictionary()
d2[('S',)] = 'c'
d2[('W',)] = 'd'
d2.readonly = True
dc.set_dicts([d2, d1])
self.assertEqual(dc.first_writable(), d1)
dc.set(('S',), 'A')
self.assertEqual(d1[('S',)], 'A')
self.assertEqual(d2[('S',)], 'c')
示例7: test_reverse_lookup
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [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',)])
示例8: test_dictionary_collection_longest_key
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
def test_dictionary_collection_longest_key():
k1 = ('S',)
k2 = ('S', 'T')
k3 = ('S', 'T', 'R')
dc = StenoDictionaryCollection()
assert dc.longest_key == 0
d1 = StenoDictionary()
d1.path = 'd1'
d1[k1] = 'a'
dc.set_dicts([d1])
assert dc.longest_key == 1
d1[k2] = 'a'
assert dc.longest_key == 2
d2 = StenoDictionary()
d2.path = 'd2'
d2[k3] = 'c'
dc.set_dicts([d2, d1])
assert dc.longest_key == 3
del d1[k2]
assert dc.longest_key == 3
dc.set_dicts([d1])
assert dc.longest_key == 1
dc.set_dicts([])
assert dc.longest_key == 0
示例9: test_dictionary_collection
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [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']
示例10: test_changing_state
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
def test_changing_state(self):
output = []
def listener(undo, do, prev):
prev = list(prev) if prev else None
output.append((undo, do, prev))
d = StenoDictionary()
d[('S', 'P')] = 'hi'
dc = StenoDictionaryCollection()
dc.set_dicts([d])
t = Translator()
t.set_dictionary(dc)
t.translate(stroke('T'))
t.translate(stroke('S'))
s = copy.deepcopy(t.get_state())
t.add_listener(listener)
expected = [([Translation([stroke('S')], None)],
[Translation([stroke('S'), stroke('P')], 'hi')],
[Translation([stroke('T')], None)])]
t.translate(stroke('P'))
self.assertEqual(output, expected)
del output[:]
t.set_state(s)
t.translate(stroke('P'))
self.assertEqual(output, expected)
del output[:]
t.clear_state()
t.translate(stroke('P'))
self.assertEqual(output, [([], [Translation([stroke('P')], None)], None)])
del output[:]
t.set_state(s)
t.translate(stroke('P'))
self.assertEqual(output,
[([],
[Translation([stroke('P')], None)],
[Translation([stroke('S'), stroke('P')], 'hi')])])
示例11: TranslateStrokeTestCase
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
class TranslateStrokeTestCase(unittest.TestCase):
class CaptureOutput(object):
output = namedtuple('output', 'undo do prev')
def __init__(self):
self.output = []
def __call__(self, undo, new, prev):
prev = list(prev) if prev else None
self.output = type(self).output(undo, new, prev)
def t(self, strokes):
"""A quick way to make a translation."""
strokes = [stroke(x) for x in strokes.split('/')]
key = tuple(s.rtfcre for s in strokes)
translation = self.dc.lookup(key)
return Translation(strokes, translation)
def lt(self, translations):
"""A quick way to make a list of translations."""
return [self.t(x) for x in translations.split()]
def define(self, key, value):
key = normalize_steno(key)
self.d[key] = value
def translate(self, stroke):
self.tlor.translate(stroke)
def assertTranslations(self, expected):
self.assertEqual(self.s.translations, expected)
def assertOutput(self, undo, do, prev):
self.assertEqual(self.o.output, (undo, do, prev))
def setUp(self):
self.d = StenoDictionary()
self.dc = StenoDictionaryCollection()
self.dc.set_dicts([self.d])
self.s = _State()
self.o = self.CaptureOutput()
self.tlor = Translator()
self.tlor.set_dictionary(self.dc)
self.tlor.add_listener(self.o)
self.tlor.set_state(self.s)
def test_first_stroke(self):
self.translate(stroke('-B'))
self.assertTranslations(self.lt('-B'))
self.assertOutput([], self.lt('-B'), None)
def test_second_stroke(self):
self.define('S/P', 'spiders')
self.s.translations = self.lt('S')
self.translate(stroke('-T'))
self.assertTranslations(self.lt('S -T'))
self.assertOutput([], self.lt('-T'), self.lt('S'))
def test_second_stroke_tail(self):
self.s.tail = self.t('T/A/I/L')
self.translate(stroke('-E'))
self.assertTranslations(self.lt('E'))
self.assertOutput([], self.lt('E'), self.lt('T/A/I/L'))
def test_with_translation_1(self):
self.define('S', 'is')
self.define('-T', 'that')
self.s.translations = self.lt('S')
self.tlor.set_min_undo_length(2)
self.translate(stroke('-T'))
self.assertTranslations(self.lt('S -T'))
self.assertOutput([], self.lt('-T'), self.lt('S'))
self.assertEqual(self.o.output.do[0].english, 'that')
def test_with_translation_2(self):
self.define('S', 'is')
self.define('-T', 'that')
self.s.translations = self.lt('S')
self.tlor.set_min_undo_length(1)
self.translate(stroke('-T'))
self.assertTranslations(self.lt('-T'))
self.assertOutput([], self.lt('-T'), self.lt('S'))
self.assertEqual(self.o.output.do[0].english, 'that')
def test_finish_two_translation(self):
self.define('S/T', 'hello')
self.s.translations = self.lt('S')
self.translate(stroke('T'))
self.assertTranslations(self.lt('S/T'))
self.assertOutput(self.lt('S'), self.lt('S/T'), None)
self.assertEqual(self.o.output.do[0].english, 'hello')
self.assertEqual(self.o.output.do[0].replaced, self.lt('S'))
def test_finish_three_translation(self):
self.define('S/T/-B', 'bye')
self.s.translations = self.lt('S T')
self.translate(stroke('-B'))
self.assertTranslations(self.lt('S/T/-B'))
self.assertOutput(self.lt('S T'), self.lt('S/T/-B'), None)
#.........这里部分代码省略.........
示例12: test_translator
# 需要导入模块: from plover.steno_dictionary import StenoDictionaryCollection [as 别名]
# 或者: from plover.steno_dictionary.StenoDictionaryCollection import set_dicts [as 别名]
def test_translator(self):
# It's not clear that this test is needed anymore. There are separate
# tests for _translate_stroke and test_translate_calls_translate_stroke
# makes sure that translate calls it properly. But since I already wrote
# this test I'm going to keep it.
class Output(object):
def __init__(self):
self._output = []
def write(self, undo, do, prev):
for t in undo:
self._output.pop()
for t in do:
if t.english:
self._output.append(t.english)
else:
self._output.append('/'.join(t.rtfcre))
def get(self):
return ' '.join(self._output)
def clear(self):
del self._output[:]
d = StenoDictionary()
out = Output()
t = Translator()
dc = StenoDictionaryCollection()
dc.set_dicts([d])
t.set_dictionary(dc)
t.add_listener(out.write)
t.translate(stroke('S'))
self.assertEqual(out.get(), 'S')
t.translate(stroke('T'))
self.assertEqual(out.get(), 'S T')
t.translate(stroke('*'))
self.assertEqual(out.get(), 'S')
t.translate(stroke('*'))
self.assertEqual(out.get(), 'S ' + _back_string()) # Undo buffer ran out.
t.set_min_undo_length(3)
out.clear()
t.translate(stroke('S'))
self.assertEqual(out.get(), 'S')
t.translate(stroke('T'))
self.assertEqual(out.get(), 'S T')
t.translate(stroke('*'))
self.assertEqual(out.get(), 'S')
t.translate(stroke('*'))
self.assertEqual(out.get(), '' )
out.clear()
d[('S',)] = 't1'
d[('T',)] = 't2'
d[('S', 'T')] = 't3'
t.translate(stroke('S'))
self.assertEqual(out.get(), 't1')
t.translate(stroke('T'))
self.assertEqual(out.get(), 't3')
t.translate(stroke('T'))
self.assertEqual(out.get(), 't3 t2')
t.translate(stroke('S'))
self.assertEqual(out.get(), 't3 t2 t1')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't3 t2')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't3')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't1')
t.translate(stroke('*'))
self.assertEqual(out.get(), '')
t.translate(stroke('S'))
self.assertEqual(out.get(), 't1')
t.translate(stroke('T'))
self.assertEqual(out.get(), 't3')
t.translate(stroke('T'))
self.assertEqual(out.get(), 't3 t2')
d[('S', 'T', 'T')] = 't4'
d[('S', 'T', 'T', 'S')] = 't5'
t.translate(stroke('S'))
self.assertEqual(out.get(), 't5')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't3 t2')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't3')
t.translate(stroke('T'))
self.assertEqual(out.get(), 't4')
t.translate(stroke('S'))
self.assertEqual(out.get(), 't5')
t.translate(stroke('S'))
self.assertEqual(out.get(), 't5 t1')
t.translate(stroke('*'))
self.assertEqual(out.get(), 't5')
#.........这里部分代码省略.........