9#include "common/LimaVersion.h"
28#include <boost/algorithm/string/regex.hpp>
29#include <QtCore/QFileInfo>
30#include <QtCore/QTimer>
41int LimaSimpleClientDelegate::argc = 1;
42char* LimaSimpleClientDelegate::argv[2] = {(
char*)(
"LimaSimpleClientDelegate"), NULL};
43QCoreApplication* LimaSimpleClientDelegate::app=
nullptr;
45boost::thread* LimaSimpleClientDelegate::thread=
nullptr;
46std::shared_ptr<LimaWorker> LimaSimpleClientDelegate::m_worker(
nullptr);
47std::shared_ptr<LimaController> LimaSimpleClientDelegate::m_controller(
nullptr);
60 m_firstInitialization(true)
82m_finishedAnalyze(false)
102 if (thread ==
nullptr)
104 thread =
new boost::thread(LimaSimpleClientDelegate::onStarted);
107 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
120 m_controller->stop();
126void LimaSimpleClientDelegate::onStarted()
129 if (QCoreApplication::instance() == NULL)
131 app =
new QCoreApplication(argc, argv);
133 m_worker=std::shared_ptr<LimaWorker>(
new LimaWorker());
134 m_controller=std::shared_ptr<LimaController>(
new LimaController());
137 QObject::connect(m_controller.get(), SIGNAL(doInitialize(std::string,std::string)), m_worker.get(), SLOT(
initialize(std::string,std::string)));
138 QObject::connect(m_controller.get(), SIGNAL(doAnalyze(std::string)), m_worker.get(), SLOT(
analyze(std::string)));
139 QObject::connect(m_worker.get(), SIGNAL(finishedInit()), m_controller.get(), SLOT(endInit()));
140 QObject::connect(m_worker.get(), SIGNAL(finishedAnalyze()), m_controller.get(), SLOT(endAnalyze()));
141 QObject::connect(m_controller.get(), SIGNAL(closeApp()), app, SLOT(quit()));
142 QObject::connect(m_controller.get(), SIGNAL(closeWorker()), m_worker.get(), SLOT(quit()));
150 const std::string& pipeline)
154 m_finishedInit=
false;
159 const std::string& pipeline)
163 m_controller->initialize(language,pipeline);
165 while (! m_controller->hasFinishedInit()) {
167 boost::this_thread::sleep( boost::posix_time::milliseconds(10) );
175 m_finishedAnalyze=
false;
183 m_controller->analyze(text);
184 while (! m_controller->hasFinishedAnalyze()) {
185 boost::this_thread::sleep( boost::posix_time::milliseconds(10) );
187 return m_worker->getResult();
191 const std::string& pipeline)
196 string clientId(
"lima-coreclient");
207 string commonConfigFile(
"lima-common.xml");
208 string lpConfigFile(
"lima-analysis.xml");
210 std::deque<std::string> langs(1,language);
211 std::deque<std::string> pipelines(1,pipeline);
227 cerr <<
"Factory already initialized" << endl;
232 init(resourcesPath.toUtf8().constData(),
233 configPath.toUtf8().constData(),
237 bool clientFactoryConfigured =
false;
238 Q_FOREACH(QString configDir, configDirs)
240 if (QFileInfo::exists(configDir +
"/" + lpConfigFile.c_str()))
244 configDir +
"/" + lpConfigFile.c_str());
245 LinguisticProcessingClientFactory::changeable().configureClientFactory(
250 clientFactoryConfigured =
true;
255 if(!clientFactoryConfigured)
257 std::cerr <<
"No LinguisticProcessingClientFactory were configured with"
259 << lpConfigFile << std::endl;
262 m_client = std::dynamic_pointer_cast<AbstractLinguisticProcessingClient>(
263 LinguisticProcessingClientFactory::single().createClient(clientId));
271 std::map<std::string,std::string> metaData;
273 string pseudofilename=text.substr(0,10);
274 boost::regex_replace(pseudofilename,
275 boost::regex(
"[.,-;:!?\",& <>\n\t ]"),
278 metaData[
"FileName"]=pseudofilename;
#define LIMA_PATH_SEPARATOR
Parser class for the lima's xml configuration files.
Use this exception to signal an error in one of the configuration files.
void doAnalyze(const std::string &text)
virtual ~LimaController()
void analyze(const std::string &text)
LimaController(QObject *parent=nullptr)
void initialize(const std::string &language, const std::string &pipeline)
void doInitialize(const std::string &language, const std::string &pipeline)
LimaSimpleClientDelegate()
void initialize(const std::string &language, const std::string &pipeline)
std::string analyze(const std::string &text)
virtual ~LimaSimpleClientDelegate()
void initialize(const std::string &language, const std::string &pipeline)
std::map< std::string, Lima::AbstractAnalysisHandler * > m_handlers
void analyze(const std::string &text)
bool m_firstInitialization
LimaWorker(QObject *parent=nullptr)
std::shared_ptr< Lima::LinguisticProcessing::AbstractLinguisticProcessingClient > m_client
Lima::LinguisticProcessing::SimpleStreamHandler * m_handler
void setOut(std::ostream *out) override
set the output stream.
static const AmosePluginsManager & single()
const singleton accessor
static LinguisticResources & changeable()
singleton accessor
QStringList buildResourcesDirectoriesList(const QStringList &projects, const QStringList &paths)
Build a list of resources directories from a list of project names and a list of paths.
QStringList buildConfigurationDirectoriesList(const QStringList &projects, const QStringList &paths)
Build a list of configuration directories from a list of project names and a list of paths.
LIMA_COMMONQSLOG_EXPORT bool initQsLog(const QString &configString)