0
Scalaにdifflib.SequenceMatcher
を実装するものはありますか?私の生産コードの一部をPythonからScalaに変換する必要がありますが、SequenceMatcherの以前の出力を変更するものは使用したくありません。Scala用のPythonのdifflib.SequenceMatcherに相当するものがあります
どのような提案も大変ありがとうございます。
Scalaにdifflib.SequenceMatcher
を実装するものはありますか?私の生産コードの一部をPythonからScalaに変換する必要がありますが、SequenceMatcherの以前の出力を変更するものは使用したくありません。Scala用のPythonのdifflib.SequenceMatcherに相当するものがあります
どのような提案も大変ありがとうございます。
検索の結果、何も見つからなかったので、SequenceMatcherを調べて書きました。実際にはScalaでは非常にシンプルです。気軽にこれを使用するか、改善してください。
/**
* Class SequenceMatcher - A simplified implimetation of Python's SequenceMatcher
* Currently only supports strings and ratio()
* @version 0.1
* @param stringA - first string
* @param stringB - second string
*/
class SequenceMatcher(stringA: String, stringB: String) {
/**
* ratio()
* @return Return a measure of the sequences’ similarity as a float in the range [0, 1]
*/
def ratio(): Double = {
(2.0 * numOfMatches())/(stringA.length() + stringB.length())
}
/**
* numOfMatches()
* @return number of characters that match in the two strings
*/
def numOfMatches(): Long = {
stringA.intersect(stringB).length()
}
}