# include # include # include # include using namespace std; # include "levenshtein_matrix.hpp" int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // levenshtein_matrix_test() tests levenshtein_matrix(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 10 September 2022 // // Author: // // John Burkardt // { int *d; int i; int j; int m; int n; string s1 = "water"; string s2 = "kitten"; string s3 = "saturday"; string s4 = "pheromones"; string t1 = "wine"; string t2 = "sitting"; string t3 = "sunday"; string t4 = "photographer"; timestamp ( ); cout << "\n"; cout << "levenshtein_matrix_test():\n"; cout << " C++ version\n"; cout << " levenshtein_matrix() computes the Levenshtein matrix\n"; cout << " associated with the computation of the Levenshtein\n"; cout << " distance between two strings.\n"; m = s1.length ( ); n = t1.length ( ); d = levenshtein_matrix ( m, s1, n, t1 ); cout << "\n"; cout << " S = '" << s1 << "'\n"; cout << " T = '" << t1 << "'\n"; for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { cout << " " << setw(2) << d[i+j*(m+1)]; } cout << "\n"; } delete [] d; m = s2.length ( ); n = t2.length ( ); d = levenshtein_matrix ( m, s2, n, t2 ); cout << "\n"; cout << " S = '" << s2 << "'\n"; cout << " T = '" << t2 << "'\n"; for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { cout << " " << setw(2) << d[i+j*(m+1)]; } cout << "\n"; } delete [] d; m = s3.length ( ); n = t3.length ( ); d = levenshtein_matrix ( m, s3, n, t3 ); cout << "\n"; cout << " S = '" << s3 << "'\n"; cout << " T = '" << t3 << "'\n"; for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { cout << " " << setw(2) << d[i+j*(m+1)]; } cout << "\n"; } delete [] d; m = s4.length ( ); n = t4.length ( ); d = levenshtein_matrix ( m, s4, n, t4 ); cout << "\n"; cout << " S = '" << s4 << "'\n"; cout << " T = '" << t4 << "'\n"; for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { cout << " " << setw(2) << d[i+j*(m+1)]; } cout << "\n"; } delete [] d; // // Terminate. // cout << "\n"; cout << "levenshtein_matrix_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }