1. Lars Yencken
  2. gpalign-cpp

Commits

Lars Yencken  committed 5b46acc

[242] Added logging of overconstrained input.

  • Participants
  • Parent commits 1abe273
  • Branches default

Comments (0)

Files changed (3)

File src/scripts.cpp

View file
 }
 
 //--------------------------------------------------------------------------//
+
+unsigned int kanjiLen(const wstring& s)
+{
+    unsigned int len = 0;
+    for (wstring::const_iterator c = s.begin(); c != s.end(); c++) {
+        if (scriptType(*c) == Script__Kanji) {
+            len++;
+        }
+    }
+    return len;
+}
+
+//--------------------------------------------------------------------------//

File src/scripts.hpp

View file
  */
 unsigned int bigKanaLen(const wstring& s);
 
+/**
+ * Returns the number of kanji in the string.
+ */
+unsigned int kanjiLen(const wstring& s);
+
 //--------------------------------------------------------------------------//
 
 #endif 

File src/tfIdfAligner.cpp

View file
 #include <algorithm>
 #include <iostream>
 #include <sstream>
+#include <fstream>
+#include <stdexcept>
 
 //--------------------------------------------------------------------------//
 
     const int nSegments = segments.size();
     int nSolved = 0;
     int nFailed = 0;
+    wofstream output;
+    output.open("errors.log");
+#ifndef DARWIN
+    output.imbue(locale(g_locale));
+#endif
+
+    if (!output.good()) {
+        throw runtime_error("Can't open errors.log for writing");
+    }
     for (int i = 0; i < nSegments; i++) {
         const Segment& seg = segments[i];
-        if (bigKanaLen(seg.g) > 5) {
+        if (kanjiLen(seg.g) > 5) {
+            output << seg << L" (too long)" << endl;
             nFailed++;
             continue;
         }
                 alignmentClouds.push_back(cloud);
             }
         } else {
+            output << seg << L" (no valid alignments)" << endl;
             nFailed++;
         }
     }
+    output.close();
     wcout << L"--> " << nSolved << L" uniquely determined" << endl;
-    wcout << L"--> " << nFailed << L" overconstrained" << endl;
+    wcout << L"--> " << nFailed << L" overconstrained, written to errors.log"
+            << endl;
 
     wcout << L"Disambiguating clouds" << endl;
     ProgressBar progress;