LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SymbolicCodeXMLHandler.cpp
Go to the documentation of this file.
1// Copyright 2002-2019 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 by CEA LIST *
8 * *
9 ***************************************************************************/
10
12#include "common/LimaCommon.h"
14
15
16using namespace std;
17using namespace Lima;
18using namespace Lima::Common::PropertyCode;
19
20SymbolicCodeXMLHandler::SymbolicCodeXMLHandler(const PropertyCodeManager& pcm,std::map<std::string,LinguisticCode>& outputMap) :
21 m_currentCode(),
22 m_currentPropertyValues(),
23 m_outputMap(outputMap),
24 m_propCodeManager(pcm)
25{}
26
28
29// -----------------------------------------------------------------------
30// Implementations of the SAX DocumentHandler interface
31// -----------------------------------------------------------------------
32bool SymbolicCodeXMLHandler::endElement(const QString & namespaceURI, const QString & name, const QString & qName)
33{
34 LIMA_UNUSED(namespaceURI);
35 LIMA_UNUSED(qName);
36 string stringName=name.toUtf8().data();
37 if (stringName == "code")
38 {
39#ifdef DEBUG_LP
41 LDEBUG << "write code " << m_currentCode;
42#endif
43 if (m_outputMap.find(m_currentCode)!=m_outputMap.end()) {
45 LWARN << m_currentCode << " already exists! overwrite it";
46 }
47 m_outputMap[m_currentCode]=m_propCodeManager.encode(m_currentPropertyValues);
48 }
49 return true;
50}
51
52bool SymbolicCodeXMLHandler::startElement(const QString & namespaceURI, const QString & name, const QString & qName, const QXmlAttributes & attributes)
53{
54 LIMA_UNUSED(namespaceURI);
55 LIMA_UNUSED(qName);
56#ifdef DEBUG_LP
58#endif
59 string stringName=name.toUtf8().data();
60 if (stringName == "code")
61 {
62 m_currentCode=attributes.value("key").toUtf8().data();
63 m_currentPropertyValues.clear();
64#ifdef DEBUG_LP
65 LDEBUG << "read code " << m_currentCode;
66#endif
67 }
68 else if (stringName == "field")
69 {
70 string key=attributes.value("key").toUtf8().data();
71 string value=attributes.value("value").toUtf8().data();
72#ifdef DEBUG_LP
73 LDEBUG << "read field key=" << key << " value=" << value;
74#endif
75 if (value!="")
76 {
77 m_currentPropertyValues[key]=value;
78 }
79 }
80 return true;
81}
#define LWARN
Definition LimaCommon.h:160
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LDEBUG
Definition LimaCommon.h:157
#define PROPERTYCODELOGINIT
Definition LimaCommon.h:213
Provide tools to parse a property file, and deal with the property coding system.
LinguisticCode encode(const std::map< std::string, std::string > &propValues) const
Compute the code corresponding to given the properties/values.
bool startElement(const QString &namespaceURI, const QString &name, const QString &qName, const QXmlAttributes &attributes) override
SymbolicCodeXMLHandler(const Lima::Common::PropertyCode::PropertyCodeManager &pcm, std::map< std::string, Lima::LinguisticCode > &outputMap)
bool endElement(const QString &namespaceURI, const QString &name, const QString &qName) override
NAUTITIA.
STL namespace.