package com.tzld.piaoquan.recommend.similarity.word2vec;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dyp
 */
public class Demo2 {

    private static Word2Vec vec;

    public static void main(String[] args) {
        vec = new Word2Vec();
        try {
            String endpoint = "oss-cn-hangzhou.aliyuncs.com";
            String bucketName = "art-recommend";
            String path = "similarity/word2vec/Google_word2vec_zhwiki210720_300d.bin";
            String accessKeyId = "LTAIP6x1l3DXfSxm";
            String accessKetSecret = "KbTaM9ars4OX3PMS6Xm7rtxGr1FLon";

            long start = System.currentTimeMillis();
            vec.loadGoogleModelFromOss(endpoint, bucketName, path, accessKeyId, accessKetSecret);
            long end = System.currentTimeMillis();
            System.out.println("loadGoogleModelFromOss cost = " + (end - start));

        } catch (IOException e) {
            e.printStackTrace();
        }

        String[] tags = {
//                "风油精,妙用,学到,老歌,记住,教师节,建议,真情,人间,早安",
//                "风油精,妙用,建议,学到,伟人,致敬,铜像,听的歌,送给,心情",
//                "送给,学到,风油精,妙用,亲人,朋友,骗局,小心,注意,瓶子",
//                "听的歌,送给,心情,建议,真情,人间,预防,可惜,知道,伟人",
//                "风油精,妙用,建议,送给,学到,骗局,小心,注意,瓶子,作用",
//                "知道,血管,水果,推荐,预防,可惜,真情,人间,小常识,老百姓",
//                "按摩,心脏,老歌,记住,骗局,小心,注意,建议,教师节,风油精",
//                "注意,骗局,小心,按摩,心脏,老歌,记住,家人,朋友,建议",
//                "知道,小常识,老百姓,真情,人间,预防,可惜,血管,水果,推荐",
//                "教师节,知道,老歌,记住,风油精,妙用,按摩,心脏,早安,创意",
//                "教师节,知道,家人,朋友,妙用,好了吗,收下,骗局,小心,注意",
//                "听的歌,送给,心情,建议,真情,人间,预防,可惜,知道,伟人",
//                "送给,风油精,妙用,建议,亲人,骗局,小心,注意,瓶子,作用"
                "教师节,知道,家人,朋友,妙用,好了吗,收下,骗局,小心,注意"
        };
        //String tags = "按摩,心脏,老歌,记住,骗局,小心,注意,建议,教师节,风油精";
        //String tags = "风油精";
        String title = "\uD83D\uDD34少年夫妻老来伴，珍惜身边人";
        Segment.getWords("init");

        for (int j = 0; j < tags.length; j++) {
            long start = System.currentTimeMillis();
            Double[] score = funcC34567ForTags(tags[j], title);
            long end = System.currentTimeMillis();
            System.out.println(tags[j] + "||" + title + "||" + score[0] + "||" + score[1] + "||" + score[2] + "||" +
                    "cost : "+(end - start));

        }
    }

    public static Double[] funcC34567ForTags(String tags, String title) {
        String[] tagsList = tags.split(",");
        int d1 = 0;
        List<String> d2 = new ArrayList<>();
        double d3 = 0.0;
        double d4 = 0.0;

        List<String> titleWords = Segment.getWords(title);
        for (String tag : tagsList) {
            if (title.contains(tag)) {
                d1++;
                d2.add(tag);
            }
            List<String> tagWords = Segment.getWords(tag);
            double score = vec.fastSentenceSimilarity(tagWords, titleWords);
            if (score > d3) {
                d3 = score;
            }
            d4 += score;
        }

        d4 = (tagsList.length > 0) ? d4 / tagsList.length : d4;

        // 使用数组来返回多个值
        Double[] result = {(double) d1, d3, d4};
        return result;
    }
}