More code cleanup
[svmtool++.git] / src / learner.h
blob6a70a03ce2cf6d68386f07a9a7c0f225ac71ba0c
1 /*
2 * Copyright (C) 2004 Jesus Gimenez, Lluis Marquez and Senen Moya
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef SVMT_LEARNER_H
21 struct samples_counter_t
23 char *key;
24 int positive;
25 int negative;
28 class learner
30 private:
31 int learnerNumAMBP,learnerNumUNKP;
32 hash_t *learnerAMBP_H,*learnerUNKP_H;
33 swindow *sw;
34 simpleList learnerFeatureList,*learnerAMBP_L,*learnerUNKP_L;
35 FILE *fKnown,*fUnknown;
36 int learnerNumFeatures;
37 char obtainAtrChar(FILE *channel);
38 int obtainAtrInt(FILE *channel,int *endAtr);
39 void learnerCreateFeatureList(char *name, simpleList *featureList);
40 simpleList *learnerTransformHashInList(hash_t *tptr);
41 void learnerCreateDefaultFile(const char *modelName, const char *str);
42 void learnerCreatePOSFile(char *modelName, int is_ambp, hash_t *h);
43 void learnerCount(char *name, int *sentences, int *words);
44 int learnerExecSVMlight(char *svmdir, char *options, char *posFile, char *outFile);
45 int learnerLeftToRight(simpleList *, simpleList *, dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
46 int learnerRightToLeft(simpleList *,simpleList *, dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
47 void learnerGetFeatures(nodo *elem, stack_t *stk,dictionary *d, simpleList *featureList, int direction);
48 void learnerGenerateFeatures(nodo *elem,simpleList *featureList, dictionary *d, int direction);
49 void learnerGenerateFeaturesUnk(nodo *elem,simpleList *featureList, dictionary *d, dictionary *dUnk, int direction);
50 void learnerTrainModel(char *trainingFileName,dictionary *d, int numModel,int direction, int numSent, int numWords, int numChunks);
51 weightRepository *learnerBuiltWeightRepository(weightRepository *wr,mapping *m,char *pos,char *fileName);
52 hash_t *learnerBuiltBias(hash_t *,char *pos,char *fileName);
53 void learnerDestroyBias(hash_t *h);
54 int learnerIsPossiblePOS(char *wrd, char *pos, int Known_or_Unknown);
55 simpleList *learnerGetPotser(char *wrd, int Known_or_Unknown, dictionary *d);
56 void learnerTraining(FILE *f,char *modelName, int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lpos);
57 void learnerPrintMessage(int numModel, int K_or_U, int LR_or_RL,int is_fex);
58 int learnerNumChunks(char *trainingFileName,float percentage,int nSentences);
59 int learnerIsInsideList(simpleList *l, char *key);
60 void learnerDoLearn(FILE *f,int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lPosToTrain);
61 void learnerDressNakedSetTrain(dictionary *d,mapping *m,FILE *f, char* pos, int numModel, int direction, int K_or_U,int *nPos,int *nNeg);
62 void learnerPushSample(char *wrd,int numModel,int direction, int Known_or_Unknown, char *pos,char *samplePos,char *features,dictionary *d, int *nNeg, int *nPos);
63 void learnerPushSampleUnk(char *wrd,int numModel,int direction, int Known_or_Unknown,char *pos, char *samplePos, char *features,dictionary *d, int *nNeg, int *nPos);
64 char *learnerCreateFeatureString(FILE *f,mapping *m);
66 char *read_feature_list_from_config_file(FILE *f, char *first_feature);
67 void read_config_file(const char *config_file);
69 public:
70 learner(char *modelName);
71 learner();
72 ~learner();
73 void learnerRun(char *train);
76 #define SVMT_LEARNER_H
77 #endif