24#include <QtCore/QProcess>
33namespace LinguisticProcessing {
58 LDEBUG <<
"Initialization";
67 LERROR <<
"Missing 'dumper' parameter in ExternalProcessUnit group for language "
68 << (int)language <<
" !";
81 LERROR <<
"Missing 'loader' parameter in ExternalProcessUnit group for language "
82 << (int)language <<
" !";
87 m_inputSuffix=QString::fromUtf8(unitConfiguration.
getParamsValueAtKey(
"inputSuffix").c_str());
94 m_outputSuffix=QString::fromUtf8(unitConfiguration.
getParamsValueAtKey(
"outputSuffix").c_str());
104 LERROR <<
"Missing 'command' parameter in ExternalProcessUnit group for language "
105 << (int)language <<
" !";
114 LINFO <<
"ExternalProcessUnit: start";
116 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
118 LERROR <<
"no LinguisticMetaData ! abort";
125 LDEBUG <<
"ExternalProcessUnit: write tmp file";
126 returnCode=m_dumper->process(analysis);
128 LERROR <<
"ExternalProcessUnit: failed to dump data to temporary file";
132 QString fileName = QString::fromUtf8(metadata->getMetaData(
"FileName").c_str());
133 QString inputFilename, outputFilename;
135 LDEBUG <<
"ExternalProcessUnit: apply external program";
136 QString commandLine = m_commandLine;
137 if (!m_inputSuffix.isEmpty())
139 inputFilename = fileName+ m_inputSuffix;
141 if (!m_outputSuffix.isEmpty())
143 outputFilename = fileName + m_outputSuffix;
145 commandLine = commandLine.arg(inputFilename, outputFilename);
146 auto args = commandLine.split(
" ");
147 auto command = args.front();
149 LDEBUG <<
"Launching " << commandLine;
150 int processResult = QProcess::execute(command, args);
151 switch (processResult) {
153 LERROR <<
"ExternalProcessUnit: Was not able to start '" << commandLine <<
"'" ;
156 LERROR <<
"ExternalProcessUnit: '" << commandLine <<
"' crashed!";
161 LERROR <<
"ExternalProcessUnit: '" << commandLine <<
"' returned error status:" << processResult;
167 LDEBUG <<
"ExternalProcessUnit: read results";
168 returnCode=m_loader->process(analysis);
170 LERROR <<
"ExternalProcessUnit: failed to load data from temporary file";
175 LWARN <<
"ExternalProcessUnit: no loader defined for the current external process unit";
This file is the main header file for the data related to annotation graphs.
#define EXTERNALPROCESSUNIT_CLASSID
Defines a Factory to create Object of type Base.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
Use this exception to signal an error in one of the configuration files.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
virtual ~ExternalProcessUnit()
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual std::shared_ptr< Object > getObject(const std::string &id)
If object doesn't exists, call the create method.
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
SimpleFactory< MediaProcessUnit, ExternalProcessUnit > ExternalProcessUnitFactory(EXTERNALPROCESSUNIT_CLASSID)
launch exception related to the configuration file parsing