コード例 #1
0
ファイル: NGrams.java プロジェクト: amuraru/streams
  @Override
  public Data process(Data data) {

    if (key != null && n != null && n >= 0) {

      Map<String, Double> counts = new LinkedHashMap<String, Double>();

      Serializable val = data.get(key);
      if (val != null) {

        String str = val.toString();
        for (int i = 0; i < str.length() - n; i++) {
          String ngram = str.substring(i, i + n);

          Double freq = counts.get(ngram);
          if (freq != null) {
            freq = freq + 1.0d;
          } else {
            freq = 1.0d;
          }
          counts.put(ngram, freq);
        }

        for (String key : counts.keySet()) {
          data.put(key, counts.get(key));
        }

        log.debug("Added {} {}-grams to item", counts.size(), n);
      }
    }

    return data;
  }
コード例 #2
0
  public static void main(String[] args) throws Exception {

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("startId", new Long(100L));
    params.put("key", "x");
    HideFeature proc = new HideFeature();

    ParameterInjection.inject(proc, params);

    Data datum = new DataImpl();
    datum.put("x", 1.0d);
    datum.put("y", 2.10d);

    log.debug("Initial datum: {}", datum);
    datum = proc.process(datum);
    log.debug("Processed datum: {}", datum);

    Map<String, ParameterType> types = discoverParameterTypes(stream.data.mapper.MapKeys.class);
    for (String key : types.keySet()) {
      log.info("Found '{}' = {}", key, types.get(key));
    }

    log.info("------------------------------------------------------------------");

    types = discoverParameterTypes(stream.data.mapper.CreateID.class);
    for (String key : types.keySet()) {
      log.info("Found '{}' = {}", key, types.get(key));
    }

    log.info("------------------------------------------------------------------");

    types = discoverParameterTypes(stream.data.mapper.MapValueToID.class);
    for (String key : types.keySet()) {
      log.info("Found '{}' = {}", key, types.get(key));
    }
  }