public float getSimilarity(LanguageProfilerBuilder another) throws TikaException {

        float sum = 0;

        try {
            Iterator<NGramEntry> i = another.getSorted().iterator();
            while (i.hasNext()) {
                NGramEntry other = i.next();
                if (ngrams.containsKey(other.seq)) {
                    sum += Math.abs((other.frequency - ngrams.get(other.seq).frequency)) / 2;
                } else {
                    sum += other.frequency;
                }
            }
            i = getSorted().iterator();
            while (i.hasNext()) {
                NGramEntry other = i.next();
                if (another.ngrams.containsKey(other.seq)) {
                    sum += Math.abs((other.frequency - another.ngrams.get(other.seq).frequency)) /
                            2;
                } else {
                    sum += other.frequency;
                }
            }
        } catch (Exception e) {
            throw new TikaException(
                    "Could not calculate a score how well NGramProfiles match each other");
        }
        return sum;
    }
Calculates a score how well NGramProfiles match each other

@param another ngram profile to compare against
@return similarity 0=exact match
@throws TikaException if could not calculate a score
tika-langdetect/tika-langdetect-tika/src/main/java/org/apache/tika/langdetect/tika/LanguageProfilerBuilder.java