<commit_before>package org.ms2ms.graph;

import com.hfg.xml.XMLNode;
import org.ms2ms.utils.IOs;
import org.ms2ms.utils.Strs;
import org.ms2ms.utils.Tools;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * ** Copyright 2014-2015 ms2ms.org
 * <p/>
 * Description:
 * <p/>
 * Author: wyu
 * Date:   12/9/14
 */
public class Property  implements Cloneable
{
  private boolean mIsValid = true;
  private SortedMap<String, String> mProperties;

  public Property() { super(); }
  public Property(Map<String, String> props) { super(); setProperties(props); }

  public boolean hasProperty(String s) { return getProperties()!=null && getProperties().containsKey(s); }

  public SortedMap<String, String> getProperties()         { return mProperties; }
  public String              getProperty(String key) { return mProperties != null ? mProperties.get(key) : null; }
  public Integer             getProperty(String key, Integer _default)
  {
    try { return Integer.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Long                getProperty(String key, Long _default)
  {
    try { return Long.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Float               getProperty(String key, Float _default)
  {
    try { return Float.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Double              getProperty(String key, Double _default)
  {
    String str = getProperty(key);
    if (Strs.isSet(str) && str.indexOf(",") >= 0)
      str = str.replaceAll(",", "");

    Double val  = (str!=null?Double.valueOf(str):null);
    return val != null ? val : _default;
  }
  public Double[]            getProperty(String key, Double _default, String delimiter)
  {
    if (getProperty(key) == null) return null;

    String[] strs = getProperty(key).split(delimiter);
    Double[] vals = new Double[strs.length];

    for (int i = 0; i < strs.length; i++)
    {
      if (Strs.isSet(strs[i]) && strs[i].indexOf(",") >= 0)
        strs[i] = strs[i].replaceAll(",", "");

      Double v = Double.valueOf(strs[i]);
      vals[i] = (v != null ? v : _default);
    }
    return vals;
  }<commit_msg>Self clustering<commit_after>package org.ms2ms.graph;

import com.google.common.collect.Range;
import com.hfg.xml.XMLNode;
import org.ms2ms.utils.IOs;
import org.ms2ms.utils.Strs;
import org.ms2ms.utils.Tools;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * ** Copyright 2014-2015 ms2ms.org
 * <p/>
 * Description:
 * <p/>
 * Author: wyu
 * Date:   12/9/14
 */
public class Property  implements Cloneable
{
  private boolean mIsValid = true;
  private SortedMap<String, String> mProperties;

  public Property() { super(); }
  public Property(Map<String, String> props) { super(); setProperties(props); }

  public boolean hasProperty(String s) { return getProperties()!=null && getProperties().containsKey(s); }

  public SortedMap<String, String> getProperties()         { return mProperties; }
  public String              getProperty(String key) { return mProperties != null ? mProperties.get(key) : null; }
  public Integer             getProperty(String key, Integer _default)
  {
    try { return Integer.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Long                getProperty(String key, Long _default)
  {
    try { return Long.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Float               getProperty(String key, Float _default)
  {
    try { return Float.valueOf(getProperty(key)); } catch (Exception e) { return _default; }
  }
  public Double              getProperty(String key, Double _default)
  {
    String str = getProperty(key);
    if (Strs.isSet(str) && str.indexOf(",") >= 0)
      str = str.replaceAll(",", "");

    Double val  = (str!=null?Double.valueOf(str):null);
    return val != null ? val : _default;
  }
  public Double[] getProperty(String key, Double _default, String delimiter)
  {
    if (getProperty(key) == null) return null;

    String[] strs = getProperty(key).split(delimiter);
    Double[] vals = new Double[strs.length];

    for (int i = 0; i < strs.length; i++)
    {
      if (Strs.isSet(strs[i]) && strs[i].indexOf(",") >= 0)
        strs[i] = strs[i].replaceAll(",", "");

      Double v = Double.valueOf(strs[i]);
      vals[i] = (v != null ? v : _default);
    }
    return vals;
  }
  public Range<Double> getProperty(String key, String delimiter)
  {
    try
    {
      String[] strs = getProperty(key).split(delimiter);
      if (strs.length>=1 && strs[0].equals("")) return Range.atMost( Double.valueOf(strs[1]));
      if (strs.length>=1 && strs[1].equals("")) return Range.atLeast(Double.valueOf(strs[1]));

      return Range.closed(Double.valueOf(strs[0]), Double.valueOf(strs[1]));
    }
    catch (Exception e) {}

    return null;
  }
{'fraction_non_alphanumeric': 0.14518603759110088, 'fraction_numerical': 0.009589566551591868, 'mean_word_length': 3.3386023294509153, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5266236', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1669, 'n_words': 408}