LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
PropertyManager.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 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
11#include "PropertyManager.h"
12
13
14using namespace std;
15
16namespace Lima
17{
18namespace Common
19{
20namespace PropertyCode
21{
22
24{
25friend class PropertyManager;
26public:
27 PropertyManagerPrivate(const std::string& name,
28 const LinguisticCode& mask,
29 const LinguisticCode& emptyNessMask,
30 const std::map<std::string,LinguisticCode> symbol2code);
31
35
36 std::string m_name;
39 std::map<LinguisticCode,std::string> m_code2symbol;
40 std::map<std::string,LinguisticCode> m_symbol2code;
41
43
44 static std::string s_none;
45
46};
47
48std::string PropertyManagerPrivate::s_none("NONE");
49
51 const std::string& name,
52 const LinguisticCode& mask,
53 const LinguisticCode& emptyNessMask,
54 const std::map<std::string,LinguisticCode> symbol2code) :
55 m_name(name),
56 m_mask(mask),
57 m_emptyNessMask(emptyNessMask),
58 m_code2symbol(),
59 m_symbol2code(symbol2code),
60 m_accessor(name,mask,emptyNessMask)
61{
62 // fill code2symbol table from symbol2code table
63 for (map<string,LinguisticCode>::const_iterator it=symbol2code.begin();
64 it!=symbol2code.end();
65 it++)
66 {
67 m_code2symbol.insert(make_pair(it->second,it->first));
68 }
69}
70
74
76 m_name(pmp.m_name),
77 m_mask(pmp.m_mask),
78 m_emptyNessMask(pmp.m_emptyNessMask),
79 m_code2symbol(pmp.m_code2symbol),
80 m_symbol2code(pmp.m_symbol2code),
81 m_accessor(pmp.m_accessor)
82{
83}
84
95
96PropertyManager::PropertyManager(const std::string& name,
97 const LinguisticCode& mask,
98 const LinguisticCode& emptyNessMask,
99 const std::map<std::string,LinguisticCode> symbol2code) :
100 m_d(std::make_unique<PropertyManagerPrivate>(name, mask, emptyNessMask, symbol2code))
101{
102}
103
107
109 m_d(std::make_unique<PropertyManagerPrivate>(*pm.m_d))
110{
111}
112
114{
115 *m_d = *pm.m_d;
116 return *this;
117}
118
119
121{
122 return m_d->m_accessor;
123}
124
125LinguisticCode PropertyManager::getPropertyValue(const std::string& symbolicValue) const
126{
127 auto it = m_d->m_symbol2code.find(symbolicValue);
128 if (it == m_d->m_symbol2code.end())
129 {
131 LWARN << "Ask for unknown value " << symbolicValue
132 << " for property " << m_d->m_name;
133 return L_NONE;
134 }
135 return it->second;
136}
137
139 const LinguisticCode& value) const
140{
141 LinguisticCode val = m_d->m_accessor.readValue(value);
142 auto it = m_d->m_code2symbol.find(val);
143 if (it == m_d->m_code2symbol.cend())
144 {
146 LWARN << "Ask for unknown value " << val << " (extracted from " << value
147 << ") for property " << m_d->m_name;
149 }
150 return it->second;
151}
152
154{
155 return m_d->m_mask;
156}
157
159{
160 return m_d->m_emptyNessMask;
161}
162
163const std::map<LinguisticCode,std::string>& PropertyManager::getCode2Symbol() const
164{
165 return m_d->m_code2symbol;
166}
167
168const std::map<std::string,LinguisticCode>& PropertyManager::getSymbol2Code() const
169{
170 return m_d->m_symbol2code;
171}
172
174{
175 return m_d->m_symbol2code.size();
176}
177
178} // PropertyCode
179} // Common
180} // Lima
#define LWARN
Definition LimaCommon.h:160
#define PROPERTYCODELOGINIT
Definition LimaCommon.h:213
#define L_NONE
Definition StdBitset.h:338
Provide function to read write and check a property.
PropertyManagerPrivate & operator=(const PropertyManagerPrivate &pmp)
std::map< LinguisticCode, std::string > m_code2symbol
PropertyManagerPrivate(const std::string &name, const LinguisticCode &mask, const LinguisticCode &emptyNessMask, const std::map< std::string, LinguisticCode > symbol2code)
std::map< std::string, LinguisticCode > m_symbol2code
Provide tools to manage a specific property.
const std::map< LinguisticCode, std::string > & getCode2Symbol() const
Get the Code -> Symbol mapping.
LinguisticCode getEmptyNessMask() const
The emptyNessMask is the mask use to check if property is empty.
const std::string & getPropertySymbolicValue(const LinguisticCode &value) const
The coded property value can hold several property data.
PropertyManager(const std::string &name, const LinguisticCode &mask, const LinguisticCode &emptyNessMask, const std::map< std::string, LinguisticCode > symbol2code)
constructor
size_t getNbValues() const
give the number of values for this property
LinguisticCode getMask() const
Get the property mask.
const PropertyAccessor & getPropertyAccessor() const
give the corresponding PropertyAccessor
const std::map< std::string, LinguisticCode > & getSymbol2Code() const
Get the Symbol -> Code mapping.
LinguisticCode getPropertyValue(const std::string &symbolicValue) const
Get the coded property value from the symbolic value.
PropertyManager & operator=(const PropertyManager &)
NAUTITIA.
STL namespace.