kgrams  0.1.0
DictionaryR.h
1 #ifndef DICTIONARY_R_H
2 #define DICTIONARY_R_H
3 
4 #include "Dictionary.h"
5 #include <queue>
6 #include <algorithm>
7 #include <Rcpp.h>
8 using namespace Rcpp;
9 
10 
11 
12 class DictionaryR : public Dictionary {
13  struct WordCount {
14  std::string word;
15  size_t count;
16  WordCount (std::string w, size_t c) : word(w), count(c) {}
17  WordCount & operator++() { count++; return *this; }
18  friend bool operator< (const WordCount & l, const WordCount & r)
19  {
20  if (l.count != r.count) return l.count < r.count;
21  else return l.word > r.word;
22  }
23  };
24 
25  double make_word_heap(Rcpp::CharacterVector, std::vector<WordCount> &);
26 
27 public:
28  DictionaryR () : Dictionary() {}
29  DictionaryR (CharacterVector word_list)
30  : Dictionary() { insert(word_list); }
31  DictionaryR (kgramFreqs & f) : Dictionary(f) {}
32 
33  LogicalVector query(CharacterVector word) const;
34 
35  void insert (CharacterVector word_list);
36  void insert_cover(Rcpp::CharacterVector text, double target);
37  void insert_n(Rcpp::CharacterVector text, size_t n);
38  void insert_above(Rcpp::CharacterVector text, size_t thresh);
39 };
40 
41 #endif
Dictionary
Word dictionary for language models.
Definition: Dictionary.h:22
Dictionary.h
Definition of Dictionary class.
DictionaryR
Definition: DictionaryR.h:12
kgramFreqs
Store k-gram frequency counts in hash tables
Definition: kgramFreqs.h:20