Skip to content

Commit 40b9641

Browse files
committed
Catch LinguisticProcessing exceptions in analyzeText and analyzeXml
1 parent ae4b447 commit 40b9641

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

lima_linguisticprocessing/test/analyzeMultimediaXmlDocuments.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,23 @@ int run(int argc, char** argv)
450450

451451
// analyze
452452
metaData["FileName"] = fileName.toUtf8().constData();
453+
#ifndef DEBUG_LP
454+
try {
455+
#endif
453456
client->analyze(text_s, metaData, pipeline.toUtf8().constData());
457+
#ifndef DEBUG_LP
458+
}
459+
catch (const LinguisticProcessingException& e) {
460+
std::cerr << "LinguisticProcessing error on document " << fileName << ":" << e.what()
461+
<< std::endl;
462+
//allows the process to continue on next file
463+
}
464+
catch (const LimaException& e) {
465+
std::cerr << "Error on document " << fileName << ":" << e.what()
466+
<< std::endl;
467+
//allows the process to continue to next file
468+
}
469+
#endif
454470
client->releaseAnalysisHandler(handlerName);
455471
}
456472
catch(const NoSuchMap &e)

lima_linguisticprocessing/test/analyzeText.cpp

+51-6
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ int main(int argc, char **argv)
108108
return a.exec();
109109
#ifndef DEBUG_LP
110110
}
111-
catch( const InvalidConfiguration& e ) {
111+
catch( const InvalidConfiguration& e )
112+
{
112113
std::cerr << "Catched InvalidConfiguration: " << e.what() << std::endl;
113114
return UNSUPPORTED_LANGUAGE;
114115
}
@@ -447,6 +448,7 @@ int run(int argc, char** argv)
447448
std::cerr << "No file to analyze." << std::endl;
448449
}
449450

451+
450452
uint64_t nfile=0;
451453
for (const auto& file : files)
452454
{
@@ -521,14 +523,30 @@ int run(int argc, char** argv)
521523
<< " (" << percent.toUtf8().constData()
522524
<< "%) lines. At " << qfile.pos();
523525
}
524-
526+
#ifndef DEBUG_LP
527+
try {
528+
#endif
525529
// analyze it
526530
client->analyze(contentText,
527531
metaData,
528532
pipeline,
529533
handlers,
530534
inactiveUnits);
531-
535+
#ifndef DEBUG_LP
536+
}
537+
catch (const LinguisticProcessingException& e) {
538+
std::cerr << "LinguisticProcessing error on line " << lineNum << "["
539+
<< contentText.toStdString() << "]:" << e.what()
540+
<< std::endl;
541+
//allows the process to continue on next line
542+
}
543+
catch (const LimaException& e) {
544+
std::cerr << "Error on line " << lineNum << "["
545+
<< contentText.toStdString() << "]:" << e.what()
546+
<< std::endl;
547+
//allows the process to continue on next line
548+
}
549+
#endif
532550
}
533551
qfile.close();
534552
}
@@ -564,19 +582,30 @@ int run(int argc, char** argv)
564582
// analyze it with the proper offset
565583
paragraph.append("\n");
566584
paraMetaData["StartOffset"]=std::to_string(prevpos);
585+
#ifndef DEBUG_LP
567586
try {
587+
#endif
588+
// analyze it
568589
client->analyze(paragraph,
569590
paraMetaData,
570591
pipeline,
571592
handlers,
572593
inactiveUnits);
594+
#ifndef DEBUG_LP
595+
}
596+
catch (const LinguisticProcessingException& e) {
597+
std::cerr << "LinguisticProcessing error on paragraph " << numpar << "["
598+
<< paragraph.toStdString() << "]:" << e.what()
599+
<< std::endl;
600+
//allows the process to continue on next paragraph
573601
}
574-
catch (LimaException& e) {
602+
catch (const LimaException& e) {
575603
std::cerr << "Error on paragraph " << numpar << "["
576604
<< paragraph.toStdString() << "]:" << e.what()
577605
<< std::endl;
578606
//allows the process to continue on next paragraph
579607
}
608+
#endif
580609
}
581610
pos += sep.matchedLength();
582611
prevpos=pos;
@@ -601,8 +630,24 @@ int run(int argc, char** argv)
601630
TimeUtils::logElapsedTime("ReadInputFile");
602631
TimeUtils::updateCurrentTime();
603632

604-
// analyze it
605-
client->analyze(contentText, metaData, pipeline, handlers, inactiveUnits);
633+
#ifndef DEBUG_LP
634+
try {
635+
#endif
636+
// analyze it
637+
client->analyze(contentText, metaData, pipeline, handlers, inactiveUnits);
638+
#ifndef DEBUG_LP
639+
}
640+
catch (const LinguisticProcessingException& e) {
641+
std::cerr << "LinguisticProcessing error on document " << file << ":" << e.what()
642+
<< std::endl;
643+
//allows the process to continue on next file
644+
}
645+
catch (const LimaException& e) {
646+
std::cerr << "Error on document " << file << ":" << e.what()
647+
<< std::endl;
648+
//allows the process to continue to next file
649+
}
650+
#endif
606651
}
607652

608653
// Close and delete opened output files

0 commit comments

Comments
 (0)