32#include <QRegularExpression>
47namespace LinguisticProcessing
49std::unique_ptr<CoreLinguisticProcessingClientFactory> CoreLinguisticProcessingClientFactory::s_instance=std::unique_ptr<CoreLinguisticProcessingClientFactory>(
new CoreLinguisticProcessingClientFactory());
65 const std::string& text,
66 const std::map<std::string,std::string>& metaData,
67 const std::string& pipelineId,
68 const std::map<std::string, AbstractAnalysisHandler*>& handlers,
69 const std::set<std::string>& inactiveUnits)
const
72 auto limatext = QString::fromStdString(text);
74 return analyze(limatext, metaData, pipelineId, handlers, inactiveUnits);
79 const std::map<std::string,std::string>& metaData,
80 const std::string& pipelineId,
81 const std::map<std::string, AbstractAnalysisHandler*>& handlers,
82 const std::set<std::string>& inactiveUnits)
const
90 QString whitespaceOnly(
"\\s*");
92 whitespaceOnly = QRegularExpression::anchoredPattern(whitespaceOnly);
93 auto analysis = std::make_shared<AnalysisContent>();
94 if (QRegularExpression(whitespaceOnly).match(text).hasMatch())
96 LWARN <<
"Empty text given to LIMA linguistic processing client. Nothing to do.";
102 analysis->setData(
"LinguisticMetaData",metadataholder);
106 analysis->setData(
"Text", lstexte);
108 LINFO <<
"CoreLinguisticProcessingClient::analyze(";
109 for(
auto attrIt = metaData.cbegin() ; attrIt != metaData.cend() ; attrIt++ ) {
110 LINFO <<
"attr:" << attrIt->first <<
"value:" << attrIt->second <<
", " ;
116 if (metaData.empty()) {
117 LDEBUG <<
"CoreLinguisticProcessingClient::analyze: no metadata";
120 for (
auto it=metaData.cbegin(), it_end=metaData.cend(); it!=it_end; it++)
122 if ((*it).first==
"date")
125 const auto& str = (*it).second;
126 auto i = str.find(
"T");
132 std::string date(str, 0, i);
133 auto docDate = QDate::fromString(date.c_str(),Qt::ISODate);
134 metadataholder->
setDate(
"document",docDate);
137 LDEBUG <<
"use '"<< date <<
"' as document date";
138 LDEBUG <<
"use boost'"<< docDate.day() <<
"/"<< docDate.month() <<
"/"<< docDate.year() <<
"' as document date";
141 catch (std::exception& e)
143 LERROR <<
"Error in date conversion (date '"<< (*it).second
144 <<
"' will be ignored): " << e.what();
147 else if ((*it).first==
"location")
149 metadataholder->
setLocation(
"document",(*it).second);
151 LDEBUG <<
"use '"<< (*it).second<<
"' as document location";
154 else if ((*it).first==
"time")
157 auto docTime= QTime::fromString((*it).second.c_str(),
"hh:mm:ss.z" );
158 metadataholder->
setTime(
"document",docTime);
160 LDEBUG <<
"use '"<< (*it).second<<
"' as document time";
163 catch (std::exception& e)
165 LERROR <<
"Error in ptime conversion (time '"<< (*it).second
166 <<
"' will be ignored): " << e.what();
169 else if ((*it).first==
"docid")
172 LDEBUG <<
"use '"<< (*it).second<<
"' as document id";
187 LINFO <<
"CoreLinguisticProcessingClient::analyze(" << docId <<
"...)";
193 const auto& offsetStr = metadataholder->
getMetaData(
"StartOffset");
201 const auto& fileName = metadataholder->
getMetaData(
"FileName");
203 const auto& lang = metadataholder->
getMetaData(
"Lang");
204 LINFO <<
"analyze file is: '" << fileName <<
"'";
205 LINFO <<
"analyze pipeline is '" << pipelineId <<
"'";
206 LINFO <<
"analyze language is '" << lang <<
"'";
208 LDEBUG <<
"text : " << text;
212 auto langId = MediaticData::single().getMediaId(lang);
216 if (pipeline ==
nullptr)
218 LERROR <<
"can't get pipeline '" << pipelineId <<
"'";
220 std::string(
"can't get pipeline '" + pipelineId +
"' for language '" + lang +
"'") );
223 for (
auto inactiveUnit: inactiveUnits)
226 inactiveUnitsData->insert(inactiveUnit);
228 analysis->setData(
"InactiveUnits", inactiveUnitsData);
232 LDEBUG <<
"add handler to analysis" ;
233 for (
auto hit = handlers.begin(); hit != handlers.end(); hit++)
235 LDEBUG <<
" " << (*hit).first << (*hit).second;
242 analysis->setData(
"AnalysisHandlerContainer", h);
246 LDEBUG <<
"Process pipeline..." ;
248 auto status = pipeline->process(*analysis);
250 LDEBUG <<
"pipeline process returned status " << (int)status ;
255 <<
" from pipeline." );
260CoreLinguisticProcessingClientFactory::CoreLinguisticProcessingClientFactory() :
274 std::deque<std::string> langs,
275 std::deque<std::string> pipelines)
279 LINFO <<
"CoreLinguisticProcessingClientFactory::configure";
284 deque<string> langToload(langs);
285 if (langToload.empty())
290 "mediaProcessingDefinitionFiles",
295 LERROR <<
"no parameter lima-coreclient/mediaProcessingDefinitionFiles/available !";
296 throw InvalidConfiguration(
"no parameter lima-coreclient/mediaProcessingDefinitionFiles/available !");
300 for (
const auto& lang: langToload)
302 LINFO <<
"CoreLinguisticProcessingClientFactory::configure load language " << lang;
303 auto langid = MediaticData::single().getMediaId(lang);
308 if (configPaths.isEmpty())
310 LERROR <<
"no config paths available in MediaticData";
315 "mediaProcessingDefinitionFiles",
317 Q_FOREACH(QString confPath, configPaths)
319 if (QFileInfo::exists(confPath +
"/" + mediaProcessingDefinitionFile))
321 file = confPath +
"/" + mediaProcessingDefinitionFile;
327 LERROR <<
"no language definition file"<< mediaProcessingDefinitionFile
328 <<
"for language" << lang <<
"found in config paths"
335 LERROR <<
"no language definition file for language " << lang;
344 LINFO <<
"configure resources for language " << lang;
347 auto&
module = langParser.getModuleConfiguration("Resources");
351 lang.find(
"ud-") != 0 && lang !=
"ud");
355 LERROR <<
"no module 'Resources' in configuration file " << file;
360 LINFO <<
"initialize processors";
371 LERROR <<
"missing module 'Processors' in language configuration file " << file;
377 LINFO <<
"initialize Pipelines";
385 LERROR <<
"no module 'pipelines' in lima-analysis.xml (configuration file)";
#define LIMA_PATH_SEPARATOR
#define LPCLIENTFACTORYLOGINIT
#define CORECLIENTLOGINIT
#define LIMA_LP_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LinguisticP...
return a message when a 'list' was not found
return a message when a 'module' is not found
return a message when a 'param' was not found
Parser class for the lima's xml configuration files.
GroupConfigurationStructure & getModuleGroupConfiguration(const std::string &moduleName, const std::string &groupName)
std::deque< std::string > & getModuleGroupListValues(const std::string &moduleName, const std::string &groupName, const std::string &key)
std::string & getModuleGroupParamValue(const std::string &moduleName, const std::string &groupName, const std::string &key)
ModuleConfigurationStructure & getModuleConfiguration(const std::string &moduleName)
Use this exception to signal an error in one of the configuration files.
A factory for the AbstractLinguisticProcessingClient: contains the registration of all implemented cl...
virtual ~CoreLinguisticProcessingClientFactory()
void configure(Common::XMLConfigurationFiles::XMLConfigurationFileParser &configuration, std::deque< std::string > langs, std::deque< std::string > pipelines) override
This function configures the factory, using an XML configuration file S2-lp.xml.
std::shared_ptr< AbstractProcessingClient > createClient() const override
This function create a LinguisticProcessing client.
virtual ~CoreLinguisticProcessingClient()
std::shared_ptr< AnalysisContent > analyze(const QString &texte, const std::map< std::string, std::string > &metaData, const std::string &pipeline, const std::map< std::string, AbstractAnalysisHandler * > &handlers, const std::set< std::string > &inactiveUnits=std::set< std::string >()) const override
This function runs the linguistic analysis on a simple text, specifying the language,...
CoreLinguisticProcessingClient()
define the limaStringText resource which is the text in limaString formal
static const MediaProcessors & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
This file contains a class to control log of informations about time, such as logging cumulated time ...
launch exception related to the configuration file parsing