#!/usr/bin/perl -w
################################################################
# LWscore.pl : Sinkov's Log-Weight score for a list of text    #
#                chunks                                        #
#--------------------------------------------------------------#
# Compute scores for membership in a language                  #
#   English version                                            #
#                                                              #
# List of texts from STDIN                                     #
# Output: a list of pairs (text, score) where                  #
#   text is the text chunk under test,                         #
#   score is the Log-Weight score.                             #
#--------------------------------------------------------------#
# Transliteration of special characters according to English   #
#   rules                                                      #
#--------------------------------------------------------------#
# Klaus Pommerening 2014-May-29                                #
#                                                              #
# This program is freeware. Use it as you like.                #
# Usual disclaimers apply.                                     #
################################################################

require "auxcrypt.pl";                # Use &to26eng

# Hash table with weights
%sctable = (A => 1.9,
            B => 1.2,
            C => 1.4,
            D => 1.6,
            E => 2.1,
            F => 1.3,
            G => 1.3,
            H => 1.8,
            I => 1.8,
            J => 0.3,
            K => 0.9,
            L => 1.6,
            M => 1.4,
            N => 1.8,
            O => 1.9,
            P => 1.3,
            Q => 0.0,
            R => 1.8,
            S => 1.8,
            T => 1.9,
            U => 1.4,
            V => 1.0,
            W => 1.4,
            X => 0.0,
            Y => 1.3,
            Z => 0.0);

while($a = <STDIN>) {
  $testtext = &to26eng($a);
  print $testtext;
  @testlett = split(//,$testtext);
  $score = 0;
  for ($i = 0; $i < @testlett; $i++) {
    $score += $sctable{$testlett[$i]};
    }
  printf (" %.1f\n", $score);
  }
