Download bert/cpp_postprocess/test.cpp from jva96160/DriveBert: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/jva96160/DriveBert/resolve/main/bert/cpp_postprocess/test.cpp
- Command line
-
hf download hf://jva96160/DriveBert/bert/cpp_postprocess/test.cpp
-
curl -L -o test.cpp https://huggingface.co/jva96160/DriveBert/resolve/main/bert/cpp_postprocess/test.cpp
2.19 kB
| // 包含您提供的 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; | |
| } |