@@ -91,19 +91,30 @@ std::vector<std::vector<CppEditop>> backtrack_all_paths(
9191 all_paths.insert (all_paths.end (), paths.begin (), paths.end ());
9292 current_path.pop_back ();
9393 }
94-
95- if (i > 0 && j > 0 ) {
96- double sub_cost = (a[i-1 ] == b[j-1 ]) ? 0.0 : replace_weight;
97- if (std::abs ((dp[i-1 ][j-1 ] + sub_cost) - current_cost) < tol) {
98- std::string out_char = (sub_cost == 0.0 ) ? std::string (1 , a[i-1 ]) : std::string (1 , b[j-1 ]);
99- CppEditop op (REPLACE, i-1 , j-1 , sub_cost, out_char);
94+
95+ if (i > 0 && j > 0 && a[i-1 ] != b[j-1 ]) {
96+ if (std::abs ((dp[i-1 ][j-1 ] + replace_weight) - current_cost) < tol) {
97+ std::string out_char = std::string (1 , b[j-1 ]);
98+ CppEditop op (REPLACE, i-1 , j-1 , replace_weight, out_char);
10099 current_path.push_back (op);
101100 auto paths = backtrack_all_paths (a, b, dp, i-1 , j-1 , current_path, replace_weight, insert_weight, delete_weight, swap_weight);
102101 all_paths.insert (all_paths.end (), paths.begin (), paths.end ());
103102 current_path.pop_back ();
104103 }
105104 }
106-
105+
106+ if (i > 0 && j > 0 && a[i-1 ] == b[j-1 ]) {
107+ double match_weight = 0.0 ; // We might want to make this non-zero in the future
108+ if (std::abs ((dp[i-1 ][j-1 ] + match_weight) - current_cost) < tol) {
109+ std::string out_char = std::string (1 , a[i-1 ]);
110+ CppEditop op (MATCH, i-1 , j-1 , match_weight, out_char);
111+ current_path.push_back (op);
112+ auto paths = backtrack_all_paths (a, b, dp, i-1 , j-1 , current_path, replace_weight, insert_weight, delete_weight, swap_weight);
113+ all_paths.insert (all_paths.end (), paths.begin (), paths.end ());
114+ current_path.pop_back ();
115+ }
116+ }
117+
107118 if (i > 1 && j > 1 &&
108119 a[i-1 ] == b[j-2 ] && a[i-2 ] == b[j-1 ] &&
109120 std::abs ((dp[i-2 ][j-2 ] + swap_weight) - current_cost) < tol) {
@@ -161,6 +172,7 @@ std::string editop_name_to_string(CppEditopName name) {
161172 case DELETE: return " DELETE" ;
162173 case REPLACE: return " REPLACE" ;
163174 case SWAP: return " SWAP" ;
175+ case MATCH: return " MATCH" ;
164176 default : return " UNKNOWN" ;
165177 }
166178}
0 commit comments