package com.lantone.qc.kernel.structure.ai.process;

import com.alibaba.fastjson.JSONObject;
import com.lantone.qc.kernel.structure.ai.model.CrfOut;
import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
import com.lantone.qc.pub.model.entity.General;
import com.lantone.qc.pub.model.entity.GeneralDesc;
import com.lantone.qc.pub.model.entity.Negative;
import org.apache.commons.lang3.StringUtils;

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

public class EntityProcessGenerals extends EntityProcess{
    public List<GeneralDesc> extractEntity(JSONObject outputs) {
        List<GeneralDesc> generals = new ArrayList<>();
        GeneralDesc general;
        List<Map<String, String>> generalEntityList = processJson(outputs, EntityEnum.GENERAL.toString());
        for (Map<String, String> generalEntityMap : generalEntityList) {
            if (StringUtils.isEmpty(generalEntityMap.get(EntityEnum.GENERAL.toString()))) {
                continue;
            }
            general = new GeneralDesc();
            for (String key : generalEntityMap.keySet()) {
                String entity = StringUtils.isEmpty(generalEntityMap.get(key)) ? "" : generalEntityMap.get(key);
                switch (EntityEnum.parseOfValue(key)){
                    case GENERAL:
                        general.setName(entity);
                        break;
                    case NEGATIVE:
                        Negative negative = new Negative();
                        negative.setName(entity);
                        general.setNegative(negative);
                        break;
                }
            }
            generals.add(general);
        }
        return generals;
    }
}
