[features] Adding counter/bag-of-words representation of features
This commit is contained in:
@@ -23,3 +23,20 @@ void feature_array_add(cstring_array *features, size_t count, ...) {
|
|||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool feature_counts_update(khash_t(str_uint32) *features, char *feature, int count) {
|
||||||
|
khiter_t k;
|
||||||
|
|
||||||
|
k = kh_get(str_uint32, features, feature);
|
||||||
|
if (k == kh_end(features)) {
|
||||||
|
int ret;
|
||||||
|
k = kh_put(str_uint32, features, feature, &ret);
|
||||||
|
if (ret < 0) return false;
|
||||||
|
|
||||||
|
kh_value(features, k) = count;
|
||||||
|
} else {
|
||||||
|
kh_value(features, k) += count;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#ifndef FEATURES_H
|
#ifndef FEATURES_H
|
||||||
#define FEATURES_H
|
#define FEATURES_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "collections.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#define FEATURE_SEPARATOR_CHAR "|"
|
#define FEATURE_SEPARATOR_CHAR "|"
|
||||||
|
|
||||||
|
// Add feature to array
|
||||||
|
|
||||||
void feature_array_add(cstring_array *features, size_t count, ...);
|
void feature_array_add(cstring_array *features, size_t count, ...);
|
||||||
|
|
||||||
|
// Add feature count to dictionary
|
||||||
|
|
||||||
|
bool feature_counts_update(khash_t(str_uint32) *features, char *feature, int count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user