ConfigChecker.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of ALIZE which is an open-source tool for 
00003         speaker recognition.
00004 
00005     ALIZE is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as 
00007     published by the Free Software Foundation, either version 3 of 
00008     the License, or any later version.
00009 
00010     ALIZE is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public 
00016     License along with ALIZE.
00017     If not, see <http://www.gnu.org/licenses/>.
00018         
00019         ALIZE is a development project initiated by the ELISA consortium
00020         [alize.univ-avignon.fr/] and funded by the French Research 
00021         Ministry in the framework of the TECHNOLANGUE program 
00022         [www.technolangue.net]
00023 
00024         The ALIZE project team wants to highlight the limits of voice
00025         authentication in a forensic context.
00026         The "Person  Authentification by Voice: A Need of Caution" paper 
00027         proposes a good overview of this point (cf. "Person  
00028         Authentification by Voice: A Need of Caution", Bonastre J.F., 
00029         Bimbot F., Boe L.J., Campbell J.P., Douglas D.A., Magrin-
00030         chagnolleau I., Eurospeech 2003, Genova].
00031         The conclusion of the paper of the paper is proposed bellow:
00032         [Currently, it is not possible to completely determine whether the 
00033         similarity between two recordings is due to the speaker or to other 
00034         factors, especially when: (a) the speaker does not cooperate, (b) there 
00035         is no control over recording equipment, (c) recording conditions are not 
00036         known, (d) one does not know whether the voice was disguised and, to a 
00037         lesser extent, (e) the linguistic content of the message is not 
00038         controlled. Caution and judgment must be exercised when applying speaker 
00039         recognition techniques, whether human or automatic, to account for these 
00040         uncontrolled factors. Under more constrained or calibrated situations, 
00041         or as an aid for investigative purposes, judicious application of these 
00042         techniques may be suitable, provided they are not considered as infallible.
00043         At the present time, there is no scientific process that enables one to 
00044         uniquely characterize a person=92s voice or to identify with absolute 
00045         certainty an individual from his or her voice.]
00046         Contact Jean-Francois Bonastre for more information about the licence or
00047         the use of ALIZE
00048 
00049         Copyright (C) 2003-2010
00050         Laboratoire d'informatique d'Avignon [lia.univ-avignon.fr]
00051         ALIZE admin [alize@univ-avignon.fr]
00052         Jean-Francois Bonastre [jean-francois.bonastre@univ-avignon.fr]
00053 */
00054 
00055 #if !defined(ALIZE_ConfigChecker_cpp)
00056 #define ALIZE_ConfigChecker_cpp
00057 
00058 #include "ConfigChecker.h"
00059 #include "Config.h"
00060 #include "Exception.h"
00061 #include <new>
00062 
00063 using namespace alize;
00064 typedef ConfigChecker CC;
00065 
00066 //-------------------------------------------------------------------------
00067 CC::ConfigChecker()
00068 :Object() {}
00069 //-------------------------------------------------------------------------
00070 void CC::check(const Config& config)
00071 {
00072   unsigned long i;
00073   for (i=0; i<_vect.size(); i++)
00074   {
00075     const Param& c = _vect.getObject(i);
00076     if (!config.existsParam(c.name))
00077     {
00078       if (c.mandatory)
00079         err("Parameter '" + c.name + "' mandatory in the config");
00080     }
00081     else
00082     {
00083       const String& content = config.getParam(c.name);
00084       if (c.type != PARAMTYPE_BOOLEAN && c.argIsRequired
00085           && content.getToken(0) == "")
00086         err("Parameter '" + c.name + "' argument required");
00087 
00088       if (c.type == PARAMTYPE_INTEGER)
00089       {
00090         try { content.toLong(); }
00091         catch (Exception&)
00092         {
00093           err("Value '" + content + "' of parameter '"
00094                + c.name + "' is not an integer");
00095         }
00096       }
00097       else if (c.type == PARAMTYPE_FLOAT)
00098       {
00099         try { content.toDouble(); }
00100         catch (Exception&)
00101         {
00102           err("Value '" + content + "' of parameter '"
00103                + c.name + "' is not a float");
00104         }
00105       }
00106       else if (c.type == PARAMTYPE_BOOLEAN)
00107       {
00108         try
00109         {
00110           String l = content;
00111           if (l != "")
00112             l.toBool();
00113         }
00114         catch (Exception&)
00115         {
00116           err("Value '" + content + "' of parameter '"
00117                + c.name + "' is not '' nor 'true' nor 'false'");
00118         }
00119       }
00120       else if (c.type == PARAMTYPE_STRING)
00121       {
00122         // no test
00123       }
00124     }
00125   }
00126 }
00127 //-------------------------------------------------------------------------
00128 void CC::err(const String& e) const
00129 { throw ConfigCheckException(e, __FILE__, __LINE__); }
00130 //-------------------------------------------------------------------------
00131 void CC::checkName(const String& name) const
00132 {
00133   if (name.getToken(0) == "")
00134     throw Exception("parameter name cannot be empty", __FILE__, __LINE__);
00135 }
00136 //-------------------------------------------------------------------------
00137 void CC::addIntegerParam(const String& name, bool mandatory,
00138                          bool argIsRequired, const String& desc)
00139 {
00140   checkName(name);
00141   Param* p = new (std::nothrow) Param();
00142   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00143   p->name = name;
00144   p->type = PARAMTYPE_INTEGER;
00145   p->mandatory = mandatory;
00146   p->argIsRequired = argIsRequired;
00147   p->description = desc;
00148   _vect.addObject(*p);
00149 }
00150 //-------------------------------------------------------------------------
00151 void CC::addFloatParam(const String& name, bool mandatory,
00152                        bool argIsRequired, const String& desc)
00153 {
00154   checkName(name);
00155   Param* p = new (std::nothrow) Param();
00156   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00157   p->name = name;
00158   p->type = PARAMTYPE_FLOAT;
00159   p->mandatory = mandatory;
00160   p->argIsRequired = argIsRequired;
00161   p->description = desc;
00162   _vect.addObject(*p);
00163 }
00164 //-------------------------------------------------------------------------
00165 void CC::addBooleanParam(const String& name, bool mandatory,
00166                          bool argIsRequired, const String& desc)
00167 {
00168   checkName(name);
00169   Param* p = new (std::nothrow) Param();
00170   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00171   p->name = name;
00172   p->type = PARAMTYPE_BOOLEAN;
00173   p->mandatory = mandatory;
00174   p->argIsRequired = argIsRequired;
00175   p->description = desc;
00176   _vect.addObject(*p);
00177 }
00178 //-------------------------------------------------------------------------
00179 void CC::addStringParam(const String& name, bool mandatory,
00180                         bool argIsRequired, const String& desc)
00181 {
00182   checkName(name);
00183   Param* p = new (std::nothrow) Param();
00184   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00185   p->name = name;
00186   p->type = PARAMTYPE_STRING;
00187   p->mandatory = mandatory;
00188   p->argIsRequired = argIsRequired;
00189   p->description = desc;
00190   _vect.addObject(*p);
00191 }
00192 //-------------------------------------------------------------------------
00193 String CC::getParamList()
00194 {
00195   unsigned long i;
00196   unsigned long length = 9;
00197   for (i=0; i<_vect.size(); i++)
00198   {
00199     unsigned long l = 2+_vect.getObject(i).name.length();
00200     if (l > length)
00201       length = l;
00202   }
00203   String s, n;
00204   n = "--help";
00205   while (n.length() < length) n += " ";
00206   s += n + " Show this help\n";
00207   n = "--version";
00208   while (n.length() < length) n += " ";
00209   s += n + " Show version information\n";
00210 
00211   for (i=0; i<_vect.size(); i++)
00212   {
00213     const Param& c = _vect.getObject(i);
00214     n = "--" + c.name;
00215     while (n.length() < length) n += " ";
00216     s += n + " "
00217 //      +  String(c.mandatory?"(mandatory)":"(optional)") + " "
00218       +  c.description + " "
00219       +  "<" + getParamTypeName(c.type) + ">"
00220       +  "\n";
00221   }
00222   return s;
00223 }
00224 //-------------------------------------------------------------------------
00225 //unsigned long CC::getCount() const { return _vect.size(); }
00226 //-------------------------------------------------------------------------
00227 String CC::getClassName() const { return "ConfigChecker";}
00228 //-------------------------------------------------------------------------
00229 CC::~ConfigChecker() { _vect.deleteAllObjects(); }
00230 //-------------------------------------------------------------------------
00231 String CC::Param::getClassName() const { return "Param"; }
00232 //-------------------------------------------------------------------------
00233 #endif // !defined(ALIZE_ConfigChecker_cpp)