[features] Feature array, a special case of contiguous string array for adding namespaced features in CRF-like sequence models
This commit is contained in:
22
src/features.c
Normal file
22
src/features.c
Normal 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
22
src/features.h
Normal 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
|
||||
Reference in New Issue
Block a user