gate.plugin.learningframework.stats.StatsForFeatures Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of learningframework Show documentation
Show all versions of learningframework Show documentation
A GATE plugin that provides many different machine learning
algorithms for a wide range of NLP-related machine learning tasks like
text classification, tagging, or chunking.
/*
* Copyright (c) 2015-2016 The University Of Sheffield.
*
* This file is part of gateplugin-LearningFramework
* (see https://github.com/GateNLP/gateplugin-LearningFramework).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see .
*/
package gate.plugin.learningframework.stats;
import java.util.HashMap;
import java.util.Map;
/**
* A simple lightweight wrapper class for maintaining stats about many features.
*
* This gathers statistics about many features, mapping feature names to
* feature statistics. The kind of statistic gathered depends on the type
* of value passed in for each data point.
*
* Currently statistics are calculated like this, depending on the type
* of value passed in:
*
* - Numeric: over the double representation of the value itself
*
- Boolean: over the 0/1 representation of false/true
*
- String: For now, no statistics are generated for this
*
- List/Array: over the size of the list or array
*
*
* @author Johann Petrak
*/
public class StatsForFeatures {
private Map feature2stats = new HashMap<>();
private final Object lockingObject = new Object();
public static final String KEY_FOR_TARGET = "╳TARGET╳";
/**
* Add a value to the stats object
* @param featureName feature name
* @param value value to add
*/
public void addValue(String featureName, Object value) {
synchronized(lockingObject) {
Stats stats;
if(feature2stats.containsKey(featureName)) {
stats = feature2stats.get(featureName);
} else {
stats = new Stats(value);
feature2stats.put(featureName, stats);
}
stats.addValue(value);
} // synchronized
} // addValue(...)
/**
* Get the statistics object for the feature.
* @param featureName feature
* @return stats object
*/
public Stats getStatistics(String featureName) {
synchronized(lockingObject) {
return feature2stats.get(featureName);
}
}
}