LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
XmlSimpleHandler.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
2//
3// SPDX-License-Identifier: MIT
4
5#include "XmlSimpleHandler.h"
9#include <sstream>
10
11using namespace Lima;
12using namespace Lima;
13using namespace std;
14
15XmlSimpleHandler::XmlSimpleHandler(std::shared_ptr<const ShiftFrom> shiftFrom) :
17m_out(0),
18m_buffer(),
19m_indexingNodeStack()
20{
21}
22
23void XmlSimpleHandler::setOut(std::ostream* out)
24{
25 std::cerr << "XmlSimpleHandler::setOut" << std::endl;
26 m_out = out;
27}
28
30{
31 std::cerr << "XmlSimpleHandler::startDocument" << std::endl;
32 LIMA_UNUSED(props)
33 (*m_out) << "<DOCSET>" << endl;
34}
35
37{
38 std::cerr << "XmlSimpleHandler::endDocument" << std::endl;
39 (*m_out) << "</DOCSET>" << endl;
40 m_out->flush();
41}
42
43void XmlSimpleHandler::handle ( const char* buf,int length )
44{
45 std::cerr << "XmlSimpleHandler::handle" << std::endl;
46 // do not write directly into buffer (need properties to write whole doc)
47 m_buffer.write(buf,length);
48}
49
53
55// TODO devrait s'appeler startHierarchyNode ?
56void XmlSimpleHandler::startNode ( const string& elementName, bool forIndexing )
57{
58 LIMA_UNUSED(elementName)
59 // do nothing: all is done at end node
60
61 // just keep track of indexing nodes
62 m_indexingNodeStack.push_back(forIndexing);
63}
64
66// TODO devrait s'appeler endHierarchyNode ?
68{
69 std::cerr << "XmlSimpleHandler::endNode" << std::endl;
70 // only print output if end of indexing node
71 if (! m_indexingNodeStack.back()) {
72 m_indexingNodeStack.pop_back();
73 return;
74 }
75
76 m_indexingNodeStack.pop_back();
77
78 // get document id in properties
79 string docId= props.getStringValue ( "identPrpty" ).first;
80 std::replace( docId.begin(), docId.end(), ',', '_');
81
82 (*m_out)
83 << "<DOC id=\"" << docId << "\">" << endl
84 << m_buffer.str()
85 << "</DOC>" << endl;
86
87 m_out->flush();
88
89 // clear buffer
90 m_buffer.str("");
91}
Common Types.
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
abstract handler for XML processing : just inherits from different handlers
std::pair< std::string, bool > getStringValue(std::string propName) const
void endDocument() override
called at the end of a document analysis
std::ostringstream m_buffer
void setOut(std::ostream *out) override
set the output stream.
std::vector< bool > m_indexingNodeStack
void startNode(const std::string &elementName, bool forIndexing) override
called by the document analyzer for a new hierarchy node
void startDocument(const Lima::Common::Misc::GenericDocumentProperties &props) override
notify the start of a new document, and give its properties
XmlSimpleHandler(std::shared_ptr< const ShiftFrom > shiftFrom)
void endNode(const Lima::Common::Misc::GenericDocumentProperties &props) override
called by the document analyzer at the end of a hierarchy node
void handle(const char *buf, int length) override
gives content.
void startAnalysis() override
function called by the LIMA analyzer on start of a new document
NAUTITIA.
STL namespace.