package org.diagbot;

import org.diagbot.bigdata.common.ApplicationCacheUtil;
import org.diagbot.bigdata.work.ParamsDataProxy;
import org.diagbot.common.work.SearchData;
import org.diagbot.nlp.participle.ParticipleUtil;
import org.diagbot.nlp.participle.cfg.Configuration;
import org.diagbot.nlp.participle.cfg.DefaultConfig;
import org.diagbot.nlp.participle.word.Lexeme;
import org.diagbot.nlp.participle.word.LexemePath;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description:
 * @Author: HUJING
 * @Date: 2019/7/2 10:31
 */
public class AddStandWordTest {
    public static void main(String[] args) throws Exception {
        //        Map<String, List<Map<String, String>>> kl_result_mapping_standword_map = ApplicationCacheUtil.getKl_result_mapping_standword_map();
        //        Set<Map.Entry<String, List<Map<String, String>>>> entries = kl_result_mapping_standword_map.entrySet();
        //        for (Map.Entry<String, List<Map<String, String>>> entry:entries) {
        //            System.out.println(entry.getKey() + "\t"+ entry.getValue());
        //        }
//        getStandWordFeatureType();
//        ApplicationCacheUtil.getKl_result_mapping_standword_map();
        long startTime = System.currentTimeMillis();
        ApplicationCacheUtil.getKl_result_mapping_standword_map();
        long endCacheTime = System.currentTimeMillis();
        long cacheTime = endCacheTime - startTime;
        System.out.println("处理标准词最终用了:" + cacheTime + "毫秒.");
        SearchData searchData = new SearchData();
        searchData.setSymptom("关节僵硬3min");
        long splitStartTime = System.currentTimeMillis();
        LexemePath<Lexeme> data = ParticipleUtil.participle(searchData.getSymptom());
        ParamsDataProxy paramsDataProxy = new ParamsDataProxy();
        paramsDataProxy.addStandWord(data, ApplicationCacheUtil.kl_result_mapping_standword_map, searchData);
        long endTime = System.currentTimeMillis();
        long splitSeconds = endTime - splitStartTime;
        long seconds = endTime - startTime;
        System.out.println("添加标准词使用了:"+splitSeconds + "毫秒.");
        System.out.println("处理文本总共使用了:"+seconds + "毫秒.");
        AddStandWordTest addStandWordTest = new AddStandWordTest();
    }

    public static void getStandWordFeatureType() throws IOException {
        Configuration configuration = new DefaultConfig();
        List<String> fileContents = configuration.readFileContents("kl_result_mapping_standword.dict");
        String operationGreater = ">=|≥|>|大于|＞|超过";
        String operationSmaller = "<=|≤|<|小于|＜|少于";
        long startTime = System.currentTimeMillis();
        for (String fileContent : fileContents) {
            LexemePath<Lexeme> lexemes = null;
            String op = "";
            String[] fileContentSplit = null;
            if (fileContent.contains(">=") || fileContent.contains("≥")
                    || fileContent.contains(">") || fileContent.contains("大于")
                    || fileContent.contains("＞") || fileContent.contains("超过")) {
                op = ">";
                fileContentSplit = fileContent.split(operationGreater);
            } else if (fileContent.contains("<=") || fileContent.contains("≤")
                    || fileContent.contains("<") || fileContent.contains("小于")
                    || fileContent.contains("＜") || fileContent.contains("少于")) {
                op = "<";
                fileContentSplit = fileContent.split(operationSmaller);
            } else {
                continue;
            }
            for (String fileContentWords : fileContentSplit) {
                LexemePath<Lexeme> lexemeWord = ParticipleUtil.participle(fileContentWords);
                if (null == lexemes) {
                    lexemes = lexemeWord;
                } else {
                    for (Lexeme lexeme : lexemeWord) {
                        lexemes.add(lexeme);
                    }
                }
            }
            int i = 1;
            for (Lexeme lexeme:lexemes) {
                if (lexeme.getProperty().contains(",")) {
                    ApplicationCacheUtil.setProterty(lexeme);
                }
                if (lexemes.size() != i) {
                    System.out.print(lexeme.getText() + "(" + lexeme.getProperty() + ")|");
                } else {
                    System.out.println(lexeme.getText() + "(" + lexeme.getProperty() + ")");
                }
                i++;
            }
        }
        long endTime = System.currentTimeMillis();
        float seconds = (endTime - startTime) / 1000F;
        System.out.println(Float.toString(seconds) + "秒.");
    }
}
