|
|
#include <iostream> |
|
|
#include <string> |
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
const char* postprocess_c(const char* query_cstr, const char* pred_class_cstr); |
|
|
void free_string(char* s); |
|
|
} |
|
|
|
|
|
|
|
|
void run_test(const std::string& test_name, const std::string& query, const std::string& pred_class) { |
|
|
std::cout << "--- 執行測試: " << test_name << " ---" << std::endl; |
|
|
std::cout << "輸入語句: " << query << std::endl; |
|
|
std::cout << "預測類別: " << pred_class << std::endl; |
|
|
|
|
|
|
|
|
const char* query_cstr = query.c_str(); |
|
|
const char* pred_class_cstr = pred_class.c_str(); |
|
|
|
|
|
|
|
|
const char* result_cstr = postprocess_c(query_cstr, pred_class_cstr); |
|
|
|
|
|
if (result_cstr) { |
|
|
std::cout << "回傳結果 (JSON):" << std::endl; |
|
|
std::cout << result_cstr << std::endl; |
|
|
|
|
|
|
|
|
char* mutable_result = const_cast<char*>(result_cstr); |
|
|
free_string(mutable_result); |
|
|
} else { |
|
|
std::cout << "回傳了空的結果。" << std::endl; |
|
|
} |
|
|
|
|
|
std::cout << std::endl; |
|
|
} |
|
|
|
|
|
int main() { |
|
|
|
|
|
run_test("案例 1: 處理區域 ID", "請打開駕駛座的車窗", "WINDOW_POS%increase"); |
|
|
|
|
|
|
|
|
run_test("案例 2: 處理開關指令", "關閉天窗", "POWER_SUNSHADE"); |
|
|
|
|
|
|
|
|
run_test("案例 3: 處理中文數字", "把空調溫度調到二十六度", "HVAC_TEMPERATURE_SET"); |
|
|
|
|
|
|
|
|
run_test("案例 4: 處理最高溫度", "把冷氣調到最冷", "HVAC_TEMPERATURE_SET"); |
|
|
|
|
|
|
|
|
run_test("案例 5: 處理預設值", "打開空調", "HVAC_TEMPERATURE_SET"); |
|
|
|
|
|
|
|
|
run_test("案例 6: 不存在類別", "這是一個不存在的測試", "NON_EXISTING_CLASS"); |
|
|
|
|
|
return 0; |
|
|
} |