blob: 2336f85444786b899a1eea8d3a78e5652b7758eb [file] [log] [blame]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../src/collocatordb.h"
int main(int argc, char* argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n", argv[0]);
return 1;
}
char *dbpath = argv[1];
char *ext = strrchr(dbpath, '.');
if (ext && strcmp(ext, ".rocksdb") == 0) {
*ext = '\0';
}
COLLOCATORDB *cdb;
fprintf(stderr, "opening collocatordb for reading: %s ...\n", dbpath);
if (!(cdb = open_collocatordb(dbpath))) {
fprintf(stderr, "Error opening %s exiting.\n", dbpath);
return 1;
}
fprintf(stderr, "Successfully opened %s.\n", dbpath);
int i;
for (i = 2; i < argc; i++) {
uint32_t word_id = get_word_id(cdb, argv[i]);
if (word_id == 0) {
fprintf(stderr, "Word \"%s\" not found in the database.\n", argv[i]);
continue;
}
printf("printing collocators of \"%s\" as json:\n", argv[i]);
printf("%s\n", get_collocators_as_json(cdb, word_id));
}
return 0;
}