Example #1
0
 def load_pipeline_ops(last_id):
     ans = []
     if plugins.runtime.CONC_PERSISTENCE.exists:
         with plugins.runtime.CONC_PERSISTENCE as cp:
             data = cp.open(last_id)
             if data is not None:
                 ans.append(build_conc_form_args(
                     data.get('corpora', []), data['lastop_form'], data['id']))
             limit = 100
             while data is not None and data.get('prev_id') and limit > 0:
                 data = cp.open(data['prev_id'])
                 ans.insert(0, build_conc_form_args(
                     data.get('corpora', []), data['lastop_form'], data['id']))
                 limit -= 1
                 if limit == 0:
                     logging.getLogger(__name__).warning('Reached hard limit when loading query pipeline {0}'.format(
                         last_id))
     return ans
Example #2
0
 def load_pipeline_ops(last_id: str) -> List[ConcFormArgs]:
     ans = []
     # here checking if instance exists -> we can ignore type check error cp.open does not exist on None
     if plugins.runtime.CONC_PERSISTENCE.exists:
         with plugins.runtime.CONC_PERSISTENCE as cp:
             data = cp.open(last_id)  # type: ignore
             if data is not None:
                 ans.append(build_conc_form_args(
                     data.get('corpora', []), data.get('lastop_form', {}), data['id']))
             limit = 100
             while data is not None and data.get('prev_id') and limit > 0:
                 data = cp.open(data['prev_id'])  # type: ignore
                 ans.insert(0, build_conc_form_args(
                     data.get('corpora', []), data.get('lastop_form', {}), data['id']))
                 limit -= 1
                 if limit == 0:
                     logging.getLogger(__name__).warning('Reached hard limit when loading query pipeline {0}'.format(
                         last_id))
     return ans
Example #3
0
 def load_pipeline_ops(last_id):
     ans = []
     if plugins.runtime.CONC_PERSISTENCE.exists:
         with plugins.runtime.CONC_PERSISTENCE as cp:
             data = cp.open(last_id)
             if data is not None:
                 ans.append(
                     build_conc_form_args(data['lastop_form'], data['id']))
             limit = 100
             while data is not None and data.get('prev_id') and limit > 0:
                 data = cp.open(data['prev_id'])
                 ans.insert(
                     0, build_conc_form_args(data['lastop_form'],
                                             data['id']))
                 limit -= 1
                 if limit == 0:
                     logging.getLogger(__name__).warning(
                         'Reached hard limit when loading query pipeline {0}'
                         .format(last_id))
     return ans
Example #4
0
    def _attach_query_params(self, tpl_out: Dict[str, Any]):
        """
        Attach data required by client-side forms which are
        part of the current query pipeline (i.e. initial query, filters,
        sorting, samples,...)
        """
        corpus_info = self.get_corpus_info(getattr(self.args, 'corpname'))
        tpl_out['metadata_desc'] = corpus_info['metadata']['desc']
        tpl_out['input_languages'] = {}
        tpl_out['input_languages'][getattr(
            self.args, 'corpname')] = corpus_info['collator_locale']
        if self._prev_q_data is not None and 'lastop_form' in self._prev_q_data:
            op_key = self._prev_q_data['id']
            conc_forms_args = {
                op_key:
                build_conc_form_args(self._prev_q_data.get('corpora', []),
                                     self._prev_q_data['lastop_form'],
                                     op_key).to_dict()
            }
        else:
            conc_forms_args = {}
        # Attach new form args added by the current action.
        if len(self._auto_generated_conc_ops) > 0:
            conc_forms_args['__latest__'] = self._auto_generated_conc_ops[-1][
                1].to_dict()
        elif self._curr_conc_form_args is not None:  # we add main query only iff there are no auto-generated ops
            item_key = '__latest__' if self._curr_conc_form_args.is_persistent else '__new__'
            conc_forms_args[item_key] = self._curr_conc_form_args.to_dict()
        tpl_out['conc_forms_args'] = conc_forms_args

        corpora = self._select_current_aligned_corpora(active_only=True)
        tpl_out['conc_forms_initial_args'] = dict(
            query=QueryFormArgs(corpora=corpora, persist=False).to_dict(),
            filter=FilterFormArgs(
                maincorp=getattr(self.args, 'maincorp') if getattr(
                    self.args, 'maincorp') else getattr(self.args, 'corpname'),
                persist=False).to_dict(),
            sort=SortFormArgs(persist=False).to_dict(),
            sample=SampleFormArgs(persist=False).to_dict(),
            shuffle=ShuffleFormArgs(persist=False).to_dict(),
            firsthits=FirstHitsFilterFormArgs(
                persist=False,
                doc_struct=self.corp.get_conf('DOCSTRUCTURE')).to_dict())
Example #5
0
    def _attach_query_params(self, tpl_out):
        """
        Attach data required by client-side forms which are
        part of the current query pipeline (i.e. initial query, filters,
        sorting, samples,...)
        """
        corpus_info = self.get_corpus_info(self.args.corpname)
        tpl_out['metadata_desc'] = corpus_info['metadata']['desc']
        tpl_out['input_languages'] = {}
        tpl_out['input_languages'][self.args.corpname] = corpus_info['collator_locale']
        if self._prev_q_data is not None and 'lastop_form' in self._prev_q_data:
            op_key = self._prev_q_data['id']
            conc_forms_args = {
                op_key: build_conc_form_args(self._prev_q_data.get('corpora', []), self._prev_q_data['lastop_form'],
                                             op_key).to_dict()
            }
        else:
            conc_forms_args = {}
        # Attach new form args added by the current action.
        if len(self._auto_generated_conc_ops) > 0:
            conc_forms_args['__latest__'] = self._auto_generated_conc_ops[-1][1].to_dict()
        elif self._curr_conc_form_args is not None:  # we add main query only iff there are no auto-generated ops
            item_key = '__latest__' if self._curr_conc_form_args.is_persistent else '__new__'
            conc_forms_args[item_key] = self._curr_conc_form_args.to_dict()
        tpl_out['conc_forms_args'] = conc_forms_args

        corpora = self._select_current_aligned_corpora(active_only=True)
        tpl_out['conc_forms_initial_args'] = dict(
            query=QueryFormArgs(corpora=corpora, persist=False).to_dict(),
            filter=FilterFormArgs(maincorp=self.args.maincorp if self.args.maincorp else self.args.corpname,
                                  persist=False).to_dict(),
            sort=SortFormArgs(persist=False).to_dict(),
            sample=SampleFormArgs(persist=False).to_dict(),
            shuffle=ShuffleFormArgs(persist=False).to_dict(),
            firsthits=FirstHitsFilterFormArgs(persist=False, doc_struct=self.corp.get_conf('DOCSTRUCTURE')).to_dict()
        )