LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SegmentationDataXmlLogger.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 *
8 * @file SegmentationDataXmlLogger.cpp
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Fri Jan 21 2011
11 * copyright Copyright (C) 2011 by CEA LIST
12 *
13 ***********************************************************************/
14
16#include "SegmentationData.h"
20#include <fstream>
21
22using namespace std;
23
24namespace Lima {
25namespace LinguisticProcessing {
26
28
29//***********************************************************************
30// constructors and destructors
32AbstractLinguisticLogger(".seg.xml"),
33m_data("segmentationData")
34{
35}
36
39
40//***********************************************************************
43 Manager* manager)
44
45{
46 LOGINIT("LP::Segmentation");
47 LDEBUG << "SegmentationDataXmlLogger::init";
48
49 AbstractLinguisticLogger::init(unitConfiguration,manager);
50
51 try {
52 m_data=unitConfiguration.getParamsValueAtKey("data");
53 }
54 catch (Common::XMLConfigurationFiles::NoSuchParam& ) {} // do nothing, keep default
55}
56
58 AnalysisContent& analysis) const
59{
60 LOGINIT("LP::Segmentation");
61 LDEBUG << "SegmentationDataXmlLogger::process";
63
64 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.getData("LinguisticMetaData"));
65 if (metadata == 0) {
66 LOGINIT("LP::Segmentation");
67 LERROR << "no LinguisticMetaData ! abort";
68 return MISSING_DATA;
69 }
70
71 // open output file
72 ofstream out;
73 if (!openLogFile(out,metadata->getMetaData("FileName"))) {
74 LOGINIT("LP::Segmentation");
75 LERROR << "Can't open log file '" << metadata->getMetaData("FileName") << "'";
76 return UNKNOWN_ERROR;
77 }
78
79 // get metadata (useful for XML documents)
80// uint64_t offset(0);
81// uint64_t offsetIndexingNode(0);
82 std::string docId("");
83 try {
84// offset=atoi(metadata->getMetaData("StartOffset").c_str());
85// offsetIndexingNode=atoi(metadata->getMetaData("StartOffsetIndexingNode").c_str());
86 docId=metadata->getMetaData("DocId");
87 }
89 // do nothing: not set in analyzeText (only in analyzeXmlDocuments)
90 }
91
92 // log
93 out << "<segmentation>" << endl;
94 auto data = analysis.getData(m_data);
95 if (data!=0) {
96 const SegmentationData* segData=static_cast<const SegmentationData*>(data.get());
97 const vector<Segment> seg=segData->getSegments();
98 for (vector<Segment>::const_iterator it=seg.begin(), it_end=seg.end(); it!=it_end; it++) {
99 out
100 << "<segment>"
101 << "<pos>" << (*it).getPosBegin() << "</pos>"
102 << "<len>" << (*it).getLength() << "</len>"
103 << "<type>" << (*it).getType() << "</type>"
104 << "</segment>"
105 << endl;
106 }
107 }
108 else {
109 LOGINIT("LP::Segmentation");
110 LDEBUG << "no SegmentationData of name " << m_data;
111 }
112
113 out << "</segmentation>" << endl;
114 out.close();
115
116 TimeUtils::logElapsedTime("SegmentationDataXmlLogger");
117 return SUCCESS_ID;
118}
119
120
121} // end namespace
122} // end namespace
#define LOGINIT(X)
Definition LimaCommon.h:187
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define SEGMENTATIONDATAXMLLOGGER_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
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
A generic process unit to log information in files: contains some common informations such as : outpu...
bool openLogFile(std::ofstream &output, const std::string &sourceFile) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
const std::vector< Segment > & getSegments() const
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, SegmentationDataXmlLogger > SegmentationDataXmlLoggerFactory(SEGMENTATIONDATAXMLLOGGER_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ UNKNOWN_ERROR
Definition LimaCommon.h:238
@ SUCCESS_ID
Definition LimaCommon.h:237
@ MISSING_DATA
Definition LimaCommon.h:243
STL namespace.