Fix include file for c++
Change-Id: Ib8c2960f276107f7fe5dbf1699ff5b20f1315166
diff --git a/src/collocatordb.h b/src/collocatordb.h
index af97419..0eed8d8 100644
--- a/src/collocatordb.h
+++ b/src/collocatordb.h
@@ -12,29 +12,9 @@
#ifdef __cplusplus
namespace rocksdb {
- class Collocator {
- public:
- uint64_t w2;
- uint64_t f2;
- uint64_t raw;
- double pmi;
- double npmi;
- double llr;
- double lfmd;
- double md;
- double left_lfmd;
- double right_lfmd;
- double left_npmi;
- double right_npmi;
- double dice;
- double logdice;
- double ldaf;
- int window;
- int af_window;
- };
-namespace rocksdb {
- class Collocator {
- public:
+
+class Collocator {
+public:
uint32_t w2;
uint64_t f2;
uint64_t raw;
@@ -52,41 +32,70 @@
double ldaf;
int window;
int af_window;
- };
+};
- class CollocatorIterator : public Iterator {
- public:
- CollocatorIterator(const Iterator& it);
- void SeekToFirst();
- void SeekToLast();
- void Seek(const rocksdb::Slice&);
- void Prev();
- bool isValid();
- uint64_t intValue();
- uint64_t intKey();
- };
-
- extern "C" {
- class CollocatorDB {
- public:
- std::string getWord(uint32_t w1);
- std::vector<Collocator> get_collocators(uint32_t w1);
- std::vector<Collocator> get_collocators(uint32_t w1, uint32_t max_w2);
- void dumpSparseLlr(uint32_t w1, uint32_t min_cooccur);
- CollocatorDB(const char *db_name, const bool read_only);
- void inc(const uint32_t w1, const uint32_t w2, const uint8_t dist);
- void dump(const uint32_t w1, const uint32_t w2, const uint8_t dist);
- CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
- };
-
- }
-}
+class CollocatorIterator : public rocksdb::Iterator {
+public:
+ CollocatorIterator(rocksdb::Iterator* base_iterator);
+ void setPrefix(char* prefix);
+ void SeekToFirst() override;
+ void SeekToLast() override;
+ void Seek(const rocksdb::Slice& s) override;
+ void SeekForPrev(const rocksdb::Slice& s) override;
+ void Prev() override;
+ void Next() override;
+ rocksdb::Slice key() const override;
+ rocksdb::Slice value() const override;
+ rocksdb::Status status() const override;
+ bool Valid() const override;
+ bool isValid();
+ uint64_t intValue();
+ uint64_t intKey();
-typedef rocksdb::CollocatorDB COLLOCATORDB;
+private:
+ char prefixc[sizeof(uint64_t)];
+ rocksdb::Iterator* base_iterator_;
+};
+
+class CollocatorDB {
+public:
+ CollocatorDB(const char* db_name, bool read_only = false);
+ void readVocab(std::string fname);
+ std::string getWord(uint32_t w1);
+ void inc(const uint32_t w1, const uint32_t w2, const uint8_t dist);
+ void dump(uint32_t w1, uint32_t w2, int8_t dist);
+ std::vector<Collocator> get_collocators(uint32_t w1);
+ std::vector<Collocator> get_collocators(uint32_t w1, uint32_t max_w2);
+ std::vector<Collocator> get_collocation_scores(uint32_t w1, uint32_t w2);
+ std::vector<Collocator> get_collocators(uint32_t w1, uint32_t min_w2, uint32_t max_w2);
+ void dumpSparseLlr(uint32_t w1, uint32_t min_cooccur);
+ std::string collocators2json(uint32_t w1, std::vector<Collocator> collocators);
+ CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
+
+private:
+ std::shared_ptr<rocksdb::DB> OpenDb(const char* dbname);
+ std::shared_ptr<rocksdb::DB> OpenDbForRead(const char* dbname);
+ void applyCAMeasures(const uint32_t w1, const uint32_t w2, uint64_t* sumWindow, const uint64_t sum, const int usedPositions, int true_window_size, Collocator* result);
+
+ rocksdb::WriteOptions merge_option_;
+ char _one[sizeof(uint64_t)];
+ rocksdb::Slice _one_slice;
+ std::vector<Collocator> _vocab;
+ uint64_t total;
+ uint64_t sentences;
+ float avg_window_size;
+ std::shared_ptr<rocksdb::DB> db_;
+ rocksdb::WriteOptions put_option_;
+ rocksdb::ReadOptions get_option_;
+ rocksdb::WriteOptions delete_option_;
+ uint64_t default_;
+};
+
+} // namespace rocksdb
+
#else
typedef struct COLLOCATORDB COLLOCATORDB;
-#endif
typedef struct {
uint32_t w2;
@@ -119,3 +128,4 @@
extern char *get_word(COLLOCATORDB *db, uint32_t w1);
extern void read_vocab(COLLOCATORDB *db, char *fname);
extern char *get_version();
+#endif