[parser] Adding context struct to feature function
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ Link: http://www.cs.columbia.edu/~mcollins/papers/tagperc.pdf
|
||||
#include <stdlib.h>
|
||||
|
||||
#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,
|
||||
|
||||
Reference in New Issue
Block a user