LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
MultimediaDocumentHandler.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
11
12#include <sstream>
13
14using namespace Lima;
15using namespace Lima::Common;
17// using namespace Lima::Common::MediaticData;
18using namespace Lima::Common::BagOfWords;
19using namespace Lima::Handler;
20using namespace std;
21
22MultimediaDocumentHandler::MultimediaDocumentHandler(std::shared_ptr<const ShiftFrom> shiftFrom) :
23 AbstractXmlDocumentHandler(shiftFrom), m_out(nullptr)
24{
25#ifdef DEBUG_LP
27 LDEBUG << "MultimediaDocumentHandler::MultimediaDocumentHandler" ;
28#endif
30 set_lastNodeId ( 1 );
31}
32
33void MultimediaDocumentHandler::setOut(std::ostream* out)
34{
35#ifdef DEBUG_LP
37 LDEBUG << "MultimediaDocumentHandler::setOut " << out;
38#endif
39 m_out = out;
41// BoWBinaryWriter writer(shiftFrom());
43}
44
45void MultimediaDocumentHandler::handle ( const char* buf,int length )
46{
47#ifdef DEBUG_LP
49 LTRACE << "MultimediaDocumentHandler::handle writing on" << m_out << QString::fromUtf8(buf,length);
50#endif
51// std::cerr << "MultimediaDocumentHandler::handle" << std::endl;
52 m_out->write(buf,length);
53}
54
56{
57#ifdef DEBUG_LP
59 LDEBUG << "MultimediaDocumentHandler::startAnalysis()" << m_out;
60#endif
62}
63
64void MultimediaDocumentHandler::startAnalysis(const std::string& bloc_type)
65{
66#ifdef DEBUG_LP
68 LDEBUG << "MultimediaDocumentHandler::startAnalysis(bloc_type) write BLOC " << bloc_type;
69#endif
70
71 if (bloc_type.compare("lpFactory")==0)
73 else if(bloc_type.compare("ImaFactory")==0)
75 else if(bloc_type.compare("VideoFactory")==0)
77 else
79}
80
82// TODO devrait s'appeler startHierarchyNode ?
83void MultimediaDocumentHandler::startNode ( const std::string& elementName, bool forIndexing )
84{
85 NODE_ID nodeId = get_lastNodeId() ;
86 set_lastNodeId ( nodeId + 1);
87 if (!m_openedNodes.empty())
88 {
89 //
91 }
92 m_openedNodes.push_back ( nodeId );
93#ifdef DEBUG_LP
95 LDEBUG << "MultimediaDocumentHandler::startNode" << this << elementName << nodeId << m_openedNodes.size();
96#endif
97
98 if ( ( get_parentlastOpenedNode() ==1 ) && ( nodeId==1 ) )
100
101 if (forIndexing)
103
104 Node newNode("MULTIMEDIA_DOCUMENT_HANDLER0", // docName
105 get_LastStructureId(), // structId
106 nodeId, // nodeId
107 -1, // contentId
108 0, // indexid
109 get_lastUri(), // uri
110 "xml", // nodeMedia
111 elementName, // nodeType
112 "none", // descrId
113 0, // nodeStart
114 0, // nodeEnd
115 0, // nodeLength
116 get_parentlastOpenedNode() // nodeParent
117 );
118 newNode.indexId(0);
119// cout<<" ajout noeud "<<newNode<<endl;
120 StructureHandler::add_Node ( newNode );
121
122 if( forIndexing )
123 {
124#ifdef DEBUG_LP
125 LDEBUG << "MultimediaDocumentHandler::startNode write INDEXING_BLOC";
126#endif
128 }
129 else
130 {
131#ifdef DEBUG_LP
132 LDEBUG << "MultimediaDocumentHandler::startNode write HIERARCHY_BLOC";
133#endif
135 }
136
137#ifdef DEBUG_LP
138 LDEBUG << "MultimediaDocumentHandler::startNode write element name: " << elementName;
139#endif
141
142//cerr >> std::cerr << "MultimediaDocumentHandler::startNode ici" << elementName << std::endl;
143}
144
146// TODO devrait s'appeler endHierarchyNode ?
148{
149 NODE_ID Nid=props.getIntValue ( "NodeId" ).first;
150#ifdef DEBUG_LP
152 LDEBUG << "MultimediaDocumentHandler::endNode" << this << Nid << m_openedNodes.size();
153#endif
154 CONTENT_ID Cid=props.getIntValue ( "ContentId" ).first;
155 //ajouter les propriétés
156// set_LastContentId(get_LastContentId()+1);
157// CONTENT_ID contentId=get_LastContentId();
158
161
162// Node newNodeProps(Sid,Nid,contentId,0,get_lastUri(),"xml","props","none",1,0,0,1,0,0,0,get_parentlastOpenedNode() );
163// newNodeProps.m_indexId=0;
164//
165// add_Node ( newNodeProps );
166
167// string docName= props.getStringValue ( "identPrpty" ).first;
168 Node* node = StructureHandler::get_Node ( Cid );
169 if (node != 0)
170 {
171 node->nodeStart(props.getIntValue ( "offBegPrpty" ).first);
172 node->nodeEnd(props.getIntValue ( "offEndPrpty" ).first);
173 node->nodeLength(node->nodeEnd()-node->nodeStart());
174 }
175 if (!m_openedNodes.empty())
176 {
177 m_openedNodes.pop_back();
178 }
179 // TODO Check why the else bellow happens. It could be a bug.
180// else
181// {
182// LERROR << "MultimediaDocumentHandler::endNode m_openedNodes should not be empty for mode id" << Nid;
183// Q_ASSERT(!m_openedNodes.empty());
184// }
185
188
189#ifdef DEBUG_LP
190 LDEBUG << "MultimediaDocumentHandler::endNode write NODE_PROPERTIES_BLOC on" << m_out;
191#endif
193 props.write(*m_out);
194#ifdef DEBUG_LP
195 LDEBUG << "MultimediaDocumentHandler::endNode write END_BLOC on" << m_out;
196#endif
198 m_out->flush();
199}
#define LTRACE
Definition LimaCommon.h:156
#define LDEBUG
Definition LimaCommon.h:157
#define HANDLERLOGINIT
Definition LimaCommon.h:207
std::shared_ptr< const ShiftFrom > shiftFrom() const
abstract handler for XML processing : just inherits from different handlers
std::vector< NODE_ID >::iterator m_lastOpenedNode
void writeHeader(std::ostream &file, BoWFileType type) const
std::pair< uint64_t, bool > getIntValue(std::string propName) const
Read access functions for "only once valued" property propName.
void addContent(CONTENT_ID ContentId, Content datas)
Ajouter un contenu au handler.
void startAnalysis() override
function called by the LIMA analyzer on start of a new document
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 setOut(std::ostream *out) override
set the output stream.
void startNode(const std::string &elementName, bool forIndexing) override
called by the document analyzer for a new hierarchy node
MultimediaDocumentHandler(std::shared_ptr< const ShiftFrom > shiftFrom)
noeud de contenu au sein d'une structure.
Definition DataTypes.h:62
TOPO_POS nodeStart() const
int32_t indexId() const
TOPO_POS nodeEnd() const
TOPO_POS nodeLength() const
void add_Node(const Node &node)
STRUCT_ID get_LastStructureId()
Accesseur de lastStructureId.
Node * get_Node(CONTENT_ID)
Récupérer un noeud du handler.
void set_LastContentId(CONTENT_ID)
void set_LastStructureId(STRUCT_ID)
void writeOneByteInt(std::ostream &file, const uint8_t number)
write a integer coded on one byte format in a file
void writeStringField(ostream &file, const string &s)
NAUTITIA.
uint64_t CONTENT_ID
Identifier of an feature content.
Definition DataTypes.h:45
uint64_t NODE_ID
Identifier of a node in a document.
Definition DataTypes.h:40
STL namespace.