29
29
#else
30
30
#include < QtGui/QApplication>
31
31
#endif
32
+ #include < QTimer>
32
33
#include " ../crengine/include/crengine.h"
33
34
#include " ../crengine/include/cr3version.h"
34
35
#include " mainwindow.h"
@@ -77,6 +78,18 @@ static void printHelp() {
77
78
" -v or --version: print program version\n "
78
79
" --loglevel=ERROR|WARN|INFO|DEBUG|TRACE: set logging level\n "
79
80
" --logfile=<filename>|stdout|stderr: set log file\n "
81
+ " \n "
82
+ " --get-sentence-info|-s INPUT_FILE_NAME OUTPUT_FILE_NAME\n "
83
+ " analyze INPUT_FILE_NAME and write sentence structure info to OUTPUT_FILE_NAME\n "
84
+ " -one sentence per line, formatted: START_POS,TEXT\n "
85
+ " -every word appears in exactly one sentence\n "
86
+ " -not every character appears; all newlines are omitted, and some whitespace\n "
87
+ " -START_POS is a UTF8-encoded string representing a unique position in the DOM of the first word\n "
88
+ " -START_POS never contains a comma\n "
89
+ " -e.g.: /body/DocFragment[3]/body/div/div[4]/p/a/text()[1].3\n "
90
+ " -TEXT is the full UTF8-encoded text of the sentence, without quotes or escaping\n "
91
+ " -TEXT never contains newline characters\n "
92
+ " -TEXT can contain commas, double quotes, and single quotes\n "
80
93
);
81
94
}
82
95
@@ -95,6 +108,9 @@ int main(int argc, char *argv[])
95
108
lString8 loglevel (" ERROR" );
96
109
lString8 logfile (" stderr" );
97
110
#endif
111
+ bool exportSentenceInfo = false ;
112
+ QString exportSentenceInfoInputFileName;
113
+ QString exportSentenceInfoOutputFileName;
98
114
for ( int i=1 ; i<argc; i++ ) {
99
115
if ( !strcmp (" -h" , argv[i]) || !strcmp (" -?" , argv[i]) || !strcmp (" /?" , argv[i]) || !strcmp (" --help" , argv[i]) ) {
100
116
printHelp ();
@@ -119,6 +135,16 @@ int main(int argc, char *argv[])
119
135
fclose (out);
120
136
return 0 ;
121
137
}
138
+ if ( !strcmp (" -s" , argv[i]) || !strcmp (" --get-sentence-info" , argv[i])) {
139
+ if (i<argc-2 ){
140
+ exportSentenceInfo = true ;
141
+ exportSentenceInfoInputFileName = QString (argv[++i]);
142
+ exportSentenceInfoOutputFileName = QString (argv[++i]);
143
+ }else {
144
+ printf (" ERROR: missing input/output filename args to --get-sentence-info\n " );
145
+ return 1 ;
146
+ }
147
+ }
122
148
lString8 s (argv[i]);
123
149
if ( s.startsWith (cs8 (" --loglevel=" )) ) {
124
150
loglevel = s.substr (11 , s.length ()-11 );
@@ -223,7 +249,15 @@ int main(int argc, char *argv[])
223
249
else
224
250
CRLog::error (" Canot load translation file %s from dir %s" , UnicodeToUtf8 (qt2cr (trname)).c_str (), UnicodeToUtf8 (qt2cr (translations)).c_str () );
225
251
MainWindow w;
226
- w.show ();
252
+ if (exportSentenceInfo){
253
+ // run w.exportSentenceInfo() as soon as possible in event loop, and then quit
254
+ QTimer::singleShot (0 , NULL , [&w, exportSentenceInfoInputFileName, exportSentenceInfoOutputFileName] () {
255
+ w.exportSentenceInfo (exportSentenceInfoInputFileName, exportSentenceInfoOutputFileName);
256
+ qApp->quit ();
257
+ });
258
+ }else {
259
+ w.show ();
260
+ }
227
261
res = a.exec ();
228
262
}
229
263
}
0 commit comments