LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
XmlBowDocumentHandler.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
13
14#include <sstream>
15
16using namespace Lima;
17using namespace Lima;
18using namespace Lima::Common;
19using namespace std;
21
22XmlBowDocumentHandler::XmlBowDocumentHandler(std::shared_ptr<const ShiftFrom> shiftFrom) : AbstractXmlDocumentHandler(shiftFrom)
23{
25 set_lastNodeId ( 1 );
26
27};
28
29void XmlBowDocumentHandler::setOut(std::ostream* out)
30{
31#ifdef DEBUG_LP
33 LDEBUG << "XmlBowDocumentHandler::setOut";
34#endif
35// std::cerr << "XmlBowDocumentHandler::setOut" << std::endl;
36 m_out = out;
39}
40
41void XmlBowDocumentHandler::handle ( const char* buf,int length )
42{
43// std::cerr << "XmlBowDocumentHandler::handle" << std::endl;
44 m_out->write(buf,length);
45}
46
48{
49#ifdef DEBUG_LP
51 LDEBUG << "XmlBowDocumentHandler::startAnalysis write BOW_TEXT_BLOC";
52#endif
54}
55
57// TODO devrait s'appeler startHierarchyNode ?
58void XmlBowDocumentHandler::startNode ( const string& elementName, bool forIndexing )
59{
60#ifdef DEBUG_LP
62 LDEBUG << "xmlDocumentHandler::startNode " << elementName;
63#endif
64 NODE_ID nodeId = get_lastNodeId() + 1;
65 set_lastNodeId ( nodeId );
66 if (!m_openedNodes.empty())
67 {
69 }
70 m_openedNodes.push_back ( nodeId );
71
72 if ( ( get_parentlastOpenedNode() ==1 ) && ( nodeId==1 ) )
74
76 CONTENT_ID contentId=get_LastContentId();
77
78 Node newNode("XML_BOW_DOCUMENT_HANDLER0", // docName
79 get_LastStructureId(), // structId
80 *m_openedNodes.rbegin(), // nodeId
81 contentId, // contentId
82 0, // indexid
83 get_lastUri(), // uri
84 "xml", // nodeMedia
85 elementName, // nodeType
86 "none", // descrId
87 0, // nodeStart
88 0, // nodeEnd
89 0, // nodeLength
90 get_parentlastOpenedNode() // nodeParent
91 );
92 newNode.indexId(0);
93 add_Node ( newNode );
94
95 if( forIndexing )
96 {
97#ifdef DEBUG_LP
98 LDEBUG << "XmlBowDocumentHandler::startNode write INDEXING_BLOC";
99#endif
101 }
102 else
103 {
104#ifdef DEBUG_LP
105 LDEBUG << "XmlBowDocumentHandler::startNode write HIERARCHY_BLOC";
106#endif
108 }
109
110#ifdef DEBUG_LP
111 LDEBUG << "XmlBowDocumentHandler::startNode write element name: " << elementName;
112#endif
114
115// std::cerr << "XmlBowDocumentHandler::startNode ici" << elementName << std::endl;
116}
117
119// TODO devrait s'appeler endHierarchyNode ?
121{
122// std::cerr << "XmlBowDocumentHandler::endNode" << std::endl;
123 STRUCT_ID Sid=props.getIntValue ( "StructureId" ).first;
124 NODE_ID Nid=props.getIntValue ( "NodeId" ).first;
125 CONTENT_ID Cid=props.getIntValue ( "ContentId" ).first;
126 //ajouter les propriétés
128 CONTENT_ID contentId=get_LastContentId();
129
132
133 Node newNodeProps("XML_BOW_DOCUMENT_HANDLER1", // docName
134 Sid, // structId
135 Nid, // nodeId
136 contentId, // contentId
137 0, // indexid
138 get_lastUri(), // uri
139 "xml", // nodeMedia
140 "props", // nodeType
141 "none", // descrId
142 0, // nodeStart
143 0, // nodeEnd
144 0, // nodeLength
145 get_parentlastOpenedNode() // nodeParent
146 );
147 newNodeProps.indexId(0);
148
149 add_Node ( newNodeProps );
150
151// string docName= props.getStringValue ( "identPrpty" ).first;
152
153 Node* node = get_Node ( Cid );
154 node->nodeStart(props.getIntValue ( "offBegPrpty" ).first);
155 node->nodeEnd(props.getIntValue ( "offEndPrpty" ).first);
156 node->nodeLength(node->nodeEnd()-node->nodeStart());
157 m_openedNodes.pop_back();
158
159#ifdef DEBUG_LP
161 LDEBUG << "XmlBowDocumentHandler::endNode write NODE_PROPERTIES_BLOC";
162#endif
164 props.write(*m_out);
165#ifdef DEBUG_LP
166 LDEBUG << "XmlBowDocumentHandler::endNode write END_BLOC";
167#endif
169 m_out->flush();
170}
Common Types.
#define LDEBUG
Definition LimaCommon.h:157
#define HANDLERLOGINIT
Definition LimaCommon.h:207
abstract handler for XML processing : just inherits from different handlers
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.
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 startNode(const std::string &elementName, bool forIndexing) override
called by the document analyzer for a new hierarchy node
XmlBowDocumentHandler(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 startAnalysis() override
function called by the LIMA analyzer on start of a new document
void handle(const char *buf, int length) override
gives content.
void setOut(std::ostream *out) override
set the output stream.
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 STRUCT_ID
Identifier of a structure in the structure index.
Definition DataTypes.h:35
uint64_t NODE_ID
Identifier of a node in a document.
Definition DataTypes.h:40
STL namespace.