package yi.iu.ft.local;

import yi.stat.hist.Quantizer;

public class QuantizeTemplate {

  /**
   * attribute number
   */
  int m_attributeNum;

  /**
   * quantized bin number for each attribute
   */
  int[] m_quantizedBinNums;

  /**
   * bin name prefix for each attribute
   */
  String[] m_binNamePrefixs;

  /**
   * quantizer short name (eg. line)
   */
  String m_quantizerShortName;

  /**
   * quantizer id name (eg. quan1)
   */
  String m_quantizerIdName;

  public QuantizeTemplate(int attribute_num, int[] quantized_bin_nums,
    String[] bin_name_prefixs, String quantizer_short_name, String
    quantizer_id_name) {
      m_attributeNum = attribute_num;
      m_quantizedBinNums = quantized_bin_nums;
      m_binNamePrefixs = bin_name_prefixs;
      m_quantizerShortName = quantizer_short_name;
      m_quantizerIdName = quantizer_id_name;
  }

  public QuantizeTemplate(int[] quantized_bin_nums,
    String[] bin_name_prefixs, String quantizer_short_name, String
    quantizer_id_name) {
      this(bin_name_prefixs.length, quantized_bin_nums, bin_name_prefixs, quantizer_short_name, quantizer_id_name);
  }

  /**
   * Attribute number
   * @return
   */
  public int getAttributeNum() {
    return m_attributeNum;
  }

  /**
   * Return the bin number of each attribute after quantization
   * @return
   */
  public int getQuantizedBinNum(int attr_index) {
    return m_quantizedBinNums[attr_index];
  }

  /**
   * Return the total bin number of all attributes after quantization
   * @return
   */
  public int getQuantizedBinNum() {
    return (int)yi.stat.StatUtil.sum(m_quantizedBinNums);
  }

  /**
   * Return the bin numbers of all attributes after quantization
   * @return
   */
  public int[] getQuantizedBinNums() {
    return m_quantizedBinNums;
  }

  /**
   * Return the bin name of each attribute after quantization
   * @return
   */
  public String[] getQuantizedBinName(int attr_index) {
    int num = getQuantizedBinNum(attr_index);
    String[] names = new String[num];
    String prefix = m_binNamePrefixs[attr_index];
    for (int i=0; i<num; i++) names[i] = prefix + '_' + i;
    return names;
  }

  /**
   * Return the bin name of all attributes after quantization
   * @return
   */
  public String[] getQuantizedBinName() {
    String[] names = new String[getQuantizedBinNum()];
    int attr_num = getAttributeNum();
    int count = 0;
    for (int i=0; i<attr_num; i++) {
      String[] attr_names = getQuantizedBinName(i);
      for (int j=0; j<attr_names.length; j++) names[count++] = attr_names[j];
    }
    return names;
  }

  /**
   * Return the quantizer short name
   * @return
   */
  public String getQuantizerShortName() {
    return m_quantizerShortName;
  }

  /**
   * Return the quantizer ID name
   * @return
   */
  public String getQuantizerIdName() {
    return m_quantizerIdName;
  }
}