From 8a86f7ec64e8cc5b872675c44b81a12de25dc5ff Mon Sep 17 00:00:00 2001 From: Al Date: Thu, 17 Sep 2015 05:48:00 -0400 Subject: [PATCH] [parser] Adding context struct to feature function --- src/averaged_perceptron_trainer.c | 7 ++----- src/averaged_perceptron_trainer.h | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/averaged_perceptron_trainer.c b/src/averaged_perceptron_trainer.c index ff96244a..12451ed0 100644 --- a/src/averaged_perceptron_trainer.c +++ b/src/averaged_perceptron_trainer.c @@ -1,9 +1,6 @@ #include "averaged_perceptron_trainer.h" #include "klib/ksort.h" -#define START "START" -#define START2 "START2" - KSORT_INIT_STR void averaged_perceptron_trainer_destroy(averaged_perceptron_trainer_t *self) { @@ -356,7 +353,7 @@ bool averaged_perceptron_trainer_update_counts(averaged_perceptron_trainer_t *se return true; } -bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *self, void *tagger, cstring_array *features, ap_tagger_feature_function feature_function, tokenized_string_t *tokenized, cstring_array *labels) { +bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *self, void *tagger, void *context, cstring_array *features, ap_tagger_feature_function feature_function, tokenized_string_t *tokenized, cstring_array *labels) { // Keep two tags of history in training char *prev = START; char *prev2 = START2; @@ -387,7 +384,7 @@ bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *se prev2 = cstring_array_get_string(labels, prev2_id); } - if (!feature_function(tagger, features, tokenized, i, prev, prev2)) { + if (!feature_function(tagger, context, tokenized, i, prev, prev2)) { log_error("Could not add address parser features\n"); return false; } diff --git a/src/averaged_perceptron_trainer.h b/src/averaged_perceptron_trainer.h index 2e54d59f..d6c868c4 100644 --- a/src/averaged_perceptron_trainer.h +++ b/src/averaged_perceptron_trainer.h @@ -34,6 +34,7 @@ Link: http://www.cs.columbia.edu/~mcollins/papers/tagperc.pdf #include #include "averaged_perceptron.h" +#include "averaged_perceptron_tagger.h" #include "collections.h" #include "string_utils.h" #include "tokens.h" @@ -51,8 +52,6 @@ KHASH_MAP_INIT_INT(class_weights, class_weight_t) KHASH_MAP_INIT_INT(feature_class_weights, khash_t(class_weights) *) -typedef bool (*ap_tagger_feature_function)(void *, cstring_array *, tokenized_string_t *, uint32_t, char *, char *); - typedef struct averaged_perceptron_trainer { uint32_t num_features; uint32_t num_classes; @@ -72,6 +71,7 @@ uint32_t averaged_perceptron_trainer_predict(averaged_perceptron_trainer_t *self bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *self, void *tagger, + void *context, cstring_array *features, ap_tagger_feature_function feature_function, tokenized_string_t *tokenized,