From 285058041cd5b0b281324707d17e941fc0b21d48 Mon Sep 17 00:00:00 2001 From: amansrivastav17 Date: Wed, 20 Mar 2019 11:58:25 +0530 Subject: [PATCH 1/2] added new url call to read unique values for text entity --- chatbot_ner/urls.py | 6 +++++- external_api/api.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/chatbot_ner/urls.py b/chatbot_ner/urls.py index 341208141..800ca2ab4 100755 --- a/chatbot_ner/urls.py +++ b/chatbot_ner/urls.py @@ -49,5 +49,9 @@ url(r'^entities/train_crf_model', external_api.train_crf_model), url(r'^entities/languages/v1/(?P.+)$', external_api.entity_language_view), - url(r'^entities/data/v1/(?P.+)$', external_api.entity_data_view) + url(r'^entities/data/v1/(?P.+)$', external_api.entity_data_view), + + # Read unique values for text entity + url(r'^entities/get_unique_values', external_api.read_unique_values_for_text_entity), + ] diff --git a/external_api/api.py b/external_api/api.py index 3be5bafe1..73a1f4222 100644 --- a/external_api/api.py +++ b/external_api/api.py @@ -62,6 +62,39 @@ def get_entity_word_variants(request): return HttpResponse(json.dumps(response), content_type='application/json', status=200) +def read_unique_values_for_text_entity(request): + """ + This function is used obtain the unique values for given text entity name. + Args: + request (HttpResponse): HTTP response from url + + Returns: + HttpResponse : With data consisting of a list of unique values. + """ + response = {"success": False, "error": "", "result": []} + try: + entity_name = request.GET.get(ENTITY_NAME) + datastore_obj = DataStore() + result = datastore_obj.get_entity_unique_values(entity_name=entity_name) + + response['result'] = result + response['success'] = True + + except (DataStoreSettingsImproperlyConfiguredException, + EngineNotImplementedException, + EngineConnectionException, FetchIndexForAliasException) as error_message: + response['error'] = str(error_message) + ner_logger.exception('Error: %s' % error_message) + return HttpResponse(json.dumps(response), content_type='application/json', status=500) + + except BaseException as e: + response['error'] = str(e) + ner_logger.exception('Error: %s' % e) + return HttpResponse(json.dumps(response), content_type='application/json', status=500) + + return HttpResponse(json.dumps(response), content_type='application/json', status=200) + + @csrf_exempt def update_dictionary(request): """ From e3b3b5171e8d91972226349910a5276ee5e57dd4 Mon Sep 17 00:00:00 2001 From: amansrivastav17 Date: Wed, 20 Mar 2019 12:29:18 +0530 Subject: [PATCH 2/2] change url call and refactored api call view --- chatbot_ner/urls.py | 2 +- external_api/api.py | 49 +++++++++++++++------------------------------ 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/chatbot_ner/urls.py b/chatbot_ner/urls.py index 800ca2ab4..6acd460b0 100755 --- a/chatbot_ner/urls.py +++ b/chatbot_ner/urls.py @@ -52,6 +52,6 @@ url(r'^entities/data/v1/(?P.+)$', external_api.entity_data_view), # Read unique values for text entity - url(r'^entities/get_unique_values', external_api.read_unique_values_for_text_entity), + url(r'^entities/values/v1/(?P.+)$', external_api.read_unique_values_for_text_entity), ] diff --git a/external_api/api.py b/external_api/api.py index 73a1f4222..b5dcc7b39 100644 --- a/external_api/api.py +++ b/external_api/api.py @@ -62,39 +62,6 @@ def get_entity_word_variants(request): return HttpResponse(json.dumps(response), content_type='application/json', status=200) -def read_unique_values_for_text_entity(request): - """ - This function is used obtain the unique values for given text entity name. - Args: - request (HttpResponse): HTTP response from url - - Returns: - HttpResponse : With data consisting of a list of unique values. - """ - response = {"success": False, "error": "", "result": []} - try: - entity_name = request.GET.get(ENTITY_NAME) - datastore_obj = DataStore() - result = datastore_obj.get_entity_unique_values(entity_name=entity_name) - - response['result'] = result - response['success'] = True - - except (DataStoreSettingsImproperlyConfiguredException, - EngineNotImplementedException, - EngineConnectionException, FetchIndexForAliasException) as error_message: - response['error'] = str(error_message) - ner_logger.exception('Error: %s' % error_message) - return HttpResponse(json.dumps(response), content_type='application/json', status=500) - - except BaseException as e: - response['error'] = str(e) - ner_logger.exception('Error: %s' % e) - return HttpResponse(json.dumps(response), content_type='application/json', status=500) - - return HttpResponse(json.dumps(response), content_type='application/json', status=200) - - @csrf_exempt def update_dictionary(request): """ @@ -357,3 +324,19 @@ def entity_data_view(request, entity_name): else: raise APIHandlerException("{0} is not allowed.".format(request.method)) + + +@external_api_response_wrapper +def read_unique_values_for_text_entity(request, entity_name): + """ + API call to View unique values for text entity. + """ + if request.method == 'GET': + try: + return dictionary_utils.get_entity_unique_values(entity_name=entity_name) + except (DataStoreSettingsImproperlyConfiguredException, + EngineNotImplementedException, + EngineConnectionException, FetchIndexForAliasException) as error_message: + raise APIHandlerException(str(error_message)) + else: + raise APIHandlerException("{0} is not allowed.".format(request.method))