Lars Yencken avatar Lars Yencken committed 5b46acc

[242] Added logging of overconstrained input.

Comments (0)

Files changed (3)

 }
 
 //--------------------------------------------------------------------------//
+
+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;
+}
+
+//--------------------------------------------------------------------------//
  */
 unsigned int bigKanaLen(const wstring& s);
 
+/**
+ * Returns the number of kanji in the string.
+ */
+unsigned int kanjiLen(const wstring& s);
+
 //--------------------------------------------------------------------------//
 
 #endif 

src/tfIdfAligner.cpp

 #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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.