FreeLing  4.0
dataset.h
Go to the documentation of this file.
00001 
00002 //
00003 //    Omlet - Open Machine Learning Enhanced Toolkit
00004 //
00005 //    Copyright (C) 2014   TALP Research Center
00006 //                         Universitat Politecnica de Catalunya
00007 //
00008 //    This file is part of the Omlet library
00009 //
00010 //    The Omlet library is free software; you can redistribute it 
00011 //    and/or modify it under the terms of the GNU Affero General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 3 of the License, or (at your option) any later version.
00014 //
00015 //    This library is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    Affero General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU Affero General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110-1301 USA
00023 //
00024 //    contact: Lluis Padro (padro@lsi.upc.es)
00025 //             TALP Research Center
00026 //             despatx Omega.S112 - Campus Nord UPC
00027 //             08034 Barcelona.  SPAIN
00028 //
00030 
00031 //
00032 // Author: Xavier Carreras
00033 //
00034 
00035 #ifndef _DATASET
00036 #define _DATASET
00037 
00038 #include <list>
00039 #include <vector>
00040 #include "freeling/omlet/example.h"
00041 
00042 namespace freeling {
00043 
00048 
00049   class dataset : public std::list<std::list<example>::iterator>
00050     {
00051     private:
00054       static std::list<example> all_examples;
00055 
00056       std::vector<int> size_pos;
00057       std::vector<int> size_neg;
00058       int dimension;
00059       int nlabels;
00060       void add_member(std::list<example>::iterator);
00061 
00062     public:
00063       dataset(int nlabels);
00064 
00066       void add_example(const example &); 
00067 
00069       //  int get_size() const;
00070       int get_negative_size(int l) const;
00071       int get_positive_size(int l) const;
00072       int get_nlabels() const;
00073       int get_dimension() const;
00074 
00075       void split(int feature, dataset &ds0, dataset &ds1) const;
00076 
00077       class iterator : public std::list<std::list<example>::iterator>::iterator {
00078       public:
00079         iterator () {};
00080         iterator (std::list<std::list<example>::iterator>::iterator x) : std::list<std::list<example>::iterator>::iterator(x) {}
00081         example& operator*() {
00082           return std::list<std::list<example>::iterator>::iterator::operator*().operator*();
00083         };
00084         example* operator->() {
00085           return std::list<std::list<example>::iterator>::iterator::operator*().operator->();
00086         };
00087       };
00088   
00089       class const_iterator : public std::list<std::list<example>::iterator>::const_iterator {
00090       public:
00091         const_iterator () {};
00092         const_iterator (std::list<std::list<example>::iterator>::const_iterator x) : std::list<std::list<example>::iterator>::const_iterator(x) {}
00093         example& operator*() {
00094           return std::list<std::list<example>::iterator>::const_iterator::operator*().operator*();
00095         };
00096         example* operator->() {
00097           return std::list<std::list<example>::iterator>::const_iterator::operator*().operator->();
00098         };
00099       };
00100   
00101       iterator begin() { return std::list<std::list<example>::iterator>::begin(); };
00102       iterator end() { return std::list<std::list<example>::iterator>::end(); };
00103       const_iterator begin() const { return std::list<std::list<example>::iterator>::begin(); };
00104       const_iterator end() const { return std::list<std::list<example>::iterator>::end(); };
00105 
00106     };
00107 
00108 } // namespace
00109 
00110 #endif
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129