LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
BowDocumentHandler.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 "BowDocumentHandler.h"
13
14using namespace std;
15using namespace Lima::Common::BagOfWords;
16
17namespace Lima {
18
19namespace LinguisticProcessing {
20
22m_bowdocs(),
23m_bowstream(0),
24m_writer(0)
25{
26}
27
28
32
34{
35 if (m_bowstream!=0) {
36 return m_bowstream->str();
37 }
38 return "";
39}
40
42{
44 LDEBUG << "BowDocumentHandler::startDocument()";
45
46 m_bowstream=new ostringstream();
47 m_writer=new SBowDocumentWriter();
48 m_writer->setOut(m_bowstream);
49 m_writer->startDocument(props);
50}
51
53{
55 LDEBUG << "BowDocumentHandler::endDocument()";
56 m_writer->endDocument();
57
58 // build bow documents from the XML-structured BoWDocument stream:
59 // flatten structure to fit standard BoWDocuments, using a writer
60 // implementing the AbstractBoWXMLWriter
61
62 istringstream in(m_bowstream->str());
63
64 BoWBinaryReader reader;
65 reader.readHeader(in);
66
67 StructuredBoWToBoWDocument structuredBowHandler(&m_bowdocs);
68 BoWDocument* document=new BoWDocument();
69 while (in.good()) {
70 // read Part( istream, AbstractBoWXMLWriter writer, bool useIterator)
71 // do not use iterator,
72 // std::cout is unused
73 reader.readBoWDocumentBlock(in, *document, structuredBowHandler, false, false);
74 }
75
76 delete m_bowstream;
77 m_bowstream=0;
78 delete m_writer;
79 m_writer=0;
80}
81
82void BowDocumentHandler::startNode( const std::string& elementName, bool forIndexing )
83{
85 LDEBUG << "BowDocumentHandler::startNode()";
86
87 m_writer->startNode(elementName, forIndexing );
88}
89
91{
93 LDEBUG << "BowDocumentHandler::endNode()";
94 m_writer->endNode(props);
95}
96
98{
100 LDEBUG << "BowDocumentHandler::startAnalysis()";
101 m_writer->startAnalysis();
102}
103
105{
107 LDEBUG << "BowDocumentHandler::endAnalysis()";
108 m_writer->endAnalysis();
109}
110
111void BowDocumentHandler::handle(const char* buf,int length)
112{
114 LDEBUG << "BowDocumentHandler::handleText()";
115 m_writer->handle(buf,length);
116}
117
118
119}
120
121}
#define LDEBUG
Definition LimaCommon.h:157
#define LPCLIENTSBOWHANDLERLOGINIT
BoWBlocType readBoWDocumentBlock(std::istream &file, BoWDocument &document, AbstractBoWDocumentHandler &handler, bool useIterator, bool useIndexIterator)
represent a document as a Bag Of Word, with associated document properties.
Definition bowDocument.h:57
void endAnalysis() override
notify the end of an analysis content
void startNode(const std::string &elementName, bool forIndexing) override
notify the start of a new hierarchyNode
void endNode(const Common::Misc::GenericDocumentProperties &props) override
notify the end of a hierarchyNode
void handle(const char *buf, int length) override
gives content.
void startAnalysis() override
notify the start of an analysis content
void startDocument(const Common::Misc::GenericDocumentProperties &props) override
notify the start of a new document
void endDocument() override
notify the end of the document
void endAnalysis() override
notify the end of an analysis content
virtual void setOut(std::ostream *out) override
set the output stream.
void handle(const char *buf, int length) override
gives content.
void startAnalysis() override
notify the start of an analysis content
void endNode(const Common::Misc::GenericDocumentProperties &props) override
notify the end of a hierarchyNode
void endDocument() override
notify the end of the document
void startNode(const std::string &elementName, bool forIndexing) override
notify the start of a new hierarchyNode
void startDocument(const Common::Misc::GenericDocumentProperties &props) override
notify the start of a new document
NAUTITIA.
STL namespace.