LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
State.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 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 23-JUL-2002
9//
10// State is the recovery point for automatons. State is a
11// collection of Transition and eventually inner automatons.
12// Inner automatons are called once when state is entered at
13// first time. Inner automatons are called before checking
14// transition. Inner automatons can return a status which
15// ccan be used by transitions.
16
17#include "State.h"
18
19#include "Transition.h"
21
22using namespace Lima::Common::Misc;
23
24namespace Lima
25{
26namespace LinguisticProcessing
27{
28namespace FlatTokenizer
29{
30
31
32State::State(const LimaString& name, Automaton& automaton) :
33 m_automaton(automaton),
34 m_transitions(),
35 m_name(name)
36{
37}
38
40{
41 for (std::list< Transition* >::iterator it = m_transitions.begin();
42 it != m_transitions.end(); it++)
43 {
44 delete (*it); (*it) = 0;
45 }
46 m_transitions.clear();
47}
48
49// Run-Time.
50// Returns true if a transition was founs open
51const State* State::run(Text& text) const
52{
53#ifdef DEBUG_LP
55 LDEBUG << "--------Entering State " << limastring2utf8stdstring(name());
56#endif
57// Lima::LimaChar returnedStatus;
58// Lima::LimaChar innerStatus = 0;
59
60 std::list< Transition* >::const_iterator it = m_transitions.begin();
61 std::list< Transition* >::const_iterator it_end = m_transitions.end();
62 for (; it != it_end; it++)
63 {
64 const Transition* transition = (*it);
65 if (transition->events().size() == 0)
66 {
67#ifdef DEBUG_LP
68 LDEBUG << "| Empty transition... continuing.";
69#endif
70 continue;
71 }
72
73#ifdef DEBUG_LP
74 LDEBUG << "| state " << limastring2utf8stdstring(name())
75 << " running transition first event="
76 << (transition->events()[0]==0?"":limastring2utf8stdstring(transition->events()[0]->id()))
77 <<" / '"
78 << (transition->events()[0]==0?"":limastring2utf8stdstring(transition->events()[0]->name()))
79 << "'";
80 LDEBUG << "| (text position " << text.position() << " ; char: '" << Common::Misc::limastring2utf8stdstring(LimaString()+text.currentChar()) << "')";
81#endif
82 const State* toState = transition->run(text);
83 if (toState != 0)
84 {
85#ifdef DEBUG_LP
86 LDEBUG << "| transition from " << Common::Misc::limastring2utf8stdstring(this->name()) << " to " << Common::Misc::limastring2utf8stdstring(transition-> nextStateName()) << " succeeded.";
87 LDEBUG << "| text position is now " << text.position() << " ; char: '" << Common::Misc::limastring2utf8stdstring(LimaString()+text.currentChar()) << "'";
88#endif
89 return toState;
90 }
91 }
92#ifdef DEBUG_LP
93 LDEBUG << "--------All transitions failed: state failed";
94#endif
95 return 0;
96}
97
98} //namespace FlatTokenizer
99} // namespace LinguisticProcessing
100} // namespace Lima
#define LDEBUG
Definition LimaCommon.h:157
#define TOKENIZERLOGINIT
const State * run(Text &text) const
Definition State.cpp:51
State(const Lima::LimaString &name, Automaton &automaton)
Definition State.cpp:32
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
NAUTITIA.
QString LimaString
Definition LimaString.h:33