Greg Thompson commited on
Commit
64033b8
1 Parent(s): da5f9ac

Update nlu endpoint to handle new mathtext features

Browse files
Files changed (2) hide show
  1. mathtext_fastapi/nlu.py +7 -29
  2. scripts/make_request.py +39 -36
mathtext_fastapi/nlu.py CHANGED
@@ -72,25 +72,10 @@ def evaluate_message_with_nlu(message_data):
72
  'message_updated_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],
73
  }
74
  message_text = message_data['message_body']
75
- message_text_arr = re.split(", |,| ", message_text.strip())
76
 
77
- # TODO: Replace this with appropriate utility function (is_int, is_float, render_int_or_float)
78
- nlu_response = test_for_float_or_int(message_data, message_text)
79
- if len(nlu_response) > 0:
80
- return nlu_response
81
 
82
- # TODO: Replace this with appropriate utility function
83
- nlu_response = test_for_number_sequence(message_text_arr, message_data, message_text)
84
- if len(nlu_response) > 0:
85
- return nlu_response
86
-
87
- student_response_arr = run_text2int_on_each_list_item(message_text_arr)
88
-
89
- # '32202' is text2int's error code for non-integer student answers (ie., "I don't know")
90
- # If any part of the list is 32202, sentiment analysis will run
91
- # TODO: Need to replace this with logic that recognizes multiple intents (Maybe 36 = "sentiment analysis" & "integer")
92
- student_response_arr = run_text2int_on_each_list_item(message_text_arr)
93
- if 32202 in student_response_arr:
94
  sentiment_api_resp = sentiment(message_text)
95
  nlu_response = build_nlu_response_object(
96
  'sentiment',
@@ -98,18 +83,11 @@ def evaluate_message_with_nlu(message_data):
98
  sentiment_api_resp[0]['score']
99
  )
100
  else:
101
- if len(student_response_arr) > 1:
102
- nlu_response = build_nlu_response_object(
103
- 'integer',
104
- ','.join(str(num) for num in student_response_arr),
105
- ''
106
- )
107
- else:
108
- nlu_response = build_nlu_response_object(
109
- 'integer',
110
- student_response_arr[0],
111
- ''
112
- )
113
 
114
  prepare_message_data_for_logging(message_data, nlu_response)
115
  return nlu_response
 
72
  'message_updated_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],
73
  }
74
  message_text = message_data['message_body']
 
75
 
76
+ number_api_resp = text2int(message_text.lower())
 
 
 
77
 
78
+ if number_api_resp == 32202:
 
 
 
 
 
 
 
 
 
 
 
79
  sentiment_api_resp = sentiment(message_text)
80
  nlu_response = build_nlu_response_object(
81
  'sentiment',
 
83
  sentiment_api_resp[0]['score']
84
  )
85
  else:
86
+ nlu_response = build_nlu_response_object(
87
+ 'integer',
88
+ number_api_resp,
89
+ ''
90
+ )
 
 
 
 
 
 
 
91
 
92
  prepare_message_data_for_logging(message_data, nlu_response)
93
  return nlu_response
scripts/make_request.py CHANGED
@@ -62,43 +62,46 @@ def run_simulated_request(endpoint, sample_answer, context=None):
62
  # run_simulated_request('text2int', 'seven thousand nine hundred fifty seven')
63
  # run_simulated_request('nlu', 'test message')
64
  # run_simulated_request('nlu', 'eight')
65
- # run_simulated_request('nlu', 'eight, nine, ten')
66
- # run_simulated_request('nlu', '8, 9, 10')
67
- # run_simulated_request('nlu', '8')
68
- # run_simulated_request('nlu', "I don't know")
69
- # run_simulated_request('nlu', 'Today is a wonderful day')
70
- # run_simulated_request('nlu', 'IDK 5?')
 
 
 
71
  # run_simulated_request('manager', '')
72
- run_simulated_request('manager', 'add')
73
- run_simulated_request('manager', 'subtract')
74
- run_simulated_request("question", {
75
- 'number_correct': 0,
76
- 'number_incorrect': 0,
77
- 'level': 'easy'
78
- })
79
- run_simulated_request("hint", {
80
- 'question_numbers': [1, 2, 3],
81
- 'right_answer': 3,
82
- 'number_correct': 0,
83
- 'number_incorrect': 0,
84
- 'level': 'easy',
85
- 'hints_used': 0
86
- })
87
- run_simulated_request("generate_question", {
88
- 'level': 'medium'
89
- })
90
- run_simulated_request("numbers_by_level", {
91
- 'level': 'medium'
92
- })
93
- run_simulated_request("number_sequence", {
94
- "current_number": 10,
95
- "ordinal_number": 2,
96
- "times": 1
97
- })
98
- run_simulated_request("level", {
99
- "current_level": "hard",
100
- "level_up": False
101
- })
102
  # run_simulated_request('manager', 'exit')
103
 
104
 
 
62
  # run_simulated_request('text2int', 'seven thousand nine hundred fifty seven')
63
  # run_simulated_request('nlu', 'test message')
64
  # run_simulated_request('nlu', 'eight')
65
+ run_simulated_request('nlu', 'eight, nine, ten')
66
+ run_simulated_request('nlu', '8, 9, 10')
67
+ run_simulated_request('nlu', '8')
68
+ run_simulated_request('nlu', "I don't know")
69
+ run_simulated_request('nlu', "I don't know eight")
70
+ run_simulated_request('nlu', "I don't 9")
71
+ run_simulated_request('nlu', "0.2")
72
+ run_simulated_request('nlu', 'Today is a wonderful day')
73
+ run_simulated_request('nlu', 'IDK 5?')
74
  # run_simulated_request('manager', '')
75
+ # run_simulated_request('manager', 'add')
76
+ # run_simulated_request('manager', 'subtract')
77
+ # run_simulated_request("question", {
78
+ # 'number_correct': 0,
79
+ # 'number_incorrect': 0,
80
+ # 'level': 'easy'
81
+ # })
82
+ # run_simulated_request("hint", {
83
+ # 'question_numbers': [1, 2, 3],
84
+ # 'right_answer': 3,
85
+ # 'number_correct': 0,
86
+ # 'number_incorrect': 0,
87
+ # 'level': 'easy',
88
+ # 'hints_used': 0
89
+ # })
90
+ # run_simulated_request("generate_question", {
91
+ # 'level': 'medium'
92
+ # })
93
+ # run_simulated_request("numbers_by_level", {
94
+ # 'level': 'medium'
95
+ # })
96
+ # run_simulated_request("number_sequence", {
97
+ # "current_number": 10,
98
+ # "ordinal_number": 2,
99
+ # "times": 1
100
+ # })
101
+ # run_simulated_request("level", {
102
+ # "current_level": "hard",
103
+ # "level_up": False
104
+ # })
105
  # run_simulated_request('manager', 'exit')
106
 
107