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

import org.ansj.domain.Term;
import org.ansj.recognition.impl.StopRecognition;
import org.ansj.splitWord.analysis.ToAnalysis;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author dyp
 */


public class Segment {
    public Segment() {
    }

    public static List<Term> Seg(String sentence) {
        StopRecognition filter = new StopRecognition();
        filter.insertStopWords(new String[]{",", " ", ".", "，", "。", ":", "：", "'", "‘", "’", "　", "“", "”", "《", "》", "[",
                "]", "-"});
        return ToAnalysis.parse(sentence).recognition(filter).getTerms();
    }

    public static List<String> getWords(String sentence) {
        List<Term> termList = Seg(sentence);
        List<String> wordList = new ArrayList();
        Iterator var4 = termList.iterator();

        while (var4.hasNext()) {
            Term wordTerm = (Term) var4.next();
            wordList.add(wordTerm.getName());
        }

        return wordList;
    }

    public static List<String> getPOS(String sentence) {
        List<Term> termList = Seg(sentence);
        List<String> natureList = new ArrayList();
        Iterator var4 = termList.iterator();

        while (var4.hasNext()) {
            Term wordTerm = (Term) var4.next();
            natureList.add(wordTerm.getNatureStr());
        }

        return natureList;
    }

    public static float[] getPOSWeightArray(List<String> posList) {
        float[] weightVector = new float[posList.size()];

        for (int i = 0; i < weightVector.length; ++i) {
            String POS = (String) posList.get(i);
            switch (POS.charAt(0)) {
                case 'n':
                case 'v':
                    weightVector[i] = 1.0F;
                    break;
                default:
                    weightVector[i] = 0.8F;
            }
        }

        return weightVector;
    }
}
