src/main/java/eu/digitisation/ngram/NgramModel.java
public double logPerWordLikelihood(boolean caseSensitive) {
        try {
            Charset encoding = Charset.forName(System.getProperty("file.encoding"));
            WordScanner scanner = new WordScanner(System.in, encoding);

            String word;
            double result = 0;
            int numWords = 0;
            while ((word = scanner.nextWord()) != null) {
                ++numWords;
                if (caseSensitive) {
                    result -= logWordProb(word);
                } else {
                    result -= logWordProb(word.toLowerCase());
                }
            }

            return result / numWords / Math.log(2);

        } catch (IOException ex) {
            Messages.severe(NgramModel.class
                    .getName() + ": " + ex);
        }
        return Double.POSITIVE_INFINITY;
    }
/**
     * Reads input text from standard input and computes per-word cross entropy.
     *
     * @param caseSensitive true if the model is case sensitive
     * @return the log-likelihood of input text (per word).
     */
Reads input text from standard input and computes per-word cross entropy.
@param caseSensitive true if the model is case sensitive
@return the log-likelihood of input text (per word).
Reads input text from standard input and computes per - word cross entropy . @param caseSensitive true if the model is case sensitive @return the log - likelihood of input text ( per word ) .
public double logPerWordLikelihood(boolean caseSensitive) {
        try {
            Charset encoding = Charset.forName(System.getProperty("file.encoding"));
            WordScanner scanner = new WordScanner(System.in, encoding);
            String word;
            double result = 0;
            int numWords = 0;
            while ((word = scanner.nextWord()) != null) {
                ++numWords;
                if (caseSensitive) {
                    result -= logWordProb(word);
                } else {
                    result -= logWordProb(word.toLowerCase());
                }
            }
            return result / numWords / Math.log(2);
        } catch (IOException ex) {
            Messages.severe(NgramModel.class
                    .getName() + ": " + ex);
        }
        return Double.POSITIVE_INFINITY;
    }
public double logPerWordLikelihood ( boolean caseSensitive ) { try { Charset encoding = Charset . forName ( System . getProperty ( "file.encoding" ) ) ; WordScanner scanner = new WordScanner ( System . in , encoding ) ; String word ; double result = 0 ; int numWords = 0 ; while ( ( word = scanner . nextWord ( ) ) != null ) { ++ numWords ; if ( caseSensitive ) { result -= logWordProb ( word ) ; } else { result -= logWordProb ( word . toLowerCase ( ) ) ; } } return result / numWords / Math . log ( 2 ) ; } catch ( IOException ex ) { Messages . severe ( NgramModel . class . getName ( ) + ": " + ex ) ; } return Double . POSITIVE_INFINITY ; }
Reads input text from standard input and computes per-word cross entropy.
Reads input text from standard input and computes per - word cross entropy .