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();

            String path = "word2vec.bin"; // 改成本地路径
            vec.loadGoogleModel(path);


//            System.out.println("loadGoogleModelFromOss cost = " + (end - start));

        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] s1 = new String[]{
            "中医", "书法", "食疗", "固气", "唱歌", "太极",
                "瑜伽", "短剧", "营养健康", "国画"
        };
        String[] s2 = new String[]{
//                "人生忠告",
//                "知识科普",
//                "祝福音乐",
//                "搞笑段子",
//                "怀念时光",
//                "生活小妙招",
//                "中国历史影像",
//                "国家力量",
//                "早中晚好",
//                "美食教程",
//                "风景实拍",
//                "民生政策",
//                "节日祝福",
//                "亲情音乐",
//                "动物萌宠",
//                "旅行攻略",
//                "中国战争史",

                "情感","音乐","搞笑","历史","生活记录","文化","旅行","美食","医疗健康","三农","科普","时政","教育","舞蹈","科技","艺术","军事","动物","财经","奇人异象","公益","随拍","母婴","综艺","法律","名人","时尚","生活家居","体育","宗教","汽车","剧情","摄影摄像","职场","地域本地","游戏","收藏品","二次元","电影","短剧","电视剧"
        };
//分词，获取词语列表
        for (String a : s1){
            List<String> worda = Segment.getWords(a);
            for (String b : s2){
                List<String> wordb = Segment.getWords(b);
                System.out.println(a + "\t" + b + "\t" + vec.sentenceSimilarity(worda, wordb));
            }
        }

//句子相似度(名词、动词权值设为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));
    }

}