package org.diagbot.nlp.util;

import org.diagbot.nlp.participle.word.Lexeme;

import java.util.Arrays;

/**
 * @Auther: fyeman
 * @Date: 2018/12/24/024 16:04
 * @Description:
 */
public class NlpUtil {

    public static String[] extendsSymbol(String[] origin, String[] extend_symbols) {
        String[] symbols = new String[origin.length + extend_symbols.length];
        System.arraycopy(origin, 0, symbols, 0, origin.length);
        System.arraycopy(extend_symbols, 0, symbols, origin.length, extend_symbols.length);

        Arrays.sort(symbols);
        return symbols;
    }

    public static boolean isNumberString(Lexeme l) {
        if (l == null) return false;
        if (NlpUtil.isFeature(l.getProperty(), new NegativeEnum[]{NegativeEnum.EVENT_TIME_VALUE})) {
            return true;
        }
        for (char c : l.getText().toCharArray()) {
            if (c >= '0' && c <= '9') {
                return true;
            }
        }
        return false;
    }

    public static boolean isFeature(String property, NegativeEnum[] features) {
        if (property == null) {
            return false;
        }
        if (features == null || features.length == 0) {
            return true;
        }
        if (property.indexOf(",") > 0) {
            String[] properties = property.split(",");
            for (int i = 0; i < properties.length; i++) {
                for (NegativeEnum nenum : features) {
                    if (NegativeEnum.parseOfValue(properties[i]) == nenum) {
                        return true;
                    }
                }
            }
        } else {
            for (NegativeEnum nenum : features) {
                if (NegativeEnum.parseOfValue(property) == nenum) {
                    return true;
                }
            }
        }
        return false;
    }
}
