package com.microservices.dms.utils;

import org.xm.Similarity;
import org.xm.similarity.text.CosineSimilarity;
import org.xm.similarity.text.TextSimilarity;

import java.util.Map;

/**
 * <a href='https://github.com/shibing624/similarity'>类库地址</a>
 */
public class SimilarityService {

//    public static double similarity(String s1, String s2) {
//        if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
//            return 0;
//        }
//
//    }

    public static double sentence(String s1, String s2) {
        if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
            return 0;
        }
        return Similarity.morphoSimilarity(s1, s2);
    }

    public static double text(String text1, String text2) {
        if (text1 == null || text2 == null || text1.isEmpty() || text2.isEmpty()) {
            return 0;
        }
        TextSimilarity cosSimilarity = new CosineSimilarity();
        return cosSimilarity.getSimilarity(text1, text2);
    }

    public static void buildUserFractionMap(Map<Long, Double> map, Long assId, Double fraction) {
        map.merge(assId, fraction, Double::sum);
    }
}
