More code cleanup
authorMiriam Ruiz <[email protected]>
Sun, 20 Nov 2011 20:02:58 +0000 (20 21:02 +0100)
committerMiriam Ruiz <[email protected]>
Sun, 20 Nov 2011 20:02:58 +0000 (20 21:02 +0100)
src/common.h
src/dict.h
src/er.h
src/hash.h
src/learner.h
src/list.h
src/mapping.h
src/marks.h
src/stack.h
src/weight.h

index 8bd4837..66cb205 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef COMMON_H
+#ifndef SVMT_COMMON_H
 
 #include <time.h>
 #include <sys/times.h>
@@ -68,5 +68,5 @@ void destroyFeatureList(simpleList *, int);
 void createFeatureList(char *, simpleList *);
 void removeFiles(char *, int ,int , int, int);
 
-#define COMMON_H
+#define SVMT_COMMON_H
 #endif
index 58144fb..8d0c789 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <stdint.h>
 
-#ifndef DICT_H
+#ifndef SVMT_DICT_H
 
 #define TAMTXT 100
 
@@ -75,5 +75,5 @@ class  dictionary
                void dictWrite(char *outName);
 };
 
-#define DICT_H
+#define SVMT_DICT_H
 #endif
index c8e67a2..b29ca31 100644 (file)
--- a/src/er.h
+++ b/src/er.h
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef ER_H
+#ifndef SVMT_ER_H
 
 #include <sys/types.h>
 #include <regex.h>
 
 extern regex_t  erCard,erCardPunct,erCardSeps,erCardSuffix;
 extern regex_t  erMultiWord,erContainNum,erStartCap,erStartLower,erStartNumber,
-erAllUp,erAllLow,erContainCap,erContainCaps,erContainPeriod,erContainComma;
+                erAllUp,erAllLow,erContainCap,erContainCaps,erContainPeriod,erContainComma;
 
 void erCompRegExp();
 void erFreeRegExp();
-int erLookRegExp2(void *er,char * str);
+int erLookRegExp2(void *er, char * str);
 int erLookRegExp(char *m);
 
-#define ER_H
+#define SVMT_ER_H
 #endif
index bac738e..85f26ae 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef SVMT_HASH_H
+
 #include <stdint.h>
 
 #ifdef __cplusplus
-
 extern "C"
 {
-       #endif
-
-       typedef struct hash_t
-       {
-                                                                /* array of hash nodes */
-               struct hash_node_t **bucket;
-               int size;                                /* size of the array */
-               int entries;                     /* number of entries in table */
-               int downshift;                   /* shift cound, used in hash function */
-               int mask;                                /* used to select bits for hashing */
-       } hash_t;
-
-       typedef struct hash_node_t
-       {
-               uintptr_t data;                  /* data in hash node */
-               const char * key;                /* key for hash lookup */
-               struct hash_node_t *next;/* next node in hash chain */
-       } hash_node_t;
-
-       #define HASH_FAIL -1
-
-       void hash_init(hash_t *, int);
-
-       uintptr_t hash_lookup (const hash_t *, const char *);
-
-       uintptr_t hash_insert (hash_t *, const char *, uintptr_t);
-
-       uintptr_t hash_delete (hash_t *, const char *);
-
-       void hash_destroy(hash_t *);
-
-       char *hash_stats (hash_t *);
-
-       void hash_print(hash_t *,FILE *f);
+#endif
 
-       void rebuild_table(hash_t *);
+typedef struct hash_t
+{
+       struct hash_node_t **bucket;   /* array of hash nodes */
+       int size;                      /* size of the array */
+       int entries;                   /* number of entries in table */
+       int downshift;                 /* shift cound, used in hash function */
+       int mask;                      /* used to select bits for hashing */
+} hash_t;
+
+typedef struct hash_node_t
+{
+       uintptr_t data;                /* data in hash node */
+       const char * key;              /* key for hash lookup */
+       struct hash_node_t *next;      /* next node in hash chain */
+} hash_node_t;
+
+#define HASH_FAIL -1
+
+void hash_init(hash_t *, int);
+uintptr_t hash_lookup (const hash_t *, const char *);
+uintptr_t hash_insert (hash_t *, const char *, uintptr_t);
+uintptr_t hash_delete (hash_t *, const char *);
+void hash_destroy(hash_t *);
+char *hash_stats (hash_t *);
+void hash_print(hash_t *,FILE *f);
+void rebuild_table(hash_t *);
 
-       #ifdef __cplusplus
+#ifdef __cplusplus
 }
 #endif
+
+#define SVMT_HASH_H
+#endif
dissimilarity index 74%
index b2040bf..6a70a03 100644 (file)
@@ -1,77 +1,77 @@
-/*
- * Copyright (C) 2004 Jesus Gimenez, Lluis Marquez and Senen Moya
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef LEARNER_H
-
-struct samples_counter_t
-{
-       char *key;
-       int positive;
-       int negative;
-};
-
-class learner
-{
-       private:
-               int learnerNumAMBP,learnerNumUNKP;
-               hash_t *learnerAMBP_H,*learnerUNKP_H;
-               swindow *sw;
-               simpleList learnerFeatureList,*learnerAMBP_L,*learnerUNKP_L;
-               FILE *fKnown,*fUnknown;
-               int learnerNumFeatures;
-               char obtainAtrChar(FILE *channel);
-               int  obtainAtrInt(FILE *channel,int *endAtr);
-               void learnerCreateFeatureList(char *name, simpleList *featureList);
-               simpleList *learnerTransformHashInList(hash_t *tptr);
-               void learnerCreateDefaultFile(const char *modelName, const char *str);
-               void learnerCreatePOSFile(char *modelName, int is_ambp, hash_t *h);
-               void learnerCount(char *name, int *sentences, int *words);
-               int learnerExecSVMlight(char *svmdir, char *options, char *posFile, char *outFile);
-               int learnerLeftToRight(simpleList *, simpleList *, dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
-               int learnerRightToLeft(simpleList *,simpleList *,   dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
-               void learnerGetFeatures(nodo *elem, stack_t *stk,dictionary *d, simpleList *featureList, int direction);
-               void learnerGenerateFeatures(nodo *elem,simpleList *featureList, dictionary *d, int direction);
-               void learnerGenerateFeaturesUnk(nodo *elem,simpleList *featureList, dictionary *d, dictionary *dUnk, int direction);
-               void learnerTrainModel(char *trainingFileName,dictionary *d, int numModel,int direction,  int numSent, int numWords, int numChunks);
-               weightRepository *learnerBuiltWeightRepository(weightRepository *wr,mapping *m,char *pos,char *fileName);
-               hash_t *learnerBuiltBias(hash_t *,char *pos,char *fileName);
-               void learnerDestroyBias(hash_t *h);
-               int learnerIsPossiblePOS(char *wrd, char *pos, int Known_or_Unknown);
-               simpleList *learnerGetPotser(char *wrd, int Known_or_Unknown, dictionary *d);
-               void learnerTraining(FILE *f,char *modelName, int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lpos);
-               void learnerPrintMessage(int numModel, int K_or_U, int LR_or_RL,int is_fex);
-               int  learnerNumChunks(char *trainingFileName,float percentage,int nSentences);
-               int learnerIsInsideList(simpleList *l, char *key);
-               void learnerDoLearn(FILE *f,int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lPosToTrain);
-               void learnerDressNakedSetTrain(dictionary *d,mapping *m,FILE *f, char* pos, int numModel, int direction, int K_or_U,int *nPos,int *nNeg);
-               void learnerPushSample(char *wrd,int numModel,int direction, int Known_or_Unknown, char *pos,char *samplePos,char *features,dictionary *d, int *nNeg, int *nPos);
-               void learnerPushSampleUnk(char *wrd,int numModel,int direction, int Known_or_Unknown,char *pos, char *samplePos, char *features,dictionary *d, int *nNeg, int *nPos);
-               char *learnerCreateFeatureString(FILE *f,mapping *m);
-
-               char *read_feature_list_from_config_file(FILE *f, char *first_feature);
-               void read_config_file(const char *config_file);
-
-       public:
-               learner(char *modelName);
-               learner();
-               ~learner();
-               void learnerRun(char *train);
-};
-
-#define LEARNER_H
-#endif
+/*
+ * Copyright (C) 2004 Jesus Gimenez, Lluis Marquez and Senen Moya
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef SVMT_LEARNER_H
+
+struct samples_counter_t
+{
+       char *key;
+       int positive;
+       int negative;
+};
+
+class learner
+{
+private:
+       int learnerNumAMBP,learnerNumUNKP;
+       hash_t *learnerAMBP_H,*learnerUNKP_H;
+       swindow *sw;
+       simpleList learnerFeatureList,*learnerAMBP_L,*learnerUNKP_L;
+       FILE *fKnown,*fUnknown;
+       int learnerNumFeatures;
+       char obtainAtrChar(FILE *channel);
+       int  obtainAtrInt(FILE *channel,int *endAtr);
+       void learnerCreateFeatureList(char *name, simpleList *featureList);
+       simpleList *learnerTransformHashInList(hash_t *tptr);
+       void learnerCreateDefaultFile(const char *modelName, const char *str);
+       void learnerCreatePOSFile(char *modelName, int is_ambp, hash_t *h);
+       void learnerCount(char *name, int *sentences, int *words);
+       int learnerExecSVMlight(char *svmdir, char *options, char *posFile, char *outFile);
+       int learnerLeftToRight(simpleList *, simpleList *, dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
+       int learnerRightToLeft(simpleList *,simpleList *,   dictionary *dKnown, dictionary *dUnknown,/*mapping *mKnown, mapping *mUnknown,*/int numWrds, int inicio);
+       void learnerGetFeatures(nodo *elem, stack_t *stk,dictionary *d, simpleList *featureList, int direction);
+       void learnerGenerateFeatures(nodo *elem,simpleList *featureList, dictionary *d, int direction);
+       void learnerGenerateFeaturesUnk(nodo *elem,simpleList *featureList, dictionary *d, dictionary *dUnk, int direction);
+       void learnerTrainModel(char *trainingFileName,dictionary *d, int numModel,int direction,  int numSent, int numWords, int numChunks);
+       weightRepository *learnerBuiltWeightRepository(weightRepository *wr,mapping *m,char *pos,char *fileName);
+       hash_t *learnerBuiltBias(hash_t *,char *pos,char *fileName);
+       void learnerDestroyBias(hash_t *h);
+       int learnerIsPossiblePOS(char *wrd, char *pos, int Known_or_Unknown);
+       simpleList *learnerGetPotser(char *wrd, int Known_or_Unknown, dictionary *d);
+       void learnerTraining(FILE *f,char *modelName, int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lpos);
+       void learnerPrintMessage(int numModel, int K_or_U, int LR_or_RL,int is_fex);
+       int  learnerNumChunks(char *trainingFileName,float percentage,int nSentences);
+       int learnerIsInsideList(simpleList *l, char *key);
+       void learnerDoLearn(FILE *f,int numModel,int LR_or_RL,int K_or_U,dictionary *d,simpleList *lPosToTrain);
+       void learnerDressNakedSetTrain(dictionary *d,mapping *m,FILE *f, char* pos, int numModel, int direction, int K_or_U,int *nPos,int *nNeg);
+       void learnerPushSample(char *wrd,int numModel,int direction, int Known_or_Unknown, char *pos,char *samplePos,char *features,dictionary *d, int *nNeg, int *nPos);
+       void learnerPushSampleUnk(char *wrd,int numModel,int direction, int Known_or_Unknown,char *pos, char *samplePos, char *features,dictionary *d, int *nNeg, int *nPos);
+       char *learnerCreateFeatureString(FILE *f,mapping *m);
+
+       char *read_feature_list_from_config_file(FILE *f, char *first_feature);
+       void read_config_file(const char *config_file);
+
+public:
+       learner(char *modelName);
+       learner();
+       ~learner();
+       void learnerRun(char *train);
+};
+
+#define SVMT_LEARNER_H
+#endif
index 407762a..84b1b48 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef SIMPLELIST_H
+#ifndef SVMT_LIST_H
 
 struct listNode
 {
@@ -29,30 +29,30 @@ struct listNode
 class simpleList
 {
 
-       private:
-               //List Control
-               listNode *first;
-               listNode *last;
-               listNode *index;
-               int numObj;
+private:
+       //List Control
+       listNode *first;
+       listNode *last;
+       listNode *index;
+       int numObj;
 
-       public:
-               ~simpleList();
-               simpleList();
-               void deleteList();
-               int next();
-               int previous();
-               void setFirst();
-               void *get(int position);
-               void *getIndex();
-               void *getFirst();
-               void *getLast();
-               int show();
-               int add(void *object);
-               int delIndex();
-               int isEmpty();
-               int numElements();
+public:
+       ~simpleList();
+       simpleList();
+       void deleteList();
+       int next();
+       int previous();
+       void setFirst();
+       void *get(int position);
+       void *getIndex();
+       void *getFirst();
+       void *getLast();
+       int show();
+       int add(void *object);
+       int delIndex();
+       int isEmpty();
+       int numElements();
 };
 
-#define SIMPLELIST_H
+#define SVMT_LIST_H
 #endif
index cbdab18..eb1c30d 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef MAPPING_H
+#ifndef SVMT_MAPPING_H
 
 class  mapping
 {
-       private:
-               hash_t *mapByKey;
-               hash_t *mapByNumber;
-               int mapping_counter;
-       public:
-               void  mappingWrite(char *,int);
-               int   mappingAddByKey(const char *key);
-               int   mappingAddNumber(const char *key);
-               int   mappingGetNumberByFeature(const char *key);
-               char *mappingGetFeatureByNumber(const char *key);
-               int   mappingRepair(int maxFeat, int times);
-               int   mappingNumElements();
-               void  mappingBuilt(FILE *f,int mac_mapping_size, int count_cut_off);
+private:
+       hash_t *mapByKey;
+       hash_t *mapByNumber;
+       int mapping_counter;
+public:
+       void  mappingWrite(char *,int);
+       int   mappingAddByKey(const char *key);
+       int   mappingAddNumber(const char *key);
+       int   mappingGetNumberByFeature(const char *key);
+       char *mappingGetFeatureByNumber(const char *key);
+       int   mappingRepair(int maxFeat, int times);
+       int   mappingNumElements();
+       void  mappingBuilt(FILE *f,int mac_mapping_size, int count_cut_off);
 
-               mapping();
-               ~mapping();
+       mapping();
+       ~mapping();
 };
 
-#define MAPPING_H
+#define SVMT_MAPPING_H
 #endif
index 2182ade..14cd11b 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef MARKS_H
+#ifndef SVMT_MARKS_H
 
-#define SLASTW "Swn"                    //Last Word
-#define WMARK  "w"                              //Words
-#define PMARK  "p"                              //POS
-#define KMARK  "k"                              //Ambiguity Classes
-#define MMARK  "m"                              //Maybe
-#define MFTMARK "f"                             //Most Frequent Tag --> f(-1) --> f-1:NN
-#define PREFIX_MARK  "a"                //prefixes
-#define SUFFIX_MARK  "z"                //Suffixes
-#define CHAR_A_MARK "ca"                //Character, counting from the beggining of the begining of the token (starting at 1)
-#define CHAR_Z_MARK "cz"                //Character, counting from the end of the begining of the token (starting at 1)
-#define LENGTH_MARK "L"                         //token length
-#define START_CAPITAL_MARK "SA"         //start with upper case
-#define START_LOWER_MARK   "sa"         //start with lower case
-#define START_NUMBER_MARK  "SN"         //start with number
-#define ALL_UPPER_MARK "AA"             //all upper case
-#define ALL_LOWER_MARK "aa"             //all lower case
-#define CONTAIN_CAP_MARK "CA"   //contains a capital letter
-#define CONTAIN_CAPS_MARK "CAA"         //contains several capital letters
-#define CONTAIN_PERIOD_MARK "CP" //contains period
-#define CONTAIN_COMMA_MARK "CC"         //contains comma
-#define CONTAIN_NUMBER_MARK "CN" //contains number
-#define MULTIWORD_MARK "MW"             //contains underscores (multiword)
+#define SLASTW "Swn"                   //Last Word
+#define WMARK  "w"                     //Words
+#define PMARK  "p"                     //POS
+#define KMARK  "k"                     //Ambiguity Classes
+#define MMARK  "m"                     //Maybe
+#define MFTMARK "f"                    //Most Frequent Tag --> f(-1) --> f-1:NN
+#define PREFIX_MARK  "a"               //prefixes
+#define SUFFIX_MARK  "z"               //Suffixes
+#define CHAR_A_MARK "ca"               //Character, counting from the beggining of the begining of the token (starting at 1)
+#define CHAR_Z_MARK "cz"               //Character, counting from the end of the begining of the token (starting at 1)
+#define LENGTH_MARK "L"                //token length
+#define START_CAPITAL_MARK "SA"        //start with upper case
+#define START_LOWER_MARK   "sa"        //start with lower case
+#define START_NUMBER_MARK  "SN"        //start with number
+#define ALL_UPPER_MARK "AA"            //all upper case
+#define ALL_LOWER_MARK "aa"            //all lower case
+#define CONTAIN_CAP_MARK "CA"          //contains a capital letter
+#define CONTAIN_CAPS_MARK "CAA"        //contains several capital letters
+#define CONTAIN_PERIOD_MARK "CP"       //contains period
+#define CONTAIN_COMMA_MARK "CC"        //contains comma
+#define CONTAIN_NUMBER_MARK "CN"       //contains number
+#define MULTIWORD_MARK "MW"            //contains underscores (multiword)
 
-#define MARKS_H
+#define SVMT_MARKS_H
 #endif
index a0e84f3..6830482 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef STACK_H
+#ifndef SVMT_STACK_H
 
-#define STACKSIZE   100
+#define STACKSIZE 100
 
 typedef enum {FALSE = 0, TRUE = 1}
 boolean;
 
 typedef void *element_type;
 
-/*
-class stack_t
-{
- public:
-       int top;
-       element_type items[STACKSIZE];
-
-       stack_t();
-       ~stack_t();
-};
-*/
-
 struct stack_t
 {
        int top;
@@ -49,5 +37,5 @@ element_type pop(struct stack_t *ps);
 void push(struct stack_t *ps, element_type x);
 element_type stack_top(struct stack_t *ps);
 
-#define STACK_h
+#define SVMT_STACK_h
 #endif
index a72317c..ebe7d51 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef WEIGHT_H
+#ifndef SVMT_WEIGHT_H
 
 typedef struct weight_node_t
 {
@@ -26,27 +26,26 @@ typedef struct weight_node_t
 
 class  weightRepository
 {
-       private:
-               hash_t wr;
+private:
+       hash_t wr;
 
-                                                                //ADD 180705
-               char *wrGetMergeInput(hash_t *tptr, float filter);
-               //char *wrGetMergeInput(hash_t *tptr); //DEL 180705
-               FILE *openFile(char *name, char mode[]);
-               void wrReadMergeModel(FILE *in,float filter);
-               char wrSaltarBlancs(FILE *in,char c,int jmp);
-               void wrAddPOS(uintptr_t obj, char* pos, long double weight);
-       public:
-               long double wrGetWeight(const char *feature,char *pos);
-               void wrAdd(char *feature, char* pos, long double weight);
-               //void wrWrite(const char *outName); //DEL 180705
-                                                                //ADD 180705
-               void wrWrite(const char *outName, float filter);
-               void wrWriteHash(hash_t *tptr,FILE *f,char separador);
-               weightRepository(char *fileName,float filter);
-               weightRepository();
-               ~weightRepository();
+       //char *wrGetMergeInput(hash_t *tptr); //DEL 180705
+       char *wrGetMergeInput(hash_t *tptr, float filter); //ADD 180705
+       FILE *openFile(char *name, char mode[]);
+       void wrReadMergeModel(FILE *in,float filter);
+       char wrSaltarBlancs(FILE *in,char c,int jmp);
+       void wrAddPOS(uintptr_t obj, char* pos, long double weight);
+
+public:
+       long double wrGetWeight(const char *feature,char *pos);
+       void wrAdd(char *feature, char* pos, long double weight);
+       //void wrWrite(const char *outName); //DEL 180705
+       void wrWrite(const char *outName, float filter); //ADD 180705
+       void wrWriteHash(hash_t *tptr,FILE *f,char separador);
+       weightRepository(char *fileName,float filter);
+       weightRepository();
+       ~weightRepository();
 };
 
-#define WEIGHT_H
+#define SVMT_WEIGHT_H
 #endif