45 LDEBUG <<
"CoreXmlReaderClient::CoreXmlReaderClient";
56 delete m_documentReader;
66 startNode(contentDocument,
false);
72 auto absElement = contentDocument.back();
79 auto offset = m_handler->
shiftFrom()->correct_offset(0, element->getOffset());
80 element->setIntValue(
"offEndPrpty", offset);
86 LDEBUG <<
"CoreXmlReaderClient::endHierarchy("
87 << element->getElementName() <<
")"
89 << element->getIntValue(
"offBegPrpty").first
91 << element->getIntValue(
"offEndPrpty").first;
101 startNode(contentDocument,
true);
109 LDEBUG <<
"CoreXmlReaderClient::endIndexing";
112 auto absElement = contentDocument.back();
117 if (element ==
nullptr)
120 LERROR <<
"CoreXmlReaderClient::endIndexing must be a structured Element" ;
124 auto offset = m_handler->
shiftFrom()->correct_offset(0, element->getOffset());
125 element->setIntValue(
"offEndPrpty", offset);
130 LDEBUG <<
"CoreXmlReaderClient::endIndexing("
131 << element->getElementName() <<
")"
133 << element->getIntValue(
"offBegPrpty").first
135 << element->getIntValue(
"offEndPrpty").first;
146 unsigned long int offset,
147 const string tagName)
153 auto rtext = m_handler->
shiftFrom()->rebuild_text(text, offset);
154 if(std::string(rtext.toStdString()).find_first_not_of(m_emptyTextChars.toStdString()) == string::npos) {
156 LDEBUG <<
"CoreXmlReaderClient::empty text, not analyzed";
164 std::string elementName = element->
getElementName().toUtf8().constData();
170 LDEBUG <<
"CoreXmlReaderClient::handle [" << rtext <<
"], offset ="
171 << offset <<
", tagName =" << tagName <<
", elementName ="
172 << elementName <<
", properties = " << properties;
179 LINFO <<
"CoreXmlReaderClient::handle"
180 <<
"[" << rtext.left(80) <<
"], offset =" << offset
181 <<
", tagName =" << tagName <<
", elementName ="
182 << elementName <<
", properties = " << properties;
184 m_docMetaData[
"StartOffset"] = std::to_string(offset);
185 m_docMetaData[
"ElementName"] = tagName;
204 LERROR <<
"CoreXmlReaderClient::handle no media associated to tag"
206 <<
"and no default media is set. metadata Lang will not be set.";
211 auto offsetIndexingNode = element->
getIntValue(
"offBegPrpty").first;
212 m_docMetaData[
"StartOffsetIndexingNode"] = std::to_string(offsetIndexingNode);
214 auto strText = rtext.toStdString();
220 m_docMetaData[
"pipeline"],
222 std::set<std::string>());
228 const std::string &data)
231 if(!property.
getId().compare(
"langPrpty")) {
232 if(data.compare(m_docMetaData[
"Lang"])) {
237 m_docMetaData[
"Lang"] = data;
240 if(!property.
getId().compare(
"identPrpty")) {
241 std::string ident = data;
242 std::replace( ident.begin(), ident.end(),
',',
'_');
243 m_docMetaData[
"Filename"].append(data);
244 m_docMetaData[
"docid"] = ident;
246 if(!property.
getId().compare(
"pipelineProperty"))
247 m_docMetaData[
"pipeline"].append(data);
250 if(!property.
getId().compare(
"locationPrpty")) {
251 m_docMetaData[
"location"] = data;
258 const std::string &text,
259 const std::map<std::string, std::string>& metaData,
260 const std::string &pipeline,
261 const std::map<std::string, Lima::AbstractAnalysisHandler *>& handlers,
262 const std::set<std::string>& inactiveUnits)
const
265 (void) inactiveUnits;
271 LDEBUG <<
"CoreXmlReaderClient::analyze(... pipeline='" << pipeline <<
"')";
276 LERROR <<
"Error XMLreader: no handler set. It will crash.";
285 std::map<std::string, std::string>* docMetadataPtr =
286 const_cast<std::map<std::string, std::string>*
>(&m_docMetaData);
287 *docMetadataPtr = metaData;
288 (*docMetadataPtr) [
"pipeline"] = pipeline;
293 LDEBUG <<
"CoreXmlReaderClient::analyze: start analyze"
294 << (*docMetadataPtr) [
"filePath"] <<
" ; pipeline='"
295 << std::string((*docMetadataPtr) [
"pipeline"]) <<
"' ; language='"
296 << std::string((*docMetadataPtr)[
"Lang"]) <<
"'";
298 m_handler->
set_lastUri(
string((*docMetadataPtr) [
"filePath"]));
299 m_handler->
set_lang(
string((*docMetadataPtr) [
"Lang"]));
301 if(!m_documentReader->
initWithString(QString::fromStdString(text))) {
303 LERROR <<
"CoreXmlReaderClient::analyze: can't init reader with text !";
304 throw XmlReaderException(
"CoreXmlReaderClient::analyze: can't init reader with text !");
307 LDEBUG <<
"CoreXmlReaderClient::analyze after initWithString";
324 return std::make_shared<AnalysisContent>();
340 element->GenericDocumentProperties::setStringValue(
"srcePrpty", m_docMetaData[
"FileName"]);
348 element->GenericDocumentProperties::setStringValue(
"encodPrpty",
"UTF8");
350 element->GenericDocumentProperties::setDateValue(
"indexDatePrpty", QDate::currentDate());
353 if(!m_docMetaData[
"type"].empty()) {
354 element->GenericDocumentProperties::setStringValue(
"typPrpty", m_docMetaData[
"type"]);
356 LDEBUG <<
"CoreXmlReaderClient::startNode() set typPrpty to: " << m_docMetaData[
"type"];
363 LDEBUG <<
"CoreXmlReaderClient::startNode m_handler::startNode(" << element->
getElementName() <<
")";
367 element->GenericDocumentProperties::setIntValue(
"StructureId", m_handler->
get_LastStructureId());
371 LDEBUG <<
"Warning: No hierarchy node => no NodeId in document properties";
374 element->GenericDocumentProperties::setIntValue(
"NodeId", *m_handler->
m_openedNodes.rbegin());
376 element->GenericDocumentProperties::setIntValue(
"ContentId", m_handler->
get_LastContentId());
383 LDEBUG <<
"CoreXmlReaderClient::setAnalysisHandler (" << handlerId <<
", "
386 if (m_mapHandlers.find(handlerId) != m_mapHandlers.end()) {
388 LERROR <<
"Error: CoreXmlReaderClient::setAnalysisHandler already contains a handler with the ID"
393 if(abstractHandler != 0) {
395 m_handler = abstractHandler;
398 LDEBUG <<
"CoreXmlReaderClient::setAnalysisHandler shiftFrom is " << m_handler->
shiftFrom().get();
401 m_mapHandlers.insert(make_pair(handlerId, handler));
404 LERROR <<
"Error: handler " << handlerId
405 <<
" is not compatible with XML analysis. Segmentation fault to come...";
413 LDEBUG <<
"CoreXmlReaderClient::releaseAnalysisHandler (" << handlerId <<
")";
415 if (m_mapHandlers.find(handlerId) == m_mapHandlers.end()) {
417 LERROR <<
"Error: CoreXmlReaderClient::releaseAnalysisHandler does not contain a handler with the ID" << handlerId;
420 delete m_mapHandlers[handlerId];
421 m_mapHandlers.erase(handlerId);
427CoreXmlReaderClientFactory::CoreXmlReaderClientFactory() :
441 const std::string& defaultMedia,
442 const std::deque<std::string>& medias,
443 const std::deque<std::string>& pipelines)
445 (void) configuration;
446 m_defaultMedia = defaultMedia;
460 LDEBUG <<
"CoreXmlReaderClientFactory::createClient";
463 std::shared_ptr< AbstractXmlReaderClient > client(
new CoreXmlReaderClient(*configuration));
467 std::map<std::string, std::shared_ptr< AbstractProcessingClient > > mapMediaClient;
473 string media = ItrMedia->first;
474 string PCfactoryName = ItrMedia->second;
476 LDEBUG <<
"Media [" << media <<
"] is analyzed by [" << PCfactoryName
479 std::shared_ptr< Lima::ProcessingClientFactory >PCfactory =
getFactoryFromId(PCfactoryName);
481 if(mapMediaClient.find(PCfactoryName) == mapMediaClient.end())
483 std::shared_ptr< AbstractProcessingClient > limaClient(PCfactory->createClient(
"lima-coreclient"));
484 mapMediaClient[PCfactoryName] = limaClient;
491 string TagName = ItrTags->first;
492 string media = ItrTags->second;
496 LINFO <<
"Tag [" << TagName <<
"] corresponding to media [" << media <<
"] has no factory associated";
501 LDEBUG <<
"Tag [" << TagName <<
"] correspond to media [" << media <<
"], analysed by [" << PCfactoryName <<
"]";
504 std::shared_ptr< AbstractProcessingClient > PCclient = mapMediaClient[
m_mapMediaFactory.find(media)->second];
506 client->m_processingClientHandler.setAnalysisClient(TagName, PCclient);
510 client->setDefaultMedia(m_defaultMedia);
511 client->setDocumentPropertyConfiguration(configuration);
#define XMLREADERCLIENTLOGINIT
The AbstractAnalysisHandler class defines the callback interface: the functions that are to be define...
virtual void handleProc(const std::string &tagName, const std::string &content, const std::map< std::string, std::string > &metaData, const std::string &pipeline, const std::map< std::string, AbstractAnalysisHandler * > &handlers=std::map< std::string, AbstractAnalysisHandler * >(), const std::set< std::string > &inactiveUnits=std::set< std::string >())
virtual void setAnalysisClients(std::map< std::string, std::shared_ptr< AbstractProcessingClient > > clients)
virtual std::map< std::string, std::shared_ptr< AbstractProcessingClient > > getAnalysisClients() const
std::shared_ptr< const ShiftFrom > shiftFrom() const
virtual void endDocument()=0
notify the end of the document
virtual void startDocument(const Common::Misc::GenericDocumentProperties &props)=0
notify the start of a new document, and give its properties
virtual void startNode(const std::string &elementName, bool forIndexing)=0
notify the start of a new hierarchyNode
virtual void endNode(const Common::Misc::GenericDocumentProperties &props)=0
notify the end of a hierarchyNode
abstract handler for XML processing : just inherits from different handlers
std::vector< NODE_ID > m_openedNodes
NODE_ID m_parentlastOpenedNode
void set_lang(std::string lang)
void set_lastNodeId(NODE_ID NID)
void set_lastUri(std::string uri)
std::pair< uint64_t, bool > getIntValue(std::string propName) const
Read access functions for "only once valued" property propName.
Parser class for the lima's xml configuration files.
ModuleConfigurationStructure & getModuleConfiguration(const std::string &moduleName)
const PropagatedProperties & getPropertyList() const
Element avec contenu texte.
virtual const QString & getElementName() const
Partie d'un document structure decodee avant analyse.
void setShiftFrom(std::shared_ptr< const ShiftFrom > shiftFrom)
void setLinguisticXMLDocHandler(StructuredXmlDocumentHandler *handler)
bool readXMLDocument()
read the next element in the current file (initFile must have been
bool initWithString(const QString &text)
Element d'un document XML dont content est indexee Exemple <section lang="fre">yeah</section> Il peut...
const std::string & getId() const
get the object id
The main LIMA exception class.
virtual const char * what() const override
STRUCT_ID get_LastStructureId()
Accesseur de lastStructureId.
CONTENT_ID get_LastContentId()
void set_LastStructureId(STRUCT_ID)
A factory for the AbstractXmlReaderClient: contains the registration of all implemented clients that ...
std::shared_ptr< Lima::ProcessingClientFactory > getFactoryFromId(const std::string &id) const
std::map< std::string, std::string > m_mapMediaFactory
std::map< std::string, std::string > m_mapTagMedia
std::string m_defaultMedia
Lima::AbstractProcessingClientHandler m_processingClientHandler
std::map< std::string, std::string > m_mapTagMedia
fabrique du client d'analyse de document XML
void configure(const Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser &configuration, const std::string &defaultMedia, const std::deque< std::string > &medias, const std::deque< std::string > &pipelines) override
virtual ~CoreXmlReaderClientFactory()
std::shared_ptr< AbstractXmlReaderClient > createClient(Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser *configuration) const override
This function create a XmlReader client
client de lecture des fichier XML faisant appel aux clients d'analyse Lors de la lecture d'un fichier...
void endHierarchy(const DocumentsReader::ContentStructuredDocument &contentDocument) override
void setAnalysisHandler(const std::string &handlerId, Lima::AbstractAnalysisHandler *handler) override
associe un handler recupérant l'analyse XML
~CoreXmlReaderClient()
destructeur
void handleProperty(const DocumentsReader::DocumentPropertyType &property, const std::string &data) override
void startHierarchy(const DocumentsReader::ContentStructuredDocument &contentDocument) override
void releaseAnalysisHandler(const std::string &handlerId) override
deletes the analysis handler with the given id and removes it
CoreXmlReaderClient(Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser &configuration)
constructeur
void startIndexing(const DocumentsReader::ContentStructuredDocument &contentDocument) override
void endIndexing(const DocumentsReader::ContentStructuredDocument &contentDocument) override
std::shared_ptr< AnalysisContent > analyze(const std::string &content, const std::map< std::string, std::string > &metaData, const std::string &pipeline, const std::map< std::string, Lima::AbstractAnalysisHandler * > &handlers=std::map< std::string, Lima::AbstractAnalysisHandler * >(), const std::set< std::string > &inactiveUnits=std::set< std::string >()) const override
analyse effective d'un fichier XML.
void handle(const DocumentsReader::ContentStructuredDocument &contentDocument, const Lima::LimaString &text, unsigned long int offset, const std::string tagName) override
callback to the handler.
LimaString utf8stdstring2limastring(const std::string &src)