LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EventDumper.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004-2012 by CEA LIST *
8 * *
9 ***************************************************************************/
10#include "EventDumper.h"
11// #include "linguisticProcessing/core/LinguisticProcessors/HandlerStreamBuf.h"
13#include "Events.h"
14
26
27#include <fstream>
28
29
30using namespace std;
31using namespace boost;
32using namespace boost::tuples;
33
35using namespace Lima::Common::MediaticData;
36using namespace Lima::Common::AnnotationGraphs;
37
39using namespace Lima::LinguisticProcessing;
41
42namespace Lima {
43namespace LinguisticProcessing {
44namespace EventAnalysis {
46
51
52
56
59 Manager* manager)
60
61{
62 m_language=manager->getInitializationParameters().media;
63
64 try
65 {
66 m_file=unitConfiguration.getParamsValueAtKey("traceFile");
67 }
69 {
71 LWARN << "No 'traceFile' parameter in unit configuration '"
72 << unitConfiguration.getName() << "' ; using tmpFile";
73 }
74 try
75 {
76 m_handler=unitConfiguration.getParamsValueAtKey("handler");
77 }
78 catch (NoSuchParam& )
79 {
81 LERROR << "EventDumper::init: Missing parameter handler in EventDumper configuration";
83 }
84
85}
86
88 AnalysisContent& analysis) const
89{
92
93 LDEBUG << "EventDumper::process()... ";
94
95 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.getData("LinguisticMetaData"));
96 if (metadata == 0)
97 {
98 LERROR << "EventDumper::process: no LinguisticMetaData ! abort";
99 return MISSING_DATA;
100 }
101
102 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("AnalysisGraph"));
103 if (anagraph==0)
104 {
105 LERROR << "EventDumper::process: no graph 'AnaGraph' available !";
106 return MISSING_DATA;
107 }
108 auto posgraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("PosGraph"));
109 if (posgraph==0)
110 {
111 LERROR << "EventDumper::process: no graph 'PosGraph' available !";
112 return MISSING_DATA;
113 }
114
115 LDEBUG << "EventDumper::process(): handler will be: " << m_handler;
116// MediaId langid = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(metadata->getMetaData("Lang"))).getMedia();
117// AbstractTextualAnalysisHandler* handler = static_cast<AbstractTextualAnalysisHandler*>(LinguisticResources::single().getResource(langid, m_handler));
118 auto h = std::dynamic_pointer_cast<AnalysisHandlerContainer>(analysis.getData("AnalysisHandlerContainer"));
119 AbstractTextualAnalysisHandler* handler = static_cast<AbstractTextualAnalysisHandler*>(h->getHandler(m_handler));
120 LDEBUG << "EventDumper::process(): handler= " << handler;
121 if (handler==0)
122 {
123 LERROR << "EventDumper::process(): handler " << m_handler << " has not been given to the core client";
124 return MISSING_DATA;
125 }
126
127 HandlerStreamBuf hsb(handler);
128 std::ostream out(&hsb);
129 LDEBUG << "EventDumper::process(): handler->startAnalysis()...";
130 handler->startAnalysis();
131
132 LDEBUG << "EventDumper::process() get EventData...";
133 auto events = std::dynamic_pointer_cast<Events>(analysis.getData("EventData"));
134 if (events==0)
135 {
136 LWARN << "EventDumper::process(): no Events !";
137 events = std::make_shared<Events>();
138 }
139
140 std::string stringEvents = events->toString("P_URI");
141 LDEBUG << "EventDumper::process(): stringEvents =" << stringEvents;
142
143 LDEBUG << "EventDumper::process() events->size()=" << events->size();
144 LDEBUG << "EventDumper::process(): events->write()...";
145 events->write(out);
146 out.flush();
147 LDEBUG << "EventDumper::process(): handler->endAnalysis()...";
148 handler->endAnalysis();
149 TimeUtils::logElapsedTime("EventDumper");
150 return SUCCESS_ID;
151}
152
153
154
155} // closing EventAnalysis
156} // closing namespace LinguisticProcessing
157} // closing namespace Lima
#define EVENTDUMPER_CLASSID
Definition EventDumper.h:42
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define DUMPERLOGINIT
Defines a Factory to create Object of type Base.
virtual void startAnalysis()=0
function called by the LIMA analyzer on start of a new document
virtual void endAnalysis()=0
function called by the LIMA analyzer on the end of a text part that is to be analyzed
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
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.
Definition LimaCommon.h:345
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
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, EventDumper > EventDumperFactory(EVENTDUMPER_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
@ MISSING_DATA
Definition LimaCommon.h:243
STL namespace.
launch exception related to the configuration file parsing