package org.diagbot.nlp.rule.pretreat;

import org.diagbot.nlp.participle.ParticipleUtil;
import org.diagbot.nlp.participle.word.Lexeme;
import org.diagbot.nlp.participle.word.LexemePath;
import org.diagbot.nlp.rule.module.PreResult;
import org.diagbot.nlp.util.NegativeEnum;
import org.diagbot.nlp.util.NlpUtil;

import java.util.List;

public class PretreatmentVital extends Pretreatment {
    protected NegativeEnum[] nees_vital_result = new NegativeEnum[]{NegativeEnum.VITAL_RESULT};
    protected NegativeEnum[] nees_vital_index = new NegativeEnum[]{NegativeEnum.VITAL_INDEX};

    public List<PreResult> analyze(String content) throws java.io.IOException{
        List<PreResult> preResults = super.analyzeDefault(content);
        LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
        for (int i = 0; i < lexemes.size(); i++) {
            Lexeme l = lexemes.get(i);
            if (NlpUtil.isFeature(l.getProperty(), nees_vital_result)) {
                PreResult result = new PreResult();
                result.setUniqueName("体征结果--");
                result.setDetailName("体征结果--");
                result.setValue(NlpUtil.concept(l, NegativeEnum.VITAL_RESULT));
                preResults.add(result);
            }else if (NlpUtil.isFeature(l.getProperty(), nees_vital_index)) {
                PreResult result = new PreResult();
                result.setUniqueName("体征结果--");
                result.setDetailName("体征结果--");
                result.setValue(NlpUtil.concept(l, NegativeEnum.VITAL_INDEX));
                preResults.add(result);
            }
        }
        return preResults;
    }

    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
        return super.createDefaultPreResult(lexemes, lexeme, index);
    }


    public String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
        if (cursor > 0) cursor--;
        int search_len = 0;
        Lexeme leftLexeme = null;
        while (search_len < max_back_search && cursor > -1) {
            leftLexeme = lexemes.get(cursor);
            if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.VITAL_INDEX})) {
                return NlpUtil.concept(leftLexeme, NegativeEnum.VITAL_INDEX);
            }
            search_len++;
            cursor--;
        }
        return null;
    }
}
