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.model.entity.*;
import com.lantone.structure.model.label.MaritalLabel;

import java.util.List;

/**
 * @ClassName : EntityProcessMarital
 * @Description : 婚育史
 * @Author : 楼辉荣
 * @Date: 2020-03-10 10:20
 */
public class EntityProcessMarital extends EntityProcess {
    public MaritalLabel extractEntity(JSONObject aiOut) {
        MaritalLabel maritalLabel = new MaritalLabel();
        //家属情况
        EntityProcessFamily entityProcessFamily = new EntityProcessFamily();
        maritalLabel.setFamily(entityProcessFamily.extractEntity(aiOut).getFamilies());
        //读取近亲史所有本体及关联信息
        List<Lemma> consanguineousLemmas = createEntityTree(aiOut, EntityEnum.NEAR_RELATION.toString());
        for (Lemma lemma :consanguineousLemmas) {
            Consanguineous consanguineous = new Consanguineous();
            consanguineous.setName(lemma.getText());
            if (lemma.isHaveChildren()) {
                consanguineous.setNegative(findNegative(lemma));
            }
            maritalLabel.setConsanguineous(consanguineous);
        }
        //读取结婚年龄所有本体及关联信息
        List<Lemma> marryiageLemmas = createEntityTree(aiOut, EntityEnum.MARRYIAGE.toString());
        for (Lemma lemma :marryiageLemmas) {
            Marryiage marryiage = new Marryiage();
            marryiage.setName(lemma.getText());
            maritalLabel.setMarryiage(marryiage);
        }
        //读取结婚年龄所有本体及关联信息
        List<Lemma> ageLemmas = createEntityTree(aiOut, EntityEnum.AGE.toString());
        for (Lemma lemma :ageLemmas) {
            Marryiage marryiage = new Marryiage();
            marryiage.setName(lemma.getText());
            maritalLabel.setMarryiage(marryiage);
        }
        //婚姻情况描述
        List<Lemma> maritalStatusLemmas = createEntityTree(aiOut, EntityEnum.MARITAL_STATUS.toString());
        for (Lemma lemma :maritalStatusLemmas) {
            MaritalStatus maritalStatus = new MaritalStatus();
            maritalStatus.setName(lemma.getText());
            maritalLabel.setMaritalStatus(maritalStatus);
        }
        //夫妻关系描述
        List<Lemma> conjugalRelationLemmas = createEntityTree(aiOut, EntityEnum.CONJUGAL_RELATION.toString());
        for (Lemma lemma :conjugalRelationLemmas) {
            ConjugalRelation conjugalRelation = new ConjugalRelation();
            conjugalRelation.setName(lemma.getText());
            maritalLabel.setConjugalRelation(conjugalRelation);
        }
        //生育情况描述
        List<Lemma> fertilityLemmas = createEntityTree(aiOut, EntityEnum.BIRTH_HIS.toString());
        for (Lemma lemma :fertilityLemmas) {
            Fertility fertility = new Fertility();
            fertility.setName(lemma.getText());
            maritalLabel.setFertility(fertility);
        }
        return maritalLabel;
    }
}