[sword-svn] r94 - trunk/flashtools

scribe at www.crosswire.org scribe at www.crosswire.org
Fri Aug 31 00:41:49 MST 2007


Author: scribe
Date: 2007-08-31 00:41:49 -0700 (Fri, 31 Aug 2007)
New Revision: 94

Modified:
   trunk/flashtools/flash.cpp
Log:
updated to produce flashcard lessons


Modified: trunk/flashtools/flash.cpp
===================================================================
--- trunk/flashtools/flash.cpp	2007-08-02 08:34:39 UTC (rev 93)
+++ trunk/flashtools/flash.cpp	2007-08-31 07:41:49 UTC (rev 94)
@@ -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 @@
 	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,17 +88,80 @@
 }
 
 
+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;
+	SWModule *bible = manager.getModule("KJV");
+	map<int, Word> wordList;
+
 	SWConfig utf8("hwords.conf");
 	SWConfig defs("hdefs.conf");
-	map<int, Word> wordList;
+//	SWConfig utf8("gwords.conf");
+//	SWConfig defs("gdefs.conf");
 
-	bible = manager.getModule("KJV");
-
 	for (bible->setKey("gen.1.1"); ((VerseKey*)bible->getKey())->Testament() == 1; (*bible)++) {
 //	for (bible->setKey("mat.1.1"); !bible->Error(); (*bible)++) {
 		bible->RenderText();		// force an entry lookup to resolve key to something in the index
@@ -129,13 +194,8 @@
 	}
 	
 	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;
-}
+




More information about the sword-cvs mailing list