def get(self, request): level = request.GET.get('level', None) access_levels = ['district', 'warehouse', 'ip', 'facility'] access_areas = [] if level and level.lower() in access_levels: access_areas = pydash.reject(Score.objects.values_list(level, flat=True).distinct(), lambda x: len(x) < 1) return Response(access_areas)
def get(self, request): level = request.GET.get('level', None) access_levels = ['district', 'warehouse', 'ip', 'facility'] access_areas = [] if level and level.lower() in access_levels: access_areas = pydash.reject( Score.objects.values_list(level, flat=True).distinct(), lambda x: len(x) < 1) return Response(access_areas)
def get(self, request): level = request.GET.get("level", None) access_levels = ["district", "warehouse", "ip", "facility"] access_areas = [] if level and level.lower() in access_levels: access_areas = pydash.reject( Score.objects.values_list(level, flat=True).distinct(), lambda x: len(x) < 1, ) return Response(access_areas)
def get_bot_response(text): sentences = (chain(re.split( PUNCTUATION_REGEX, text)).reject(is_empty).map(clean_sentence).value()) if len(sentences) <= 0: return NO_INTENT_DETECTED_ANSWER lemmatized_sentences = reject( [lemmatize_sentence(nlp(sentence)) for sentence in sentences], is_empty, ) X = [ sentence_to_feature_vector(sentence, bag_of_words) for sentence in lemmatized_sentences ] predictions = model.predict(X) largest_index = np.argmax(predictions, axis=1) largest_values = np.take_along_axis(predictions, np.expand_dims(largest_index, axis=-1), axis=-1) # last user intent was not detected correctly if largest_values[-1][0] < MINIMUM_THRESHOLD: return NO_INTENT_DETECTED_ANSWER answers = [ random.choice(intents_json[idx]["responses"]) for idx in largest_index ] for idx in largest_index: if "date" in intents_json[idx]["extract"]: extracted_date = get_date(sentences[-1]) answers[-1] = answers[-1].replace("<date>", str(extracted_date)) if "place" in intents_json[idx]["extract"]: extracted_places = get_places(sentences[-1], nlp) answers[-1] = answers[-1].replace("<place>", ",".join(extracted_places)) if "number" in intents_json[idx]["extract"]: extracted_numbers = get_numbers(sentences[-1]) answers[-1] = answers[-1].replace("<number>", ",".join(extracted_numbers)) return { "answer": " ".join(answers), "intent": intents_json[largest_index[-1]]["tag"], "nextStates": intents_json[largest_index[-1]]["nextStates"], }
def persist_multiple_order_records(report): facilities_with_multiple_orders = pydash.reject( report.locs, lambda f: facility_has_single_order(f)) all = pydash.map_(facilities_with_multiple_orders, build_mof(report)) MultipleOrderFacility.objects.filter(cycle=report.cycle).delete() MultipleOrderFacility.objects.bulk_create(all)
def test_reject(case, expected): assert _.reject(*case) == expected
def persist_multiple_order_records(report): facilities_with_multiple_orders = pydash.reject(report.locs, lambda f: facility_has_single_order(f)) all = pydash.collect(facilities_with_multiple_orders, build_mof(report)) MultipleOrderFacility.objects.filter(cycle=report.cycle).delete() MultipleOrderFacility.objects.bulk_create(all)