How to use _init_matcher method in pyshould

Best Python code snippet using pyshould_python

opentran.py

Source:opentran.py Github

copy

Full Screen

...45 self.load_config()46 self.main_controller = controller.main_controller47 self.term_controller = controller48 self.matcher = None49 self._init_matcher()50 self.opentrantm = self._find_opentran_tm()51 if self.opentrantm is None:52 self._init_opentran_client()53 else:54 self.opentrantm.connect('match-found', self._on_match_found)55 self.__setup_opentrantm_lang_watchers()56 def _find_opentran_tm(self):57 """58 Try and find an existing OpenTranClient instance, used by the OpenTran59 TM model.60 """61 plugin_ctrl = self.main_controller.plugin_controller62 if 'tm' not in plugin_ctrl.plugins:63 return None64 tm_ctrl = plugin_ctrl.plugins['tm'].tmcontroller65 if 'opentran' not in tm_ctrl.plugin_controller.plugins:66 return None67 return tm_ctrl.plugin_controller.plugins['opentran']68 def _init_matcher(self):69 """70 Initialize the matcher to be used by the C{TerminologyPlaceable} parser.71 """72 if self.matcher in TerminologyPlaceable.matchers:73 TerminologyPlaceable.matchers.remove(self.matcher)74 self.store = TranslationStore()75 self.store.makeindex()76 self.matcher = terminologymatcher(self.store)77 TerminologyPlaceable.matchers.append(self.matcher)78 def _init_opentran_client(self):79 """80 Create and initialize a new Open-Tran client. This should only happen81 when the Open-Tran TM model plug-in is not loaded.82 """83 plugin_ctrlr = self.main_controller.plugin_controller84 lang_ctrlr = self.main_controller.lang_controller85 # The following two values were copied from plugins/tm/__init__.py86 max_candidates = 587 min_similarity = 7088 # Try to get max_candidates and min_quality from the TM plug-in89 if 'tm' in plugin_ctrlr.plugins:90 max_candidates = plugin_ctrlr.plugins['tm'].config['max_matches']91 min_similarity = plugin_ctrlr.plugins['tm'].config['min_quality']92 self.opentranclient = opentranclient.OpenTranClient(93 max_candidates=max_candidates,94 min_similarity=min_similarity95 )96 self.opentranclient.source_lang = lang_ctrlr.source_lang.code97 self.opentranclient.target_lang = lang_ctrlr.target_lang.code98 self.__setup_lang_watchers()99 self.__setup_cursor_watcher()100 def __setup_cursor_watcher(self):101 unitview = self.main_controller.unit_controller.view102 def cursor_changed(cursor):103 self.__start_query()104 store_ctrlr = self.main_controller.store_controller105 def store_loaded(store_ctrlr):106 if hasattr(self, '_cursor_connect_id'):107 self.cursor.disconnect(self._cursor_connect_id)108 self.cursor = store_ctrlr.cursor109 self._cursor_connect_id = self.cursor.connect('cursor-changed', cursor_changed)110 cursor_changed(self.cursor)111 store_ctrlr.connect('store-loaded', store_loaded)112 if store_ctrlr.store:113 store_loaded(store_ctrlr)114 def __setup_lang_watchers(self):115 def client_lang_changed(client, lang):116 self.cache = {}117 self._init_matcher()118 self.__start_query()119 self._connect_ids.append((120 self.opentranclient.connect('source-lang-changed', client_lang_changed),121 self.opentranclient122 ))123 self._connect_ids.append((124 self.opentranclient.connect('target-lang-changed', client_lang_changed),125 self.opentranclient126 ))127 lang_controller = self.main_controller.lang_controller128 self._connect_ids.append((129 lang_controller.connect(130 'source-lang-changed',131 lambda _c, lang: self.opentranclient.set_source_lang(lang)132 ),133 lang_controller134 ))135 self._connect_ids.append((136 lang_controller.connect(137 'target-lang-changed',138 lambda _c, lang: self.opentranclient.set_target_lang(lang)139 ),140 lang_controller141 ))142 def __setup_opentrantm_lang_watchers(self):143 def set_lang(ctrlr, lang):144 self.cache = {}145 self._init_matcher()146 self._connect_ids.append((147 self.opentrantm.tmclient.connect('source-lang-changed', set_lang),148 self.opentrantm.tmclient149 ))150 self._connect_ids.append((151 self.opentrantm.tmclient.connect('target-lang-changed', set_lang),152 self.opentrantm.tmclient153 ))154 def __start_query(self):155 unit = self.main_controller.unit_controller.current_unit156 if not unit:157 return158 query_str = unit.source159 if not self.cache.has_key(query_str):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyshould automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful