|
@@ -0,0 +1,37 @@
|
|
|
|
+from django.conf import settings
|
|
|
|
+from requests import post
|
|
|
|
+import json
|
|
|
|
+
|
|
|
|
+nlu_server_url = settings.NLU_SERVER_URI
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def model_inference(text):
|
|
|
|
+ url = nlu_server_url + '/model/parse'
|
|
|
|
+ payload = {'text': text}
|
|
|
|
+ headers = {'content-type': 'application/json'}
|
|
|
|
+
|
|
|
|
+ response = post(url, data=json.dumps(payload), headers=headers)
|
|
|
|
+ if response.status_code == 200:
|
|
|
|
+ return response.json()
|
|
|
|
+ return response
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def analyze_inference(response):
|
|
|
|
+ '''
|
|
|
|
+ response has four property
|
|
|
|
+ ['intent', 'entities', 'intent_ranking', 'text']
|
|
|
|
+ we took all intents that has more than 10% of intent confident.
|
|
|
|
+ all the intents that has bellow confidence has been omitted.
|
|
|
|
+ :param response:
|
|
|
|
+ :return: dictionary with key of intent and value of it's confident.
|
|
|
|
+ '''
|
|
|
|
+
|
|
|
|
+ res_intents = response.get('intent_ranking')
|
|
|
|
+ intents = {}
|
|
|
|
+ for intent in res_intents:
|
|
|
|
+ key = intent.get('name')
|
|
|
|
+ values = intent.get('confidence')
|
|
|
|
+ if values > 0.1:
|
|
|
|
+ intents[key] = int(values*100)
|
|
|
|
+
|
|
|
|
+ return intents
|