Marc Kupietz | f08631e | 2024-11-21 18:05:07 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <math.h> |
| 5 | #include "../src/collocatordb.h" |
| 6 | |
| 7 | int main(int argc, char* argv[]) { |
| 8 | if (argc < 3) { |
| 9 | fprintf(stderr, "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n", argv[0]); |
| 10 | return 1; |
| 11 | } |
| 12 | |
| 13 | |
| 14 | |
| 15 | char *dbpath = argv[1]; |
| 16 | char *ext = strrchr(dbpath, '.'); |
| 17 | if (ext && strcmp(ext, ".rocksdb") == 0) { |
| 18 | *ext = '\0'; |
| 19 | } |
| 20 | |
| 21 | COLLOCATORDB *cdb; |
| 22 | |
| 23 | fprintf(stderr, "opening collocatordb for reading: %s ...\n", dbpath); |
| 24 | if (!(cdb = open_collocatordb(dbpath))) { |
| 25 | fprintf(stderr, "Error opening %s exiting.\n", dbpath); |
| 26 | return 1; |
| 27 | } |
| 28 | fprintf(stderr, "Successfully opened %s.\n", dbpath); |
| 29 | |
| 30 | int i; |
| 31 | for (i = 2; i < argc; i++) { |
| 32 | uint32_t word_id = get_word_id(cdb, argv[i]); |
| 33 | if (word_id == 0) { |
| 34 | fprintf(stderr, "Word \"%s\" not found in the database.\n", argv[i]); |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | printf("printing collocators of \"%s\" as json:\n", argv[i]); |
| 39 | printf("%s\n", get_collocators_as_json(cdb, word_id)); |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |