@@ -0,0 +1,3177 @@
+/*%0A * Copyright (c) 2015-2016 The University Of Sheffield.%0A *%0A * This file is part of gateplugin-LearningFramework %0A * (see https://github.com/GateNLP/gateplugin-LearningFramework).%0A *%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Lesser General Public License as published by%0A * the Free Software Foundation, either version 2.1 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public License%0A * along with this software. If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage gate.plugin.learningframework.stats;%0A%0Aimport gate.plugin.learningframework.LFUtils;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport org.apache.commons.math3.stat.descriptive.SummaryStatistics;%0A%0A/**%0A * A simple lightweight wrapper class for maintaining stats about many features.%0A * %0A * This gathers statistics about many features, mapping feature names to %0A * feature statistics. The kind of statistic gathered depends on the type%0A * of value passed in for each data point. %0A * %3Cp%3E%0A * Currently statistics are calculated like this, depending on the type%0A * of value passed in:%0A * %3Cul%3E%0A * %3Cli%3ENumeric: over the double representation of the value itself%0A * %3Cli%3EBoolean: over the 0/1 representation of false/true%0A * %3Cli%3EString: For now, no statistics are generated for this%0A * %3Cli%3EList/Array: over the size of the list or array%0A * %3C/ul%3E%0A * %0A * @author Johann Petrak %3Cjohann.petrak@gmail.com%3E%0A */%0Apublic class StatsForFeatures %7B%0A  private Map%3CString,SummaryStatistics%3E feature2stats = new HashMap%3C%3E();%0A  private final Object lockingObject = new Object();%0A  %0A  public void addValue(String featureName, Object value) %7B%0A    synchronized(lockingObject) %7B%0A      SummaryStatistics stats;%0A      if(feature2stats.containsKey(featureName)) %7B%0A        stats = feature2stats.get(featureName);%0A      %7D else %7B%0A        stats = new SummaryStatistics();%0A        feature2stats.put(featureName, stats);%0A      %7D%0A      if(value instanceof Double) %7B%0A        stats.addValue((Double)value);%0A      %7D else if(value instanceof Number) %7B%0A         stats.addValue(((Number) value).doubleValue());%0A      %7D else if(value instanceof String) %7B%0A        // none for now     %0A      %7D else if(value instanceof Boolean) %7B%0A        stats.addValue(((Boolean)value) ? 1.0 : 0.0);%0A      %7D else if(value instanceof List) %7B%0A        stats.addValue(((List)value).size());%0A      %7D else if(value instanceof String%5B%5D) %7B%0A        stats.addValue(((double%5B%5D)value).length);%0A      %7D else if(value instanceof double%5B%5D) %7B%0A        stats.addValue(((double%5B%5D)value).length);%0A      %7D else %7B%0A        // for now just silently ignore this!!%0A      %7D%0A    %7D // synchronized%0A  %7D // addValue(...)%0A  %0A  public SummaryStatistics getStatistics(String featureName) %7B%0A    synchronized(lockingObject) %7B%0A      return feature2stats.get(featureName);%0A    %7D%0A  %7D%0A%7D%0A

Add a simple stats collecting class.