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 PretreatmentSymptom extends Pretreatment {
    protected NegativeEnum[] nees_symptom = new NegativeEnum[]{NegativeEnum.SYMPTOM};

    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);
            PreResult result = new PreResult();
            result.setUniqueName("症状--");
            result.setDetailName("症状--");
            if (NlpUtil.isFeature(l.getProperty(), nees_symptom)) {
                result.setValue(NlpUtil.concept(l, NegativeEnum.SYMPTOM));
                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--;
        Lexeme leftLexeme = lexemes.get(cursor);
        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.SYMPTOM})) {
            return NlpUtil.concept(leftLexeme, NegativeEnum.SYMPTOM);
        }
        return null;
    }
}
