src/main/java/eu/digitisation/langutils/TermFrequency.java
public double cosine(TermFrequency other) {
        double norm1 = 0;
        double norm2 = 0;
        double scalar = 0;

        for (Map.Entry<String, Integer> entry : this.entrySet()) {
            int freq = entry.getValue();
            norm1 += freq * freq;
            scalar += freq * other.get(entry.getKey());
        }

        for (int freq2 : other.values()) {
            norm2 += freq2 * freq2;
        }

        return scalar / Math.sqrt(norm1 * norm2);
    }
/**
     *
     * @param other another term frequency vector
     * @return the cosine distance (normalized scalar product)
     */
@param other another term frequency vector
@return the cosine distance (normalized scalar product)
@param other another term frequency vector @return the cosine distance ( normalized scalar product )
public double cosine(TermFrequency other) {
        double norm1 = 0;
        double norm2 = 0;
        double scalar = 0;
        for (Map.Entry<String, Integer> entry : this.entrySet()) {
            int freq = entry.getValue();
            norm1 += freq * freq;
            scalar += freq * other.get(entry.getKey());
        }
        for (int freq2 : other.values()) {
            norm2 += freq2 * freq2;
        }
        return scalar / Math.sqrt(norm1 * norm2);
    }
public double cosine ( TermFrequency other ) { double norm1 = 0 ; double norm2 = 0 ; double scalar = 0 ; for ( Map . Entry < String , Integer > entry : this . entrySet ( ) ) { int freq = entry . getValue ( ) ; norm1 += freq * freq ; scalar += freq * other . get ( entry . getKey ( ) ) ; } for ( int freq2 : other . values ( ) ) { norm2 += freq2 * freq2 ; } return scalar / Math . sqrt ( norm1 * norm2 ) ; }
@param other another term frequency vector
 @return the cosine distance (normalized scalar product)
@param other another term frequency vector @return the cosine distance ( normalized scalar product )