@Override
    protected double scoreImpl(List<Word> words1, List<Word> words2) {
        //计算词列表1总的字符数
        AtomicInteger words1Length = new AtomicInteger();
        words1.parallelStream().forEach(word -> words1Length.addAndGet(word.getText().length()));
        //计算词列表2总的字符数
        AtomicInteger words2Length = new AtomicInteger();
        words2.parallelStream().forEach(word -> words2Length.addAndGet(word.getText().length()));
        //计算词列表1和词列表2共有的词的总的字符数
        words1.retainAll(words2);
        AtomicInteger intersectionLength = new AtomicInteger();
        words1.parallelStream().forEach(word -> {
            intersectionLength.addAndGet(word.getText().length());
        });
        double score = intersectionLength.get()/(double)Math.max(words1Length.get(), words2Length.get());
        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("词列表1总的字符数：" + words1Length.get());
            LOGGER.debug("词列表2总的字符数：" + words2Length.get());
            LOGGER.debug("词列表1和2共有的词的总的字符数：" + intersectionLength.get());
            LOGGER.debug("相似度分值=" + intersectionLength.get() + "/(double)Math.max(" + words1Length.get() + ", " + words1Length.get() + ")=" + score);
        }
        return score;
    }
@ Override protected double scoreImpl ( List < Word > words1 , List < Word > words2 ) { AtomicInteger words1Length = new AtomicInteger ( ) ; words1 . parallelStream ( ) . forEach ( word -> words1Length . addAndGet ( word . getText ( ) . length ( ) ) ) ; AtomicInteger words2Length = new AtomicInteger ( ) ; words2 . parallelStream ( ) . forEach ( word -> words2Length . addAndGet ( word . getText ( ) . length ( ) ) ) ; words1 . retainAll ( words2 ) ; AtomicInteger intersectionLength = new AtomicInteger ( ) ; words1 . parallelStream ( ) . forEach ( word -> { intersectionLength . addAndGet ( word . getText ( ) . length ( ) ) ; } ) ; double score = intersectionLength . get ( ) / ( double ) Math . max ( words1Length . get ( ) , words2Length . get ( ) ) ; if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "词列表1总的字符数：" + words1Length . get ( ) ) ; LOGGER . debug ( "词列表2总的字符数：" + words2Length . get ( ) ) ; LOGGER . debug ( "词列表1和2共有的词的总的字符数：" + intersectionLength . get ( ) ) ; LOGGER . debug ( "相似度分值=" + intersectionLength . get ( ) + "/(double)Math.max(" + words1Length . get ( ) + ", " + words1Length . get ( ) + ")=" + score ) ; } return score ; }
计算相似度分值
@param words1 词列表1
@param words2 词列表2
@return 相似度分值