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

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

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

    public static void main(String[] args) throws Exception {

        Word2Vec 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[] s = new String[]{
                "🔴终于找到了这首歌，献给你！",
                "各位退休的同学，请听！",
                "这首歌太好听了，听醉了别怪我！",
                "老了真的很难！",
                "老同学在聚会上的演讲幽默是太实在了💢",
                "🔥🔥🔥一篇关于养老金问题的文章，请过来看看",
                "🔴老人考级的标准出台！符合6个条件的了不得🔥",
                "超级贵的景色，看过的彻底傻眼了📣",
                "她走了！泪目！留下了这段话，让人潸然泪下！",
                "🔴老同学❗️好久不见了，大家来看看吧！",
                "⭕谁写的？把人《一辈子》写明白了，给老友看看吧 ~!",
                "太美了，难得一见的美景～"
        };


//分词，获取词语列表
        List<String>[] words = new ArrayList[s.length];
        for (int i = 0; i < s.length; i++) {
            words[i] = Segment.getWords(s[i]);
        }

//快速句子相似度
        System.out.println("快速句子相似度:");
        for (int i = 0; i < words.length - 1; i++) {
            for (int j = i + 1; j < words.length; j++) {
                System.out.println(s[i] + "|||" + s[j] + ": " + vec.fastSentenceSimilarity(words[i], words[j]));
            }
        }


//句子相似度(所有词语权值设为1)
        System.out.println("句子相似度:");
        for (int i = 0; i < s.length - 1; i++) {
            for (int j = i + 1; j < s.length; j++) {
                System.out.println(s[i] + "|||" + s[j] + ": " + vec.sentenceSimilarity(words[i], words[j]));
            }
        }

//句子相似度(名词、动词权值设为1，其他设为0.8)
//        float[] weightArray1 = Segment.getPOSWeightArray(Segment.getPOS(s1));
//        float[] weightArray2 = Segment.getPOSWeightArray(Segment.getPOS(s2));
//        float[] weightArray3 = Segment.getPOSWeightArray(Segment.getPOS(s3));
//        System.out.println("s1|s2: " + vec.sentenceSimilarity(wordList1, wordList2, weightArray1, weightArray2));
//        System.out.println("s1|s3: " + vec.sentenceSimilarity(wordList1, wordList3, weightArray1, weightArray3));
//        System.out.println("s2|s3: " + vec.sentenceSimilarity(wordList2, wordList3, weightArray2, weightArray3));
    }

}