about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-08-20 14:06:12 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-08-20 14:06:12 -0400
commitaeee9782b8331c93e4665663e9e759188197074e (patch)
treeee050993e1a572c9453813b0122918e9c430ef66
parentc132dc01c600349ffe5c8ec8622b5393451b3db8 (diff)
downloadrawr-ebooks-aeee9782b8331c93e4665663e9e759188197074e.tar.gz
rawr-ebooks-aeee9782b8331c93e4665663e9e759188197074e.tar.bz2
rawr-ebooks-aeee9782b8331c93e4665663e9e759188197074e.zip
Marked rawr::randomSentence const
-rw-r--r--kgramstats.cpp6
-rw-r--r--kgramstats.h2
2 files changed, 4 insertions, 4 deletions
diff --git a/kgramstats.cpp b/kgramstats.cpp index cb63db6..f171be9 100644 --- a/kgramstats.cpp +++ b/kgramstats.cpp
@@ -553,7 +553,7 @@ void rawr::setMinCorpora(int _arg)
553} 553}
554 554
555// runs in O(n log t) time where n is the input number of sentences and t is the number of tokens in the input corpus 555// runs in O(n log t) time where n is the input number of sentences and t is the number of tokens in the input corpus
556std::string rawr::randomSentence(int maxL) 556std::string rawr::randomSentence(int maxL) const
557{ 557{
558 if (!_compiled) 558 if (!_compiled)
559 { 559 {
@@ -597,10 +597,10 @@ std::string rawr::randomSentence(int maxL)
597 cur = kgram(1, wildcardQuery); 597 cur = kgram(1, wildcardQuery);
598 } 598 }
599 599
600 auto& distribution = _stats[cur]; 600 auto& distribution = _stats.at(cur);
601 int max = distribution.rbegin()->first; 601 int max = distribution.rbegin()->first;
602 int r = rand() % max; 602 int r = rand() % max;
603 token_data& next = distribution.upper_bound(r)->second; 603 const token_data& next = distribution.upper_bound(r)->second;
604 std::string nextToken = next.tok.w.forms.next(); 604 std::string nextToken = next.tok.w.forms.next();
605 605
606 // Apply user-specified transforms 606 // Apply user-specified transforms
diff --git a/kgramstats.h b/kgramstats.h index d939ade..2ee0e35 100644 --- a/kgramstats.h +++ b/kgramstats.h
@@ -18,7 +18,7 @@ class rawr {
18 18
19 void setTransformCallback(transform_callback _arg); 19 void setTransformCallback(transform_callback _arg);
20 void setMinCorpora(int _arg); 20 void setMinCorpora(int _arg);
21 std::string randomSentence(int maxL); 21 std::string randomSentence(int maxL) const;
22 22
23 private: 23 private:
24 struct terminator { 24 struct terminator {