package com.lantone.qc.kernel;

import com.google.common.collect.Lists;
import com.lantone.qc.kernel.structure.ai.model.EntityBlock;
import com.lantone.qc.kernel.structure.ai.model.Lemma;
import com.lantone.qc.kernel.structure.ai.model.ConflictFinder;
import com.lantone.qc.kernel.structure.ai.model.Relation;
import com.lantone.qc.kernel.util.CatalogueUtil;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Description:
 * @Author: HUJING
 * @Date: 2020/8/1 13:32
 */


public class KnowledgeTest {

    public static Lemma lemmaSetting(Integer start, Integer end, Integer id, String name, String value) {
        Lemma lemma_1 = new Lemma();
        lemma_1.setFrom(start);
        lemma_1.setTo(end);
        lemma_1.setProperty(name);
        lemma_1.setText(value);
        lemma_1.setId(id);
        return lemma_1;
    }

    public static Relation relationSetting(Integer fromId, Integer toId, String relationName){
        Relation relation = new Relation();
        relation.setFrom(fromId);
        relation.setTo(toId);
        relation.setRelationName(relationName);
        return relation;
    }

    public static void main(String[] args) {

        //        Set<Integer[]> xx = new HashSet<>();
        //        xx.add(new Integer[]{11, 22});
        //        xx.add(new Integer[]{11, 22});
        //        System.out.println(xx.size());

        //
        ConflictFinder finder = new ConflictFinder();

        Lemma lemma_1 = lemmaSetting(11, 20, 1, "指标值", "20次/分钟;体温");
        Lemma lemma_23 = lemmaSetting(129, 130, 23, "身体部位", "腹");
        Lemma lemma_24 = lemmaSetting(130, 131, 24, "临床表现", "软");
        Lemma lemma_25 = lemmaSetting(132, 133, 25, "否定", "无");

        Lemma lemma_30 = lemmaSetting(100, 103, 30, "修饰", "边界清");
        Lemma lemma_31 = lemmaSetting(100, 103, 31, "修饰", "边界不清");
        Lemma lemma_26 = lemmaSetting(100, 103, 26, "临床表现", "压痛");
        Lemma lemma_40 = lemmaSetting(100, 103, 40, "一般情况", "胃纳");
        Lemma lemma_41 = lemmaSetting(100, 103, 41, "一般情况描述", "差");

        Lemma lemma_50 = lemmaSetting(100, 103, 50, "临床表现", "胃纳可");

        Relation relation23_26 = relationSetting(23, 26, "身体部位-临床表现");
        Relation relation25_26 = relationSetting(25, 26, "否定-临床表现");
        Relation relation40_41 = relationSetting(40, 41, "一般情况-一般情况描述");


        // 放入专科检查中的实体列表
        List<Lemma> checkLemmas = Lists.newArrayList(lemma_1, lemma_23, lemma_24, lemma_25, lemma_30, lemma_26,
                lemma_40, lemma_41);

        // 放入现病史中的实体列表
        List<Lemma> presentLemmas = Lists.newArrayList(lemma_1, lemma_23, lemma_24, lemma_25,
                lemma_31, lemma_26, lemma_50);

        // 放入专科检查中的关系列表
        List<Relation> checkRelations = Lists.newArrayList(relation23_26, relation25_26, relation40_41);
        // 放入现病史中的关系列表
        List<Relation> presentRelations = Lists.newArrayList(relation23_26);

        Object[] checkPairs;
        Object[] presentPairs;
        checkPairs = new Object[] {checkLemmas, checkRelations};
        presentPairs = new Object[] {presentLemmas, presentRelations};

        List<Object[]> positionPairs = finder.findConflictPositions(checkPairs, presentPairs);
        if (positionPairs.size() > 0) {
            String info = "";
            for (int i = 0; i < positionPairs.size(); i++) {
                if (i % 2 != 0){
                    String infoStr = "";
                    Object[] entityBlocks = positionPairs.get(i);
                    for (Object o:entityBlocks) {
                        EntityBlock entityBlock = (EntityBlock) o;
                        infoStr += entityBlock.getSearchWord() + "->";
                    }
                    info = CatalogueUtil.concatInfo(info, infoStr.substring(0, infoStr.length() - 2));
                }
            }
            System.out.println(info);
        }
        System.out.println("有冲突的位置组数目:" + positionPairs.size()/2);

    }
}
