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
"
20
#include "
common/misc/Exceptions.h
"
21
22
using namespace
Lima::Common::Misc
;
23
24
namespace
Lima
25
{
26
namespace
LinguisticProcessing
27
{
28
namespace
FlatTokenizer
29
{
30
31
32
State::State
(
const
LimaString
& name,
Automaton
& automaton) :
33
m_automaton(automaton),
34
m_transitions(),
35
m_name(name)
36
{
37
}
38
39
State::~State
()
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
51
const
State
*
State::run
(
Text
& text)
const
52
{
53
#ifdef DEBUG_LP
54
TOKENIZERLOGINIT
;
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
Exceptions.h
LDEBUG
#define LDEBUG
Definition
LimaCommon.h:157
TOKENIZERLOGINIT
#define TOKENIZERLOGINIT
Definition
LinguisticProcessingCommon.h:97
State.h
Transition.h
Lima::LinguisticProcessing::FlatTokenizer::Automaton
Definition
Automaton.h:38
Lima::LinguisticProcessing::FlatTokenizer::State
Definition
State.h:37
Lima::LinguisticProcessing::FlatTokenizer::State::run
const State * run(Text &text) const
Definition
State.cpp:51
Lima::LinguisticProcessing::FlatTokenizer::State::name
const LimaString & name() const
Definition
State.h:46
Lima::LinguisticProcessing::FlatTokenizer::State::State
State(const Lima::LimaString &name, Automaton &automaton)
Definition
State.cpp:32
Lima::LinguisticProcessing::FlatTokenizer::State::~State
virtual ~State()
Definition
State.cpp:39
Lima::LinguisticProcessing::FlatTokenizer::Text
Definition
Text.h:36
Lima::LinguisticProcessing::FlatTokenizer::Text::position
int position() const
Definition
Text.cpp:102
Lima::LinguisticProcessing::FlatTokenizer::Text::currentChar
Lima::LimaChar currentChar() const
Definition
Text.cpp:83
Lima::LinguisticProcessing::FlatTokenizer::Transition
Definition
Transition.h:52
Lima::LinguisticProcessing::FlatTokenizer::Transition::run
const State * run(Text &text) const
Definition
Transition.cpp:95
Lima::LinguisticProcessing::FlatTokenizer::Transition::events
const Events & events() const
Definition
Transition.h:105
Lima::Common::Misc
Definition
genericDocumentProperties.cpp:29
Lima::Common::Misc::limastring2utf8stdstring
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
Definition
strwstrtools.cpp:221
Lima
NAUTITIA.
Definition
AmosePluginsManager.h:15
Lima::LimaString
QString LimaString
Definition
LimaString.h:33
lima_linguisticprocessing
src
linguisticProcessing
core
FlatTokenizer
State.cpp
Generated by
1.9.8