/usr/include/timbl/Types.h is in libtimbl4-dev 6.4.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | /*
Copyright (c) 1998 - 2016
ILK - Tilburg University
CLST - Radboud University
CLiPS - University of Antwerp
This file is part of timbl
timbl is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
timbl 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
For questions and suggestions, see:
https://github.com/LanguageMachines/timbl/issues
or send mail to:
lamasoftware (at ) science.ru.nl
*/
#ifndef TIMBL_TYPES_H
#define TIMBL_TYPES_H
#include <string>
#include <set>
#include <vector>
#include <map>
#include <exception>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include "ticcutils/StringOps.h"
#include "timbl/StringOps.h"
namespace Timbl {
enum InputFormatType { UnknownInputFormat,
Compact, C4_5, Columns, Tabbed, ARFF, SparseBin,
Sparse,
MaxInputFormat };
inline InputFormatType& operator++( InputFormatType &I ){
return I = ( MaxInputFormat == I )
? UnknownInputFormat
: InputFormatType(I+1);
}
enum WeightType { Unknown_w,
No_w, GR_w, IG_w, X2_w, SV_w, SD_w, UserDefined_w,
Max_w };
inline WeightType& operator++( WeightType &W ){
return W = ( Max_w == W ) ? Unknown_w : WeightType(W+1);
}
enum AlgorithmType { Unknown_a,
IB1_a, IB2_a, IGTREE_a, TRIBL_a, TRIBL2_a,
LOO_a, CV_a,
Max_a };
inline AlgorithmType& operator++( AlgorithmType &W ){
return W = ( Max_a == W ) ? Unknown_a : AlgorithmType(W+1);
}
enum MetricType { UnknownMetric, Ignore,
Numeric, DotProduct, Cosine, Overlap, Levenshtein,
Dice, ValueDiff, JeffreyDiv, JSDiv, Euclidean, MaxMetric };
inline MetricType& operator++( MetricType &W ){
return W = ( MaxMetric == W ) ? UnknownMetric : MetricType(W+1);
}
enum OrdeningType { UnknownOrdening, DataFile, NoOrder,
GROrder, IGOrder,
OneoverFeature, OneoverSplitInfo,
GRoverFeature, IGoverFeature,
GREntropyOrder, IGEntropyOrder,
X2Order, SVOrder, SDOrder,
X2overFeature, SVoverFeature, SDoverFeature,
MaxOrdening };
inline OrdeningType& operator++( OrdeningType &W ){
return W = ( MaxOrdening == W ) ? UnknownOrdening : OrdeningType(W+1);
}
enum VerbosityFlags { NO_VERB=0, SILENT=1, OPTIONS=2, FEAT_W=4,
VD_MATRIX=8, EXACT=16, DISTANCE=32, DISTRIB=64,
NEAR_N=128, ADVANCED_STATS=256, CONF_MATRIX=512,
CLASS_STATS=1024, CLIENTDEBUG=2048, ALL_K=4096,
MATCH_DEPTH=8192, BRANCHING=16384, CONFIDENCE=32768,
MAX_VERB };
inline VerbosityFlags operator~( VerbosityFlags V ){
return (VerbosityFlags)( ~(int)V );
}
inline VerbosityFlags operator|( VerbosityFlags V1, VerbosityFlags V2 ){
return (VerbosityFlags)( (int)V1|(int)V2 );
}
inline VerbosityFlags& operator|= ( VerbosityFlags& f, VerbosityFlags g ){
f = (f | g);
return f;
}
inline VerbosityFlags operator& ( VerbosityFlags f, VerbosityFlags g ){
return (VerbosityFlags)((int)f & (int)g );
}
inline VerbosityFlags& operator&= ( VerbosityFlags& f, VerbosityFlags g ){
f = (f & g);
return f;
}
enum OptType { UnknownOpt,
StringT, IntegerT, BooleanT, VerbosityT, IFormatT,
AlgoT, MetricT, WeightT, OrdeningT,
MaxOpt };
inline OptType& operator++( OptType &W ){
return W = ( MaxOpt == W ) ? UnknownOpt : OptType(W+1);
}
enum DecayType { UnknownDecay,
Zero, InvDist, InvLinear, ExpDecay, MaxDecay };
inline DecayType& operator++( DecayType &W ){
return W = ( MaxDecay == W ) ? UnknownDecay : DecayType(W+1);
}
enum SmoothingType { UnknownSmoothing, Default, Lidstone, MaxSmoothing };
inline SmoothingType& operator++( SmoothingType &W ){
return W = ( MaxSmoothing == W ) ? UnknownSmoothing : SmoothingType(W+1);
}
enum normType { unknownNorm, noNorm, probabilityNorm,
addFactorNorm, logProbNorm, maxNorm };
inline normType& operator++( normType &W ){
return W = ( maxNorm == W ) ? noNorm : normType(W+1);
}
extern const std::string DecayName[][2];
extern const std::string OrdeningName[][2];
extern const std::string WeightName[][2];
extern const std::string MetricName[][2];
extern const std::string InputFormatName[][2];
extern const std::string AlgorithmName[][2];
extern const std::string SmoothingName[][2];
extern const std::string VerbosityName[][2];
extern const std::string NormalisationName[][2];
WeightType charToWeig( char );
AlgorithmType charToAlg( char );
normType charToNorm( char );
}
namespace TiCC {
//
// We create specializations of TiCC templates
// the must be placed in the TiCC namespace (isn't it?)
//
using namespace Timbl;
template <>
inline DecayType stringTo<DecayType>( const std::string& str ) {
DecayType d = UnknownDecay;
for ( ++d; d < MaxDecay; ++d ){
if ( compare_nocase( str, DecayName[d][0] ) ||
compare_nocase( str, DecayName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to decayType failed" ) );
return UnknownDecay;
}
template <>
inline std::string toString<DecayType>( const DecayType& W, bool b ){
if ( b )
return DecayName[W][1];
else
return DecayName[W][0];
}
template <>
inline OrdeningType stringTo<OrdeningType>( const std::string& str ) {
OrdeningType d = UnknownOrdening;
for ( ++d; d < MaxOrdening; ++d ){
if ( compare_nocase( str, OrdeningName[d][0] ) ||
compare_nocase( str, OrdeningName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to ordeningType failed" ) );
return UnknownOrdening;
}
template <>
inline std::string toString<OrdeningType>( const OrdeningType& W,
bool b ){
return OrdeningName[W][(b?1:0)];
}
template <>
inline MetricType stringTo<MetricType>( const std::string& str ) {
MetricType d = UnknownMetric;
for ( ++d; d < MaxMetric; ++d ){
if ( compare_nocase( str, MetricName[d][0] ) ||
compare_nocase( str, MetricName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to metricType failed" ) );
return UnknownMetric;
}
template <>
inline std::string toString<MetricType>( const MetricType& W, bool b ){
if ( b )
return MetricName[W][1];
else
return MetricName[W][0];
}
template <>
inline WeightType stringTo<WeightType>( const std::string& str ) {
WeightType w = Unknown_w;
if ( str.length() == 1 && isdigit(str[0]) ){
w = charToWeig( str[0] );
}
if ( w != Unknown_w )
return w;
for ( ++w; w < Max_w; ++w ){
if ( compare_nocase( str, WeightName[w][0] ) ||
compare_nocase( str, WeightName[w][1] ) ){
return w;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to weightType failed" ) );
return Unknown_w;
}
template <>
inline std::string toString<WeightType>( const WeightType& W, bool b ){
if ( b )
return WeightName[W][1];
else
return WeightName[W][0];
}
template <>
inline AlgorithmType stringTo<AlgorithmType>( const std::string& str ) {
AlgorithmType a = Unknown_a;
if ( str.length() == 1 && isdigit(str[0]) ){
a = charToAlg( str[0] );
}
if ( a != Unknown_a )
return a;
for ( ++a; a < Max_a; ++a ){
if ( compare_nocase( str, AlgorithmName[a][0] ) ||
compare_nocase( str, AlgorithmName[a][1] ) ){
return a;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to algorithmType failed" ) );
return Unknown_a;
}
template <>
inline std::string toString<AlgorithmType>( const AlgorithmType& a,
bool b ){
if ( b )
return AlgorithmName[a][1];
else
return AlgorithmName[a][0];
}
template <>
inline InputFormatType stringTo<InputFormatType>( const std::string& str ){
InputFormatType d = UnknownInputFormat;
for ( ++d; d < MaxInputFormat; ++d ){
if ( compare_nocase( str, InputFormatName[d][0] ) ||
compare_nocase( str, InputFormatName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to weightType failed" ) );
return UnknownInputFormat;
}
template <>
inline std::string toString<InputFormatType>( const InputFormatType& i,
bool b ){
if ( b )
return InputFormatName[i][1];
else
return InputFormatName[i][0];
}
template <>
inline SmoothingType stringTo<SmoothingType>( const std::string& str ) {
SmoothingType d = UnknownSmoothing;
for ( ++d; d < MaxSmoothing; ++d ){
if ( compare_nocase( str, SmoothingName[d][0] ) ||
compare_nocase( str, SmoothingName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to smoothingType failed" ) );
return UnknownSmoothing;
}
template <>
inline std::string toString<SmoothingType>( const SmoothingType& s,
bool b ){
if ( b )
return SmoothingName[s][1];
else
return SmoothingName[s][0];
}
template <>
inline normType stringTo<normType>( const std::string& str ) {
normType d = unknownNorm;
if ( str.length() == 1 && isdigit(str[0]) ){
d = charToNorm( str[0] );
}
if ( d != unknownNorm )
return d;
for ( ++d; d < maxNorm; ++d ){
if ( compare_nocase( str, NormalisationName[d][0] ) ||
compare_nocase( str, NormalisationName[d][1] ) ){
return d;
}
}
throw( std::runtime_error( "conversion from string '"
+ str + "' to normalisationType failed" ) );
return unknownNorm;
}
template <>
inline std::string toString<normType>( const normType& s,
bool b ){
if ( b )
return NormalisationName[s][1];
else
return NormalisationName[s][0];
}
inline bool string_to_verbflag( const std::string& line,
VerbosityFlags &a ){
unsigned int i;
for ( i=0; VerbosityName[i][0][0] != '\0'; i++ )
if ( compare_nocase( line, VerbosityName[i][0] ) ||
compare_nocase( line, VerbosityName[i][1] ) ){
if ( i==0 ){
a = NO_VERB;
}
else{
a = (VerbosityFlags)(1<<(i-1));
}
return true;
}
return false;
}
template <>
inline VerbosityFlags stringTo<VerbosityFlags>( const std::string& str ) {
std::vector<std::string> tmp;
size_t cnt = TiCC::split_at( str, tmp, "+" );
VerbosityFlags V = NO_VERB;
for ( size_t i=0; i < cnt; ++i ){
VerbosityFlags Flag;
if ( string_to_verbflag( tmp[i], Flag ) ){
V |= Flag;
}
else {
throw( std::runtime_error( "conversion from string '"
+ str + "' to verbosityFlag failed" ) );
}
}
return V;
}
inline std::string verbosity_to_string( int v, bool full ){
if ( v == 0 )
return VerbosityName[0][(full?1:0)];
else {
std::string OutLine;
bool first = true;
for ( unsigned int i=1; VerbosityName[i][0][0] != '\0'; ++i )
if ( v & (1<<(i-1)) ){
if (first)
first = false;
else
OutLine += '+';
OutLine += VerbosityName[i][(full?1:0)];
}
return OutLine;
}
}
template <>
inline std::string toString<VerbosityFlags>( const VerbosityFlags& v,
bool full ){
return verbosity_to_string( (int)v, full );
}
inline std::string toString( const AlgorithmType& a, bool b=false ){
return toString<AlgorithmType>( a, b );
}
inline std::string toString( const MetricType& a, bool b=false ){
return toString<MetricType>( a, b );
}
inline std::string toString( const WeightType& a, bool b=false ){
return toString<WeightType>( a, b );
}
inline std::string toString( const InputFormatType& a, bool b=false ){
return toString<InputFormatType>( a, b );
}
inline std::string toString( const DecayType& a, bool b=false ){
return toString<DecayType>( a, b );
}
inline std::string toString( const OrdeningType& a, bool b=false ){
return toString<OrdeningType>( a, b );
}
inline std::string toString( const VerbosityFlags& a, bool b=false ){
return toString<VerbosityFlags>( a, b );
}
}
#endif
|