package com.lantone.structure.ai.process;

import com.alibaba.fastjson.JSONObject;
import com.lantone.structure.ai.model.EntityEnum;
import com.lantone.structure.ai.model.Lemma;
import com.lantone.structure.util.DiagEnhancer;
import com.lantone.structure.model.entity.Diag;
import com.lantone.structure.model.entity.PD;
import com.lantone.structure.model.entity.Possible;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

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

@Component
public class EntityProcessDiag extends EntityProcess {
    private Logger logger = LoggerFactory.getLogger(EntityProcessDiag.class);
    public List<Diag> extractEntity(JSONObject aiOut) {
        List<Diag> diags = new ArrayList<>();
        try {
            //读取疾病信息
            List<Lemma> diagLemmas = createEntityTree(aiOut, EntityEnum.DIEASE.toString());
            for (Lemma lemma : diagLemmas) {
                Diag diag = DiagEnhancer.create(lemma.getText());
                if (lemma.isHaveChildren()) {
                    diag.setNegative(findNegative(lemma));//阴性
                    diag.setPossible(findT(lemma, new Possible(), EntityEnum.POSSIBLE.toString()));//可能的
                    diag.setPd(findT(lemma, new PD(), EntityEnum.TIME.toString()));//时间
                }
                diags.add(diag);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return diags;
    }
}
