All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.vickumar1981.stringdistance.impl.OverlapImpl.scala Maven / Gradle / Ivy

The newest version!
package com.github.vickumar1981.stringdistance.impl

import com.github.vickumar1981.stringdistance.interfaces.NGramTokenizer

private[stringdistance] trait OverlapImpl extends NGramTokenizer {
  protected def overlap[T](s1: Array[T], s2: Array[T], n: Int = 1): Double = {
    require(n > 0, "Overlap score, ngram size must be a positive number.")
    foldNGram(s1, s2, n)(0d)(_ => 1d) { (s1Tok, s2Tok, dist) =>
      dist.toDouble / math.min(s1Tok.length, s2Tok.length)
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy