diff options
Diffstat (limited to 'flashtools/flash.cpp')
-rw-r--r-- | flashtools/flash.cpp | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/flashtools/flash.cpp b/flashtools/flash.cpp index ca8bada..eedc959 100644 --- a/flashtools/flash.cpp +++ b/flashtools/flash.cpp @@ -2,31 +2,33 @@ #include <vector> #include <iostream> #include <sstream> +#include <fstream> #include <swmgr.h> #include <swbuf.h> #include <swmodule.h> #include <utf8utf16.h> #include <versekey.h> +#include <thmlplain.h> using namespace sword; using namespace std; class Word { public: -Word() - : utf8("") - , strong(0) - , freq(0) - , kjvTrans("") -{} -SWBuf utf8; -int strong; -int freq; -// from stongs lex -SWBuf kjvTrans; -// computed ourselves -map<SWBuf, int> kjvFreq; + Word() + : utf8("") + , strong(0) + , freq(0) + , kjvTrans("") + {} + SWBuf utf8; + int strong; + int freq; + // from stongs lex + SWBuf kjvTrans; + // computed ourselves + map<SWBuf, int> kjvFreq; }; string itoa(int v) { stringstream str; str << v; return str.str(); } @@ -44,7 +46,7 @@ SWBuf prettyKJVFreq(map<SWBuf, int> &in) { vector<map<SWBuf, int>::const_iterator> sorted; for (map<SWBuf, int>::const_iterator it = in.begin(); it != in.end(); it++) { // combine cap words with lowercase, if exists - if (toupper(it->first[0]) == it->first[0]) { + if (toupper(it->first[0]) == it->first[0] && it->first != "God" && it->first != "Lord") { SWBuf key = it->first; key[0] = tolower(key[0]); if (key != it->first) { @@ -86,16 +88,79 @@ SWBuf escapedUTF8(SWBuf inText) { } +void outputCSV(vector<Word *> &wordList) { + for (vector<Word *>::iterator it = wordList.begin(); it != wordList.end(); it++) { + Word *w = (*it); +// cout << w->freq << "|" << escapedUTF8(w->utf8).c_str() << "|" << w->strong << "|" << prettyKJVFreq(w->kjvFreq).c_str() << "\n"; + cout << w->freq << "|" << w->utf8.c_str() << "|" << w->strong << "|" << prettyKJVFreq(w->kjvFreq).c_str() << "|" << w->kjvTrans << "\n"; + } + std::cout << std::endl; +} + + +void outputFlash(vector<Word *> &wordList, int maxPerLesson) { + ThMLPlain strip; + ofstream ofile; + int wordCount = 0; + int lessonNumber = 0; + int startFreq = 0; + int lastFreq = 0; + + vector<Word *>::iterator it = wordList.begin(); + while (it != wordList.end()) { + Word *w = (*it); + if (!wordCount) { + SWBuf fname = "lesson"; + fname.appendFormatted("%d", lessonNumber); + fname += ".flash"; + ofile.open(fname); + startFreq = w->freq; + } + + // use if you want answers as KJV phrases + SWBuf answers = prettyKJVFreq(w->kjvFreq); + if (answers.size() > 200) answers.size(200); + + // use if you would rather have short strongs +// SWBuf answers = w->kjvTrans; +// strip.processText(answers); // remove html tags +// answers.replaceBytes("\n\r", ' '); // remove newlines + + // be sure we have both a word and an answer + if (w->utf8.trim().size() && answers.trim().size()) { + ofile << "word" << wordCount << "=" << escapedUTF8(w->utf8) << "\n"; + ofile << "answers" << wordCount << "=" << answers << "\n"; + lastFreq = w->freq; + wordCount++; + } + + it++; + + if (it == wordList.end() || wordCount >= maxPerLesson) { + // close lesson + SWBuf lessonTitle = ""; + lessonTitle.appendFormatted("lessonTitle=%.3d Freqs. %d-%d\n", lessonNumber, startFreq, lastFreq); + ofile << lessonTitle; + ofile << "wordCount=" << wordCount << "\n"; + ofile.close(); + wordCount = 0; + lessonNumber++; + } + } +} + + int main(int argc, char **argv) { SWMgr manager; - SWModule *bible; - SWConfig utf8("hwords.conf"); - SWConfig defs("hdefs.conf"); + SWModule *bible = manager.getModule("KJV"); map<int, Word> wordList; - bible = manager.getModule("KJV"); + SWConfig utf8("hwords.conf"); + SWConfig defs("hdefs.conf"); +// SWConfig utf8("gwords.conf"); +// SWConfig defs("gdefs.conf"); for (bible->setKey("gen.1.1"); ((VerseKey*)bible->getKey())->Testament() == 1; (*bible)++) { // for (bible->setKey("mat.1.1"); !bible->Error(); (*bible)++) { @@ -129,13 +194,8 @@ int main(int argc, char **argv) } sort(sorted.begin(), sorted.end(), compareFreq); +// outputCSV(sorted); + outputFlash(sorted, 25); return 0; } -void outputCSV(Vector<Word *>wordList) { - for (vector<Word *>::iterator it = wordList.begin(); it != wordList.end(); it++) { - Word *w = (*it); -// cout << w->freq << "|" << escapedUTF8(w->utf8).c_str() << "|" << w->strong << "|" << prettyKJVFreq(w->kjvFreq).c_str() << "\n"; - cout << w->freq << "|" << w->utf8.c_str() << "|" << w->strong << "|" << prettyKJVFreq(w->kjvFreq).c_str() << "|" << w->kjvTrans << "\n"; - } - std::cout << std::endl; -} + |