#!/usr/bin/perl -w
################################################################
# fritest.pl : Friedman's Test for a list of text chunks       #
#--------------------------------------------------------------#
# Compute scores for membership in a language                  #
#   French version, the ten most frequent letters are          #
#             EASNTIRULO                                       #
#                                                              #
# List of texts from STDIN                                     #
# Output: a list of pairs (text, score) where                  #
#   text is the text chunk under test,                         #
#   score is the Friedman rate                                 #
#     = the relative number of the most frequent letters in    #
#     the text chunk.                                          #
#   Example: The (French) score of CAESAR is 5/6 = 0.833.      #
#--------------------------------------------------------------#
# Klaus Pommerening 2014-May-18                                #
#                                                              #
# This program is freeware. Use it as you like.                #
# Usual disclaimers apply.                                     #
################################################################

require "auxcrypt.pl";                # Use &to26fra

while($a = <STDIN>) {
  $testtext = &to26fra($a);
  print $testtext;
  $rr = length($testtext);
  $nn = $testtext =~ s/[EASNTIRULO]//g;  # French version
  if (!$nn) {$nn = 0;}
  $score = 0;
  if ($rr > 0) {$score = $nn/$rr;}
  printf (" %1.2f\n", $score);
  }
