# include # include # include # include # include "levenshtein_matrix.h" int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: levenshtein_matrix_test() tests levenshtein_matrix(). Licensing: This code is distributed under the MIT license. Modified: 18 March 2018 Author: John Burkardt */ { int *d; int i; int j; int m; int n; char *s1 = "water"; char *s2 = "kitten"; char *s3 = "saturday"; char *s4 = "pheromones"; char *t1 = "wine"; char *t2 = "sitting"; char *t3 = "sunday"; char *t4 = "photographer"; timestamp ( ); printf ( "\n" ); printf ( "levenstein_matrix_test():\n" ); printf ( " C version\n" ); printf ( " levenstein_matrix() computes the Levenshtein matrix\n" ); printf ( " associated with the computation of the Levenshtein\n" ); printf ( " distance between two strings.\n" ); m = strlen ( s1 ); n = strlen ( t1 ); d = levenshtein_matrix ( m, s1, n, t1 ); printf ( "\n" ); printf ( " S = '%s'\n", s1 ); printf ( " T = '%s'\n", t1 ); for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { printf ( " %2d", d[i+j*(m+1)] ); } printf ( "\n" ); } free ( d ); m = strlen ( s2 ); n = strlen ( t2 ); d = levenshtein_matrix ( m, s2, n, t2 ); printf ( "\n" ); printf ( " S = '%s'\n", s2 ); printf ( " T = '%s'\n", t2 ); for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { printf ( " %2d", d[i+j*(m+1)] ); } printf ( "\n" ); } free ( d ); m = strlen ( s3 ); n = strlen ( t3 ); d = levenshtein_matrix ( m, s3, n, t3 ); printf ( "\n" ); printf ( " S = '%s'\n", s3 ); printf ( " T = '%s'\n", t3 ); for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { printf ( " %2d", d[i+j*(m+1)] ); } printf ( "\n" ); } free ( d ); m = strlen ( s4 ); n = strlen ( t4 ); d = levenshtein_matrix ( m, s4, n, t4 ); printf ( "\n" ); printf ( " S = '%s'\n", s4 ); printf ( " T = '%s'\n", t4 ); for ( i = 0; i <= m; i++ ) { for ( j = 0; j <= n; j++ ) { printf ( " %2d", d[i+j*(m+1)] ); } printf ( "\n" ); } free ( d ); /* Terminate. */ printf ( "\n" ); printf ( "levenstein_matrix_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }