src/main/java/eu/digitisation/ngram/NgramModel.java
public double logWordProb(String word) {
        double res = 0;

        if (word.length() < 1) {
            throw new IllegalArgumentException("Cannot compute probability of empty word");
        } else {
            String input = BOS + word + EOS;
            for (int high = 2; high <= input.length(); ++high) {
                int low = Math.max(0, high - order);
                String s = input.substring(low, high);
                double p = smoothProb(s);
                if (p == 0) {
                    Messages.warning(s + " has 0 probability");
                    return Double.NEGATIVE_INFINITY;
                } else {
                    res += Math.log(p);
                }
            }
        }
        return res;
    }
/**
     * Compute probability of a word or text
     *
     * @param word a non-empty a sequence of characters
     * @return the log-probability (base e) of this string
     */
Compute probability of a word or text
@param word a non-empty a sequence of characters
@return the log-probability (base e) of this string
Compute probability of a word or text @param word a non - empty a sequence of characters @return the log - probability ( base e ) of this string
public double logWordProb(String word) {
        double res = 0;
        if (word.length() < 1) {
            throw new IllegalArgumentException("Cannot compute probability of empty word");
        } else {
            String input = BOS + word + EOS;
            for (int high = 2; high <= input.length(); ++high) {
                int low = Math.max(0, high - order);
                String s = input.substring(low, high);
                double p = smoothProb(s);
                if (p == 0) {
                    Messages.warning(s + " has 0 probability");
                    return Double.NEGATIVE_INFINITY;
                } else {
                    res += Math.log(p);
                }
            }
        }
        return res;
    }
public double logWordProb ( String word ) { double res = 0 ; if ( word . length ( ) < 1 ) { throw new IllegalArgumentException ( "Cannot compute probability of empty word" ) ; } else { String input = BOS + word + EOS ; for ( int high = 2 ; high <= input . length ( ) ; ++ high ) { int low = Math . max ( 0 , high - order ) ; String s = input . substring ( low , high ) ; double p = smoothProb ( s ) ; if ( p == 0 ) { Messages . warning ( s + " has 0 probability" ) ; return Double . NEGATIVE_INFINITY ; } else { res += Math . log ( p ) ; } } } return res ; }
Compute probability of a word or text
 @param word a non-empty a sequence of characters
 @return the log-probability (base e) of this string
Compute probability of a word or text @param word a non - empty a sequence of characters @return the log - probability ( base e ) of this string