package org.diagbot;

import org.diagbot.bigdata.work.BigDataParamsProxy;
import org.diagbot.common.push.bean.SearchData;
import org.diagbot.common.push.cache.ApplicationCacheUtil;
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;

/**
 * @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("血压14/43mmhg,收缩压140mmhg,血压149/43mmhg");
        searchData.setSymptom("病程6月");
        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,"symptom");
        long endTime = System.currentTimeMillis();
        long splitSeconds = endTime - splitStartTime;
        long seconds = endTime - startTime;
        System.out.println("添加标准词使用了:"+splitSeconds + "毫秒.");
        System.out.println("处理文本总共使用了:"+seconds + "毫秒.");*/
//        for (int j = 1; j < 11; j++) {
//
//
//            SearchData searchData = new SearchData();
//            BigDataParamsProxy paramsDataProxy = new BigDataParamsProxy();
//            searchData.setSymptom("安静时心率98次/分");
//            searchData.setOther("心率156次/分");
//            searchData.setVital("男性43岁");
//            searchData.setLis("Hachinski缺血积分2分");
//            searchData.setPacs("病程9个月");
//            searchData.setDiag("BMI12");
//            String[] items = { searchData.getSymptom(), searchData.getOther(), searchData.getVital()
//                    , searchData.getLis(), searchData.getPacs(), searchData.getDiag() };
//            String[] itemsType = { "symptom", "other", "vital", "lis", "pacs", "diag" };
//            long startTime = System.currentTimeMillis();
//            for (int i = 0; i < items.length; i++) {
//                if (items[i] != null) {
//                    LexemePath<Lexeme> featureData = ParticipleUtil.participle(items[i]);
//                    if (featureData != null) {
//                        paramsDataProxy.addStandWord(featureData, ApplicationCacheUtil.getKl_result_mapping_standword_map(), searchData, itemsType[i]);
//                    }
//                }
//            }
//            System.out.println(searchData.getSymptom());
//            System.out.println(searchData.getOther());
//            System.out.println(searchData.getVital());
//            System.out.println(searchData.getLis());
//            System.out.println(searchData.getPacs());
//            System.out.println(searchData.getDiag());
//            long endTime = System.currentTimeMillis();
//            System.out.println("处理文本总共使用了:" + (endTime - startTime) + "毫秒.");
//            System.out.println("---------------------------第" + j + "次处理---------------------------------");
//        }
        //        String s = "\tsafGG\tAFASSADG";
        //        System.out.println(s);
        //        System.out.println(s.trim());

    }

    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) + "秒.");
    }
}
