33namespace LinguisticProcessing {
34namespace SpecificEntities {
36#define NUMVALUE_FEATURE_NAME "numvalue"
37#define UNIT_FEATURE_NAME "unit"
50m_microsForNumber(nullptr),
51m_microsForUnit(nullptr),
52m_microsForConjunction(nullptr),
53m_microAccessor(nullptr)
60 auto micros = std::dynamic_pointer_cast<MicrosForNormalization>(res);
61 m_microsForNumber=micros->getMicros(
"NumberMicros");
62 m_microsForUnit=micros->getMicros(
"UnitMicros");
63 m_microsForConjunction=micros->getMicros(
"ConjCoordMicros");
65 catch (exception& e) {
67 LWARN <<
"Exception caught: " << e.what();
68 LWARN <<
"-> micros for number normalization are not initialized";
90 vector<NumberPart>::iterator itBegin,
91 vector<NumberPart>::iterator itEnd,
94double NormalizeNumber::
112 MorphoSyntacticData::const_iterator
115 for (; it!=it_end; it++) {
120 double d = str.toDouble(&ok);
132 LDEBUG <<
"getNumberValue of " << t->
stringForm() <<
". Could not read number.";
146 LDEBUG <<
"NormalizeNumber " << m;
150 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
152 vector<NumberPart> values;
155 for (RecognizerMatch::iterator it=m.begin(),it_end=m.end();
158 if (! (*it).isKept()) {
164 bool hasNumericValue(
false);
165 std::set< AnnotationGraphVertex > matches = annotationData->matches(m.
getGraph()->
getGraphId(),(*it).m_elem.first,
"annot");
166 for (std::set< AnnotationGraphVertex >::const_iterator annot = matches.begin(),
167 annot_end=matches.end(); annot != annot_end; annot++) {
170 LDEBUG <<
"NormalizeNumber: vertex " << (*it).m_elem.first <<
" has specific entity annotation";
174 pointerValue<SpecificEntityAnnotation>();
176 for (EntityFeatures::const_iterator f=features.begin(),f_end=features.end();
179 LDEBUG <<
"NormalizeNumber: looking at feature " << (*f).getName();
183 double value=boost::any_cast<double>((*f).getValue());
185 LDEBUG <<
"NormalizeNumber: add value " << value;
187 values.push_back(value);
188 hasNumericValue=
true;
190 catch (
const boost::bad_any_cast& e) {
193 std::string strval=(*f).getValueString();
195 double val = std::strtod(strval.c_str(), &end);
196 if (val!=0 || strval==
"0") {
197 values.push_back(val);
198 hasNumericValue=
true;
202 LERROR <<
"Error: failed to get numeric value for feature" << (*f).getName() <<
":" << (*f).getValueString();
209 if (hasNumericValue) {
215 double value=getNumberValue(t,data);
217 values.push_back(value);
221 values.push_back(0.0);
232 if (values.empty()) {
235 <<
"\": no numeric information available for components";
245 LDEBUG <<
"NormalizeNumber: add feature NUMVALUE " << number;
259 default:
return false;
267 default:
return false;
275 default:
return false;
290 int firstSep(str.indexOf(sep));
291 if (firstSep == -1) {
296 int nextSep(str.indexOf(sep,firstSep+1));
303 if (afterSep.size() == 3) {
312 /pow((
double)10,(
int)afterSep.size())) ) ;
318 double result(beforeSep.toDouble());
320 while (nextSep != -1) {
321 afterSep=str.mid(firstSep+1,nextSep-firstSep-1);
322 if (afterSep.size() != 3 ) {
326 result = result*1000 + afterSep.toDouble();
328 nextSep = str.indexOf(sep,firstSep+1);
331 afterSep=str.mid(firstSep+1);
332 if (afterSep.size() != 3 ) {
355 vector<NumberPart>::iterator itBegin,
356 vector<NumberPart>::iterator itEnd,
360 if (itBegin == itEnd) {
367 vector<NumberPart>::iterator tmp(itBegin);
368 if (++tmp == itEnd) {
374 vector<NumberPart>::iterator ConjunctionPosition(itEnd);
375 vector<NumberPart>::iterator biggestMultiplier(itEnd);
376 double biggestMultiplierValue(0);
378 for (vector<NumberPart>::iterator i(itBegin); i!=itEnd; i++) {
382 ConjunctionPosition=i;
385 if (value > biggestMultiplierValue) {
386 biggestMultiplier = i;
387 biggestMultiplierValue = value;
393 if (biggestMultiplier != itEnd) {
395 biggestMultiplierValue
401 if (ConjunctionPosition != itEnd) {
This file is the main header file for the data related to annotation graphs.
#define DEFAULT_ATTRIBUTE
#define UNIT_FEATURE_NAME
#define NUMVALUE_FEATURE_NAME
#define NormalizeNumberId
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
␈rief A class for the description of automata
a list of generic features: each feature is unique (only one feature for a name)
void setFeature(const std::string &name, const ValueType &value)
void addFeature(const std::string &name, const ValueType &value)
const EntityFeatures & features() const
LinguisticAnalysisStructure::Token * getToken(RecognizerMatch::iterator) const
LimaString getString() const
const LinguisticAnalysisStructure::AnalysisGraph * getGraph() const
LinguisticAnalysisStructure::MorphoSyntacticData * getData(RecognizerMatch::iterator) const
const std::string & getGraphId(void) const
Holds morphosyntactic informations.
NumericType getNumeric() const
holds surface data of a token
const TStatus & status() const
const LimaString & stringForm() const
NormalizeNumber(MediaId language, const LimaString &complement=LimaString())
bool operator()(Automaton::RecognizerMatch &m, AnalysisContent &analysis) const override
zero-ary constraint function : applies the function without a vertex indication (used for actions,...
A representation of a specific entity to store in the annotation graph.
const Automaton::EntityFeatures & getFeatures() const
static const MediaticData & single()
const singleton accessor
LimaString utf8stdstring2limastring(const std::string &src)
uint64_t LimaStringToInt(LimaString s)
bool isFraction(Token *t)
double computeNumberValue(vector< NumberPart > &m, vector< NumberPart >::iterator itBegin, vector< NumberPart >::iterator itEnd, NumberNormalizationMode mode=ADDITIVE)
bool isMultiplierNumber(double n)
Automaton::ConstraintFunctionFactory< NormalizeNumber > NormalizeNumberFactory(NormalizeNumberId)
bool isIntegerWithCommaOrDot(Token *t)
double getValueHeuristic(const LimaString &str, LimaChar sep)
bool isIntegerWithComma(Token *t)
bool isIntegerWithDot(Token *t)
bool testMicroCategory(const std::set< LinguisticCode > *micros, const Common::PropertyCode::PropertyAccessor *microAccessor, const LinguisticCode properties)