text - Is there an equivalent of Python's difflib.SequenceMatcher for Scala -
is there implements difflib.sequencematcher
in scala? need convert of production code python scala not want use change previous output sequencematcher.
any suggestions appreciated.
after searching couldn't find researched sequencematcher , wrote up. it's quite simple in scala. please feel free use or improve on it.
/** * class sequencematcher - simplified implimetation of python's sequencematcher * supports strings , ratio() * @version 0.1 * @param stringa - first string * @param stringb - second string */ class sequencematcher(stringa: string, stringb: string) { /** * ratio() * @return return measure of sequences’ similarity float in range [0, 1] */ def ratio(): double = { (2.0 * numofmatches()) / (stringa.length() + stringb.length()) } /** * numofmatches() * @return number of characters match in 2 strings */ def numofmatches(): long = { stringa.intersect(stringb).length() } }
Comments
Post a Comment