Add first tests
Change-Id: I7ef95cef912feb2b997e1c7da5eb5a369cbe56b1
diff --git a/src/collocatordb.cc b/src/collocatordb.cc
index eef1860..52cbc27 100644
--- a/src/collocatordb.cc
+++ b/src/collocatordb.cc
@@ -858,15 +858,27 @@
db->dump(w1, w2, dist);
}
- Collocator *get_collocators(COLLOCATORS *db, uint32_t w1) {
- return &db->get_collocators(w1)[0];
+ COLLOCATORS *get_collocators(COLLOCATORS *db, uint32_t w1) {
+ std::vector<Collocator> c = db->get_collocators(w1);
+ if (c.empty())
+ return NULL;
+ uint64_t size = c.size() + sizeof c[0];
+ COLLOCATORS *p = (COLLOCATORS *) malloc(size);
+ memcpy(p, c.data(), size);
+ return p;
}
- Collocator *get_collocation_scores(COLLOCATORS *db, uint32_t w1, uint32_t w2) {
- return &db->get_collocation_scores(w1, w2)[0];
+ COLLOCATORS *get_collocation_scores(COLLOCATORS *db, uint32_t w1, uint32_t w2) {
+ std::vector<Collocator> c = db->get_collocation_scores(w1, w2);
+ if (c.empty())
+ return NULL;
+ uint64_t size = c.size() + sizeof c[0];
+ COLLOCATORS *p = (COLLOCATORS *) malloc(size);
+ memcpy(p, c.data(), size);
+ return p;
}
- const char *get_word(COLLOCATORS *db, uint32_t w) {
+ char *get_word(COLLOCATORS *db, uint32_t w) {
return strdup(db->getWord(w).c_str());
}
diff --git a/src/collocatordb.h b/src/collocatordb.h
index 4e1d412..7b9b3f5 100644
--- a/src/collocatordb.h
+++ b/src/collocatordb.h
@@ -86,33 +86,34 @@
#else
typedef struct COLLOCATORDB COLLOCATORDB;
-typedef struct {
- uint32_t w2;
- uint64_t f2;
- uint64_t raw;
- double pmi;
- double npmi;
- double llr;
- double lfmd;
- double md;
- uint64_t left_raw;
- uint64_t right_raw;
- double left_pmi;
- double right_pmi;
- double dice;
- double logdice;
- double ldaf;
- int window;
- int af_window;
-} Collocator ;
#endif
+typedef struct {
+ uint32_t w2;
+ uint64_t f2;
+ uint64_t raw;
+ double pmi;
+ double npmi;
+ double llr;
+ double lfmd;
+ double md;
+ uint64_t left_raw;
+ uint64_t right_raw;
+ double left_pmi;
+ double right_pmi;
+ double dice;
+ double logdice;
+ double ldaf;
+ int window;
+ int af_window;
+} COLLOCATOR ;
+
extern COLLOCATORDB *open_collocatordb(const char *s);
extern COLLOCATORDB *open_collocatordb_for_write(const char *s);
extern void inc_collocator(COLLOCATORDB *db, uint64_t w1, uint64_t w2, int8_t dist);
extern void dump_collocators(COLLOCATORDB *db, uint32_t w1, uint32_t w2, int8_t dist);
-extern Collocator *get_collocators(COLLOCATORDB *db, uint32_t w1);
-extern Collocator *get_collocation_scores(COLLOCATORDB *db, uint32_t w1, uint32_t w2);
+extern COLLOCATOR *get_collocators(COLLOCATORDB *db, uint32_t w1);
+extern COLLOCATOR *get_collocation_scores(COLLOCATORDB *db, uint32_t w1, uint32_t w2);
extern char *get_collocators_as_json(COLLOCATORDB *db, uint32_t w1);
extern char *get_collocation_scores_as_json(COLLOCATORDB *db, uint32_t w1, uint32_t w2);
extern char *get_word(COLLOCATORDB *db, uint32_t w1);