[sword-svn] r3677 - trunk/utilities

scribe at crosswire.org scribe at crosswire.org
Sat Nov 23 10:52:30 MST 2019


Author: scribe
Date: 2019-11-23 10:52:29 -0700 (Sat, 23 Nov 2019)
New Revision: 3677

Modified:
   trunk/utilities/imp2vs.cpp
   trunk/utilities/osis2mod.cpp
Log:
updated imp2vs to include logic from osis2mod to append verses outside of v11n scheme

Modified: trunk/utilities/imp2vs.cpp
===================================================================
--- trunk/utilities/imp2vs.cpp	2019-10-30 23:10:56 UTC (rev 3676)
+++ trunk/utilities/imp2vs.cpp	2019-11-23 17:52:29 UTC (rev 3677)
@@ -20,6 +20,8 @@
  *
  */
 
+int       debug            =   0; // mask of debug flags
+const int DEBUG_REV11N     =  64; // versification
 #ifdef _MSC_VER
 	#pragma warning( disable: 4251 )
 #endif
@@ -53,6 +55,8 @@
 using namespace std;
 
 void writeEntry(SWModule *module, const SWBuf &key, const SWBuf &entry, bool replace);
+void makeValidRef(VerseKey &key, SWModule *module);
+bool isValidRef(const char *v11n, const char *buf, const char *caller);
 
 void usage(const char *progName, const char *error = 0) {
 	if (error) fprintf(stderr, "\n%s: %s\n", progName, error);
@@ -104,7 +108,7 @@
 	SWBuf v11n	     = "KJV";
 	SWBuf outPath	  = "./";
 	SWBuf locale	       = "en";
-	
+
 	bool fourByteSize      = false;
 	bool append	    = false;
 	bool replace	    = false;
@@ -242,14 +246,14 @@
 		module->addRawFilter(cipherFilter);
 	}
 	// -----------------------------------------------------
-	
+
 	// setup locale manager
-	
+
 	LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale);
 			
 
 	// setup module key to allow full range of possible values, and then some
-	
+
 	VerseKey *vkey = (VerseKey *)module->createKey();
 	vkey->setIntros(true);
 	vkey->setAutoNormalize(false);
@@ -303,8 +307,9 @@
 int page = 0;
 
 
-void writeEntry(SWModule *module, const SWBuf &key, const SWBuf &entry, bool replace)
+void writeEntry(SWModule *module, const SWBuf &key, const SWBuf &origEntry, bool replace)
 {
+	SWBuf entry = origEntry;
 	if (key.size() && entry.size()) {
 		std::cout << "from file: " << key << std::endl;
 		VerseKey *vkey = (VerseKey *)module->getKey();
@@ -312,12 +317,25 @@
 
 		ListKey listKey = vkey->parseVerseList(key.c_str(), "Gen1:1", true);
 
+		static VerseKey lastKey;
+		lastKey.setVersificationSystem(vkey->getVersificationSystem());
+		lastKey.setAutoNormalize(0);
+		lastKey.setIntros(1);
+
 		bool first = true;
 		for (listKey = TOP; !listKey.popError(); listKey++) {
-			*vkey = listKey;
+			lastKey = listKey;
+			SWBuf lameMergeVerseMarker = "";
+			if (!isValidRef(vkey->getVersificationSystem(), lastKey, "writeEntry")) {
+				lameMergeVerseMarker = SWBuf(" (") + lastKey.getShortText() + ") ";
+				makeValidRef(lastKey, module);
+			}
+			*vkey = lastKey;
 			if (first) {
 				*linkMaster = *vkey;
 				SWBuf text = (replace) ? "" : module->getRawEntry();
+				// only add lame verse marker once, in case we append
+				if (lameMergeVerseMarker.size() && text.indexOf(lameMergeVerseMarker) < 0) text += lameMergeVerseMarker;
 				text += entry;
 
 
@@ -364,3 +382,118 @@
 		delete linkMaster;
 	}
 }
+
+/**
+ * This routine is used to ensure that all the text in the input is saved to the module.
+ * Assumption: The input orders all the verses for a chapter in numerical order. Thus, any
+ * verses that are not in the chosen versification (v11n) follow those that are.
+ *
+ * The prior implementation of this adjusted the verse to the last one that is in the chosen v11n.
+ * If it the chapter were extra, then it is appended to the last verse of the last
+ * chapter in the chosen v11n for that book. If it is just extra verses for a chapter, then it is
+ * appended to the last verse of the chapter.
+ *
+ * The problem with this is when a OSIS verse refers to more than one verse, e.g.
+ * osisID="Gen.1.29 Gen.1.30 Gen.1.31" (Gen.1.31 is the last verse of the chapter in the chosen v11n)
+ * and then it is followed by Gen.1.32.
+ *
+ * This routine assumes that linking is postponed to the end so that in the example Gen.1.30-31
+ * are not linked but rather empty. This routine will then find the last verse in the computed
+ * chapter that has content.
+ *
+ * Alternative, we could have done linking as we went, but this routine would have needed
+ * to find the first entry in the link set and elsewhere in the code when appending to a
+ * verse, it would need to be checked for adjacent links and those would have needed to be adjusted.
+ *
+ * param key the key that may need to be adjusted
+ */
+void makeValidRef(VerseKey &key, SWModule *module) {
+	VerseKey saveKey;
+	saveKey.setVersificationSystem(key.getVersificationSystem());
+	saveKey.setAutoNormalize(false);
+	saveKey.setIntros(true);
+	saveKey = key;
+
+	// Since isValidRef returned false constrain the key to the nearest prior reference.
+	// If we are past the last chapter set the reference to the last chapter
+	int chapterMax = key.getChapterMax();
+	if (key.getChapter() > chapterMax) {
+		key.setChapter(chapterMax);
+	}
+
+	// Either we set the chapter to the last chapter and now need to set to the last verse in the chapter
+	// Or the verse is beyond the end of the chapter.
+	// In any case we need to constrain the verse to it's chapter.
+	int verseMax   = key.getVerseMax();
+	key.setVerse(verseMax);
+
+	if (debug & DEBUG_REV11N) {
+		cout << "DEBUG(V11N) Chapter max:" << chapterMax << ", Verse Max:" << verseMax << endl;
+	}
+
+	// There are three cases we want to handle:
+	// In the examples we are using the KJV versification where the last verse of Matt.7 is Matt.7.29.
+	// In each of these cases the out-of-versification, extra verse is Matt.7.30.
+	// 1) The "extra" verse follows the last verse in the chapter.
+	//      <verse osisID="Matt.7.29">...</verse><verse osisID="Matt.7.30">...</verse>
+	//    In this case re-versify Matt.7.30 as Matt.7.29.
+	//
+	// 2) The "extra" verse follows a range (a set of linked verses).
+	//      <verse osisID="Matt.7.28-Matt.7.29">...</verse><verse osisID="Matt.7.30">...</verse>
+	//    In this case, re-versify Matt.7.30 as Matt.7.28, the first verse in the linked set.
+	//    Since we are post-poning linking, we want to re-reversify to the last entry in the module.
+	//
+	// 3) The last verse in the chapter is not in the input. There may be other verses missing as well.
+	//      <verse osisID="Matt.7.8">...</verse><verse osisID="Matt.7.30">...</verse>
+	//    In this case we should re-versify Matt.7.30 as Matt.7.29.
+	//    However, since this and 2) are ambiguous, we'll re-reversify to the last entry in the module.
+
+	while (!key.popError() && !module->hasEntry(&key)) {
+		key.decrement(1);
+	}
+
+	cout << "INFO(V11N): " << saveKey.getOSISRef()
+	     << " is not in the " << key.getVersificationSystem()
+	     << " versification. Appending content to " << key.getOSISRef() << endl;
+}
+
+/**
+ * Determine whether a verse as given is valid for the versification.
+ * This is done by comparing the before and after of normalization.
+ */
+bool isValidRef(const char *v11n, const char *buf, const char *caller) {
+	// Create a VerseKey that does not do auto normalization
+	// Note: need to turn on headings so that a heading does not get normalized anyway
+	// And set it to the reference under question
+	VerseKey before;
+	before.setVersificationSystem(v11n);
+	before.setAutoNormalize(false);
+	before.setIntros(true);
+	before.setText(buf);
+
+	// If we are a heading we must bail
+	// These will autonormalize to the last verse of the prior chapter
+	if (!before.getTestament() || !before.getBook() || !before.getChapter() || !before.getVerse()) {
+		return true;
+	}
+
+	// Create a VerseKey that does do auto normalization
+	// And set it to the reference under question
+	VerseKey after;
+	after.setVersificationSystem(v11n);
+	after.setAutoNormalize(true);
+	after.setText(buf);
+
+	if (before == after)
+	{
+		return true;
+	}
+
+	// If we have gotten here the reference is not in the selected versification.
+	// cout << "INFO(V11N): " << before << " is not in the " << currentVerse.getVersificationSystem() << " versification." << endl;
+	if (debug & DEBUG_REV11N) {
+		cout << "DEBUG(V11N)[" << caller << "]: " << before << " normalizes to "  << after << endl;
+	}
+
+	return false;
+}

Modified: trunk/utilities/osis2mod.cpp
===================================================================
--- trunk/utilities/osis2mod.cpp	2019-10-30 23:10:56 UTC (rev 3676)
+++ trunk/utilities/osis2mod.cpp	2019-11-23 17:52:29 UTC (rev 3677)
@@ -391,8 +391,7 @@
 	after.setAutoNormalize(true);
 	after.setText(buf);
 
-	if (before == after)
-	{
+	if (before == after) {
 		return true;
 	}
 




More information about the sword-cvs mailing list