LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Condition.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// NAUTITIA
7//
8// jys 14-JUL-2002
9//
10// Condition is the class which groups various static
11// conditions associated with a Transition. There are 3 types
12// of static conditions :
13// o value of characters before the current one in the string,
14// o value of characters after the current one in the string,
15// o value of inner automaton return status.
16// Input text is translated into characters class string.
17// Characters class are coded using printable character, so,
18// they can be maniplated as String.
19
20#include "Condition.h"
21
22#include "Events.h"
25
26using namespace Lima::Common::Misc;
27
28namespace Lima
29{
30namespace LinguisticProcessing
31{
32namespace FlatTokenizer
33{
34
35Condition::Condition(std::shared_ptr<CharChart> chart) :
36_before(),
37_after(),
38_status(chart)
39{
40}
41
45
46// for run-time usage. Within a context, a condition is
47// fulfilled or not.
48bool Condition::isFulfilled(const Text& text) const
49{
50#ifdef DEBUG_LP
52 LDEBUG << "| | | testing if condition is fullfilled with "
53 << _before.size() << " events before and "
54 << _after.size() << " events after.";
55#endif
56 try {
57 int currentIndex = 0;
58 for (uint64_t b = 0; b < _before.size(); b++)
59 {
60 LimaChar c;
61 if (!(((currentIndex == 0) && _before[b].isRecognized(c))||(_before[b].isRecognized(text[--currentIndex]))))
62 {
63#ifdef DEBUG_LP
64 LDEBUG << "| | | before condition is not fullfilled";
65#endif
66 return false;
67 }
68 }
69 currentIndex = 0;
70 for (uint64_t a = 0 ; a < _after.size(); a++)
71 {
72 if (!(_after[a].isRecognized(text[++currentIndex])))
73 {
74#ifdef DEBUG_LP
75 LDEBUG << "| | | after condition is not fullfilled";
76#endif
77 return false;
78 }
79 }
80 }
82 {
83#ifdef DEBUG_LP
85 LDEBUG << "Condition tried to reach out of text bounds";
86#endif
87 return false;
88 }
89#ifdef DEBUG_LP
90 LDEBUG << "| | | condition is fullfilled";
91#endif
92 return true;
93}
94
95} //namespace FlatTokenizer
96} // namespace LinguisticProcessing
97} // namespace Lima
#define LDEBUG
Definition LimaCommon.h:157
#define TOKENIZERLOGINIT
Condition(std::shared_ptr< CharChart > chart)
Definition Condition.cpp:35
NAUTITIA.
QChar LimaChar
Definition LimaString.h:30