function dictionary_encode ( )

%*****************************************************************************80
%
%% DICTIONARY_ENCODE applies dictionary encoding to a text file.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 November 2016
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'DICTIONARY_ENCODE:\n' );
  fprintf ( 1, '  Apply dictionary encoding to a file.\n' );

  list = textread ( 'gettysburg_address2.txt', '%s' );
  list_num = length ( list );

  ch_num = 0;
  for i = 1 : list_num
    ch_num = ch_num + length ( list{i} );
  end
  fprintf ( 1, '  Text contains %d characters\n', ch_num );
  fprintf ( 1, '  Text contains %d words\n', list_num );

  list2 = unique ( list );
  list2_num = length ( list2 );
  fprintf ( 1, '  Text contains %d unique words\n', list2_num );

  for i = 1 : list2_num
    fprintf ( 1, '%d  %s\n', i, list2{i} );
  end

  output1 = fopen ( 'gettysburg_address_dictionary.txt', 'wt' );
  for i = 1 : list2_num
    fprintf ( output1, '%s\n', list2{i} );
  end
  fclose ( output1 );

  output2 = fopen ( 'gettysburg_address_encoded.txt', 'wt' );
  for i = 1 : list_num
    index = find ( ismember ( list2, list{i} ) );
    fprintf ( output2, ' %d', index );
  end
  fclose ( output2 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'DICTIONARY_ENCODE:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end

