perf: 基建干员专精干员名替换优化

[skip changelog]
This commit is contained in:
status102
2024-03-22 17:47:48 +08:00
parent 3d3d8c1036
commit 6eee1d85bc
2 changed files with 10 additions and 8 deletions

View File

@@ -8045,6 +8045,10 @@
[
"^\\[",
""
],
[
"]",
"\\n"
]
]
},

View File

@@ -53,28 +53,26 @@ bool asst::InfrastTrainingTask::analyze_status()
return true;
}
const auto& replace_map = Task.get<OcrTaskInfo>("CharsNameOcrReplace")->replace_map;
auto task_replace = Task.get<OcrTaskInfo>("InfrastTrainingOperatorAndSkill")->replace_map;
ranges::copy(replace_map, std::back_inserter(task_replace));
RegionOCRer rec_analyzer(image);
rec_analyzer.set_task_info("InfrastTrainingOperatorAndSkill");
rec_analyzer.set_replace(task_replace);
if (!rec_analyzer.analyze()) {
Log.error(__FUNCTION__, "recognition failed");
return false;
}
std::string raw_str = rec_analyzer.get_result().text;
size_t separation_pos = raw_str.find(']');
size_t separation_pos = raw_str.find('\n');
if (separation_pos == std::string::npos) {
Log.error(__FUNCTION__, "separate string failed");
return false;
}
// ']'前为干员名,']'后为技能名
// '\n'前为干员名,'\n'后为技能名
m_operator_name = raw_str.substr(0, separation_pos);
for (const auto& replace_map = Task.get<OcrTaskInfo>("CharsNameOcrReplace")->replace_map;
const auto& [regex, new_str] : replace_map) {
if (std::regex_search(m_operator_name, std::regex(regex))) {
m_operator_name = new_str;
}
}
m_skill_name = raw_str.substr(separation_pos + 1, raw_str.length() - separation_pos + 1);
// TODO: 根据角色职业增加换班功能