LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
MetaDataHandler.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 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 "MetaDataHandler.h"
11
12#include <sstream>
13
14using namespace std;
15
16using namespace Lima::LinguisticProcessing;
17
18namespace Lima
19{
20namespace LinguisticProcessing
21
22{
23
24MetaDataHandler::MetaDataHandler(std::ostream* /*out*/):
26m_stream(0),
27m_writer(0),
28m_metadata()
29{
30}
31
34m_stream(0),
35m_writer(0),
36m_metadata()
37{}
38
39
41{
42 if (m_writer != 0) delete m_writer;
43 if (m_stream != 0) delete m_stream;
44}
45
46const std::map<std::string,std::string>& MetaDataHandler::getMetaData()
47{
48 return m_metadata;
49}
50
51void MetaDataHandler::setOut( std::ostream* out ) {
52 m_out = out;
53}
54
58
61
63{
65 LDEBUG << "MetaDataHandler::endAnalysis()";
66 m_writer->endAnalysis();
67 istringstream in(m_stream->str());
68 LDEBUG << "MetaDataHandler::endAnalysis(): m_stream->str= " << m_stream->str();
69 // read the metadata
70 uint size;
71 string key(""),value("");
72 getline(in,value);
73 size=std::stoi(value);
74 for (uint i(0);i<size;i++) {
75 getline(in,key);
76 getline(in,value);
77 m_metadata[key]=value;
78 }
79 //for (const auto& m: m_metadata) {
80 // cerr << "MetaDataHandler: metadata[" << m.first << "]=" << m.second << endl;
81 //}
82}
83
85{
87 LDEBUG << "MetaDataHandler::startAnalysis()";
88 if (m_writer!=0) {
89 LDEBUG << "MetaDataHandler::startAnalysis(): delete m_writer";
90 delete m_writer;
91 m_writer=0;
92 }
93 if (m_stream!=0) {
94 LDEBUG << "MetaDataHandler::startAnalysis(): delete m_stream";
95 delete m_stream;
96 m_writer=0;
97 }
98 m_stream= new ostringstream();
99 m_writer=new SimpleStreamHandler();
100 m_writer->setOut(m_stream);
101 LDEBUG << "MetaDataHandler::startAnalysis(): m_stream->StartAnalysis()...";
102 m_writer->startAnalysis();
103}
104
105
106void MetaDataHandler::handle(const char* buf,int length)
107{
109 LDEBUG << "MetaDataHandler::handle( buff, " << length << ")";
110 m_writer->handle(buf,length);
111}
112
113void MetaDataHandler::startNode( const std::string& /*elementName*/, bool /*forIndexing*/ )
114{
115}
116
120
121} // closing namespace LinguisticProcessing
122} // closing namespace Lima
#define LDEBUG
Definition LimaCommon.h:157
#define DUMPERLOGINIT
void startNode(const std::string &elementName, bool forIndexing) override
notify the start of a new hierarchyNode
virtual void setOut(std::ostream *out) override
set the output stream.
virtual void handle(const char *buf, int length) override
gives content.
virtual void startAnalysis() override
function called by the LIMA analyzer on start of a new document
virtual void endAnalysis() override
function called by the LIMA analyzer on the end of a text part that is to be analyzed
void endNode(const Common::Misc::GenericDocumentProperties &props) override
notify the end of a hierarchyNode
void endDocument() override
notify the end of the document
void startDocument(const Common::Misc::GenericDocumentProperties &) override
notify the start of a new document, and give its properties
const std::map< std::string, std::string > & getMetaData()
void startAnalysis() override
function called by the LIMA analyzer on start of a new document
void setOut(std::ostream *out) override
set the output stream.
void endAnalysis() override
function called by the LIMA analyzer on the end of a text part that is to be analyzed
void handle(const char *buf, int length) override
gives content.
NAUTITIA.
STL namespace.