MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / edit_distance

Function edit_distance

src/models/miotts/session.cpp:522–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520
521template <typename T>
522int64_t edit_distance(const std::vector<T> & ref, const std::vector<T> & hyp) {
523 if (ref.empty()) {
524 return static_cast<int64_t>(hyp.size());
525 }
526 if (hyp.empty()) {
527 return static_cast<int64_t>(ref.size());
528 }
529 std::vector<int64_t> dp(hyp.size() + 1);
530 std::iota(dp.begin(), dp.end(), 0);
531 for (size_t i = 0; i < ref.size(); ++i) {
532 int64_t prev = dp[0];
533 dp[0] = static_cast<int64_t>(i + 1);
534 for (size_t j = 0; j < hyp.size(); ++j) {
535 const int64_t temp = dp[j + 1];
536 const int64_t cost = ref[i] == hyp[j] ? 0 : 1;
537 dp[j + 1] = std::min({dp[j + 1] + 1, dp[j] + 1, prev + cost});
538 prev = temp;
539 }
540 }
541 return dp.back();
542}
543
544double asr_error(const std::string & reference, const std::string & hypothesis, const std::string & language) {
545 if (language == "en") {

Callers 1

asr_errorFunction · 0.70

Calls 5

minFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected