File size: 2,192 Bytes
67068c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
#include <vector>

// 包含您提供的 postprocess.cpp 檔案
// 注意:在實際編譯時,您需要將這兩個檔案一起編譯。
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;

    // 將 std::string 轉換為 C-style 字串
    const char* query_cstr = query.c_str();
    const char* pred_class_cstr = pred_class.c_str();

    // 呼叫 postprocess 函式
    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() {
    // 測試案例 1: 處理區域 ID (主駕)
    run_test("案例 1: 處理區域 ID", "請打開駕駛座的車窗", "WINDOW_POS%increase");

    // 測試案例 2: 處理開關指令 (關閉天窗)
    run_test("案例 2: 處理開關指令", "關閉天窗", "POWER_SUNSHADE");

    // 測試案例 3: 處理中文數字 (二十六)
    run_test("案例 3: 處理中文數字", "把空調溫度調到二十六度", "HVAC_TEMPERATURE_SET");

    // 測試案例 4: 處理最高溫度
    run_test("案例 4: 處理最高溫度", "把冷氣調到最冷", "HVAC_TEMPERATURE_SET");
    
    // 測試案例 5: 處理預設值 (HVAC_TEMPERATURE_SET)
    run_test("案例 5: 處理預設值", "打開空調", "HVAC_TEMPERATURE_SET");

    // 測試案例 6: 處理不存在的類別 (應回傳空 JSON 陣列)
    run_test("案例 6: 不存在類別", "這是一個不存在的測試", "NON_EXISTING_CLASS");

    return 0;
}