[features] Feature array, a special case of contiguous string array for adding namespaced features in CRF-like sequence models

This commit is contained in:
Al
2015-03-14 18:37:41 -04:00
parent 3e20b4f600
commit 0df849b440
2 changed files with 44 additions and 0 deletions

22
src/features.c Normal file
View File

@@ -0,0 +1,22 @@
#include "features.h"
void feature_array_add(char_array *features, int num_args, ...) {
if (num_args <= 0) {
return;
}
va_list args;
va_start(args, num_args);
for (int i = 0; i < num_args - 1; i++) {
char *arg = va_arg(args, char *);
contiguous_string_array_add_string_unterminated(features, arg);
contiguous_string_array_add_string_unterminated(features, FEATURE_SEPARATOR_CHAR);
}
char *arg = va_arg(args, char *);
contiguous_string_array_add_string(features, arg);
va_end(args);
}

22
src/features.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef FEATURES_H
#define FEATURES_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include "string_utils.h"
#define FEATURE_SEPARATOR_CHAR "|"
void feature_array_add(char_array *features, int num_args, ...);
#ifdef __cplusplus
}
#endif
#endif