package org.diagbot.common.push.filter.pretreat;

import org.diagbot.common.push.filter.PreResult;
import org.diagbot.nlp.participle.word.Lexeme;
import org.diagbot.nlp.participle.word.LexemePath;
import org.diagbot.nlp.util.NegativeEnum;
import org.diagbot.nlp.util.NlpUtil;
import org.springframework.util.StringUtils;

import java.util.List;

public class PretreatmentLis extends Pretreatment {
    public List<PreResult> analyze(String content) throws java.io.IOException{
        return super.analyzeDefault(content);
    }

    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
        PreResult result = new PreResult();
        double value = findNumberValue(lexemes, lexeme, index);
        if (value == -1) return null;
        //继续往前找化验明细项
        if (cursor > 0) cursor--;
        Lexeme leftLexeme = lexemes.get(cursor);
        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_NAME})) {
            result.setDetailName(leftLexeme.getText());
        } else {
            return null;
        }
        //查找化验套餐
        int position = cursor - 1;
        while (position > -1) {
            leftLexeme = lexemes.get(position);
            if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_TYPE})) {
                result.setName(leftLexeme.getText());
                break;
            }
            position--;
        }
        return result;
    }
}
