Class Similarity

java.lang.Object
org.aoju.bus.core.text.Similarity

public class Similarity extends Object
文本相似度计算,局部敏感hash,用于海量文本去重 局部敏感hash定义:假定两个字符串具有一定的相似性, 在hash之后,仍然能保持这种相似性,就称之为局部敏感hash
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    最长公共子串,采用动态规划算法。 其不要求所求得的字符在所给的字符串中是连续的。 算法解析见:https://leetcode-cn.com/problems/longest-common-subsequence/solution/zui-chang-gong-gong-zi-xu-lie-by-leetcod-y7u0/
    static double
    similar(String texta, String textb)
    利用莱文斯坦距离(Levenshtein distance)算法计算相似度,两个都是空串相似度为1,被认为是相同的串 比较方法为: 只比较两个字符串字母、数字、汉字部分,其他符号去除 计算出两个字符串最大子串,除以最长的字符串,结果即为相似度
    static String
    similar(String texta, String textb, int scale)
    计算相似度百分比

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Similarity

      public Similarity()
  • Method Details

    • similar

      public static double similar(String texta, String textb)
      利用莱文斯坦距离(Levenshtein distance)算法计算相似度,两个都是空串相似度为1,被认为是相同的串 比较方法为:
      • 只比较两个字符串字母、数字、汉字部分,其他符号去除
      • 计算出两个字符串最大子串,除以最长的字符串,结果即为相似度
      Parameters:
      texta - 字符串1
      textb - 字符串2
      Returns:
      相似度
    • similar

      public static String similar(String texta, String textb, int scale)
      计算相似度百分比
      Parameters:
      texta - 字符串1
      textb - 字符串2
      scale - 保留小数
      Returns:
      百分比
    • longestCommonSubstring

      public static String longestCommonSubstring(String texta, String textb)
      最长公共子串,采用动态规划算法。 其不要求所求得的字符在所给的字符串中是连续的。 算法解析见:https://leetcode-cn.com/problems/longest-common-subsequence/solution/zui-chang-gong-gong-zi-xu-lie-by-leetcod-y7u0/
      Parameters:
      texta - 字符串1
      textb - 字符串2
      Returns:
      最长公共子串