edit-distance.h
Go to the documentation of this file.
1 // util/edit-distance.h
2 
3 // Copyright 2009-2011 Microsoft Corporation; Haihua Xu
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #ifndef KALDI_UTIL_EDIT_DISTANCE_H_
22 #define KALDI_UTIL_EDIT_DISTANCE_H_
23 #include <vector>
24 #include <set>
25 #include <algorithm>
26 #include <limits>
27 #include <cassert>
28 #include <utility>
29 #include "util/edit-distance-inl.h"
30 #include "base/kaldi-types.h"
31 
32 namespace kaldi {
33 
34 // Compute the edit-distance between two strings.
35 template<class T>
36 int32 LevenshteinEditDistance(const std::vector<T> &a,
37  const std::vector<T> &b);
38 
39 
40 // edit distance calculation with conventional method.
41 // note: noise word must be filtered out from the hypothesis and
42 // reference sequence
43 // before the following procedure conducted.
44 template<class T>
45 int32 LevenshteinEditDistance(const std::vector<T> &ref,
46  const std::vector<T> &hyp,
47  int32 *ins, int32 *del, int32 *sub);
48 
49 // This version of the edit-distance computation outputs the alignment
50 // between the two. This is a vector of pairs of (symbol a, symbol b).
51 // The epsilon symbol (eps_symbol) must not occur in sequences a or b.
52 // Where one aligned to no symbol in the other (insertion or deletion),
53 // epsilon will be the corresponding member of the pair.
54 // It returns the edit-distance between the two strings.
55 
56 template<class T>
57 int32 LevenshteinAlignment(const std::vector<T> &a,
58  const std::vector<T> &b,
59  T eps_symbol,
60  std::vector<std::pair<T, T> > *output);
61 
62 } // end namespace kaldi
63 
64 #endif // KALDI_UTIL_EDIT_DISTANCE_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int32 LevenshteinAlignment(const std::vector< T > &a, const std::vector< T > &b, T eps_symbol, std::vector< std::pair< T, T > > *output)
kaldi::int32 int32
int32 LevenshteinEditDistance(const std::vector< T > &a, const std::vector< T > &b)