def update_filters_labeller(project_id): ''' Update filters for a labeller and receive the updated labeller state. GET: project_id: ID for "link" project POST: module_params: must: #TODO: document must_not: #TODO: document ''' _, module_params = _parse_request() logging.info('update_musts got:', module_params) must = module_params['must'] must_not = module_params['must_not'] proj = ESLinker(project_id=project_id) labeller = proj.labeller_from_json() labeller.update_musts(must, must_not) proj.labeller_to_json(labeller) encoder = MyEncoder() return jsonify(error=False, result=encoder.encode(labeller.to_emit()))
def update_targets_labeller(project_id): ''' Update filters for a labeller and receive the updated labeller state. GET: project_id: ID for "link" project POST: module_params: target_precision: value between 0 and 1 representing the minimal acceptable value for precision (results with lower values will be strongly penalised) target_recall:value between 0 and 1 representing the minimal acceptable value for recall (results with lower values will be strongly penalised) ''' _, module_params = _parse_request() logging.info('update_musts got:', module_params) t_p = module_params['target_precision'] t_r = module_params['target_recall'] proj = ESLinker(project_id=project_id) labeller = proj.labeller_from_json() labeller.update_targets(t_p, t_r) proj.labeller_to_json(labeller) encoder = MyEncoder() return jsonify(error=False, result=encoder.encode(labeller.to_emit()))
def update_labeller(project_id): ''' Send an user input to the labeller and receive the updated labeller state GET: project_id: ID for "link" project POST: module_params: user_input: #TODO: document ''' _, module_params = _parse_request() logging.info(module_params) user_input = module_params['user_input'] proj = ESLinker(project_id=project_id) labeller = proj.labeller_from_json() if labeller.answer_is_valid(user_input): labeller.update(user_input) else: raise ValueError('Answer received "{0}" is not valid'.format(user_input)) proj.labeller_to_json(labeller) encoder = MyEncoder() return jsonify(error=False, result=encoder.encode(labeller.to_emit()))
def add_search(project_id): ''' # Perform search on specific user-specified terms GET: project_id: ID for "link" project POST: module_params: col_to_search: A dictionnary mapping the column name to query string Ex: [{'columns': ['col1', 'col2'], 'values_to_search': ['val1']}, ...] max_num_results: (optional) Max number of results for search ''' _, module_params = _parse_request() proj = ESLinker(project_id) labeller = proj.labeller_from_json() # TODO: change this hack def temp(cols): if isinstance(cols, str): return cols elif isinstance(cols, list): return tuple(cols) pms = {temp(search['columns']): search['values_to_search'] for search in module_params['search']} labeller.add_custom_search(pms, module_params.get('max_num_results', 15)) proj.labeller_to_json(labeller) encoder = MyEncoder() return jsonify(error=False, result=encoder.encode(labeller.to_emit()))
def _create_es_labeller(project_id, *argv): ''' Create an "es" labeller and pickle to project ARGUMENTS (GET): - project_id ARGUMENTS (POST): - data_params: none - module_params: none ''' proj = ESLinker(project_id=project_id) labeller = proj._gen_es_labeller() proj.labeller_to_json(labeller) return
def clear_search(project_id): ''' Remove user search items from the list of next labeller proposals ''' _, module_params = _parse_request() proj = ESLinker(project_id) labeller = proj.labeller_from_json() labeller.clear_custom_search() proj.labeller_to_json(labeller) encoder = MyEncoder() return jsonify(error=False, result=encoder.encode(labeller.to_emit()))
def _create_es_labeller(project_id, _, module_params): ''' Create an "es" labeller and pickle to project ARGUMENTS (GET): - project_id ARGUMENTS (POST): - data_params: none - module_params: force: (false) Set to true if ''' proj = ESLinker(project_id=project_id) if module_params is None: module_params = {} print('ES_labeller module_params:', module_params) if not proj._has_labeller() or module_params.get('force', False): print('yes here') labeller = proj._gen_es_labeller() proj.labeller_to_json(labeller) return