LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
transitionUnit.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
/***********************************************************************
7
*
8
* File : transitionUnit.cpp
9
* Author : Romaric Besan�on (besanconr@zoe.cea.fr)
10
* Created on : Fri Oct 04 2002
11
* Copyright : (c) 2002 by CEA
12
* Version : $Id$
13
*
14
************************************************************************/
15
16
17
#include "
transitionUnit.h
"
18
#include "
linguisticProcessing/LinguisticProcessingCommon.h
"
19
#include "
common/Data/strwstrtools.h
"
20
#include <iostream>
21
22
using namespace
std
;
23
using namespace
Lima::LinguisticProcessing::LinguisticAnalysisStructure
;
24
25
namespace
Lima
{
26
namespace
LinguisticProcessing {
27
namespace
Automaton {
28
29
/***********************************************************************/
30
// constructors
31
/***********************************************************************/
32
TransitionUnit::TransitionUnit
():
33
m_keep(true),
34
m_negative(false),
35
m_head(false),
36
m_actionHash(
""
),
37
m_constraints(vector<
Constraint
>(0))
38
{
39
}
40
41
TransitionUnit::TransitionUnit
(
bool
keep,
bool
negative):
42
m_keep(keep),
43
m_negative(negative),
44
m_head(false),
45
m_actionHash(
""
),
46
m_constraints(vector<
Constraint
>(0)) {
47
}
48
49
TransitionUnit::TransitionUnit
(
const
TransitionUnit
& t):
50
m_keep(t.m_keep),
51
m_negative(t.m_negative),
52
m_head(t.m_head),
53
m_id(t.m_id),
54
m_actionHash(t.m_actionHash),
55
m_constraints(t.m_constraints) {
56
}
57
58
/***********************************************************************/
59
// destructor
60
/***********************************************************************/
61
TransitionUnit::~TransitionUnit
() {
62
m_constraints
.clear();
63
}
64
65
/***********************************************************************/
66
// copy
67
/***********************************************************************/
68
TransitionUnit
&
TransitionUnit::operator =
(
const
TransitionUnit
& t) {
69
if
(
this
!= &t) {
70
copyProperties
(t);
71
}
72
return
*
this
;
73
}
74
75
/***********************************************************************/
76
// functions to treat common properties to all kind of transitions
77
/***********************************************************************/
78
void
TransitionUnit::copyProperties
(
const
TransitionUnit
& t) {
79
setKeep
(t.
keep
());
80
setNegative
(t.
negative
());
81
setHead
(t.
head
());
82
setId
(t.
getId
()),
83
setActionHash
(t.
getActionHash
()),
84
m_constraints
.clear();
85
for
(uint64_t i(0); i<t.
numberOfConstraints
(); i++) {
86
addConstraint
(t.
constraint
(i));
87
}
88
}
89
90
bool
TransitionUnit::compareProperties
(
const
TransitionUnit
& t)
const
{
91
if
(
m_id
!= t.
getId
()) {
return
false
; }
92
if
(
m_keep
!= t.
keep
()) {
return
false
; }
93
if
(
m_negative
!= t.
negative
()) {
return
false
; }
94
if
(
m_head
!= t.
head
()) {
return
false
; }
95
if
(
numberOfConstraints
() != t.
numberOfConstraints
()) {
return
false
; }
96
if
(
getActionHash
() != t.
getActionHash
()) {
return
false
; }
97
for
(uint64_t i(0); i<
numberOfConstraints
(); i++) {
98
if
(!(
constraint
(i) == t.
constraint
(i)) ) {
99
return
false
;
100
}
101
}
102
return
true
;
103
}
104
105
/***********************************************************************/
106
// check constraints
107
/***********************************************************************/
108
bool
TransitionUnit::
109
checkConstraints
(
const
AnalysisGraph
& graph,
110
const
LinguisticGraphVertex
& vertex,
111
AnalysisContent
& analysis,
112
ConstraintCheckList
& checklist)
const
{
113
114
std::vector<Constraint>::const_iterator
115
c=
m_constraints
.begin(),
116
c_end=
m_constraints
.end();
117
for
(; c!=c_end; c++) {
118
if
(!(*c).checkConstraint(graph,vertex,analysis,checklist)) {
119
return
false
;
120
}
121
}
122
return
true
;
123
}
124
125
// if stored values resulting from the constraints are to be
126
// removed
127
void
TransitionUnit::popConstraints
(
ConstraintCheckList
& checklist)
const
{
128
for
(uint64_t i(0); i<
numberOfConstraints
(); i++) {
129
if
(
m_constraints
[i].action() ==
PUSH
) {
130
checklist[i].pop();
131
}
132
}
133
}
134
135
/***********************************************************************/
136
// output
137
/***********************************************************************/
138
139
ostream&
operator <<
(ostream& os,
const
TransitionUnit
& t)
140
{
141
// AULOGINIT;
142
// LTRACE << "TransitionUnit::operator<< on transition of type " << t.type();
143
144
if
(t.
negative
()) { os <<
'^'
; }
145
if
(t.
head
()) { os <<
'H'
; }
146
os <<
"'"
<< t.
getId
() <<
"'#"
<< t.
getActionHash
();
147
if
(! t.
keep
()) {
148
os <<
'_'
<< t.
printValue
() <<
'_'
;
149
}
150
else
{
151
os << t.
printValue
();
152
}
153
if
(t.
numberOfConstraints
()) {
154
for
(uint64_t i(0); i<t.
numberOfConstraints
(); i++) {
155
os << t.
constraint
(i);
156
}
157
}
158
159
return
os;
160
}
161
162
QDebug&
operator <<
(QDebug& os,
const
TransitionUnit
& t)
163
{
164
// AULOGINIT;
165
// LTRACE << "TransitionUnit::operator<< on transition of type " << t.type();
166
167
if
(t.
negative
()) { os <<
'^'
; }
168
if
(t.
head
()) { os <<
'H'
; }
169
os <<
"'"
<< t.
getId
() <<
"'#"
<< t.
getActionHash
();
170
if
(! t.
keep
()) {
171
os <<
'_'
<< t.
printValue
() <<
'_'
;
172
}
173
else
{
174
os << t.
printValue
();
175
}
176
if
(t.
numberOfConstraints
()) {
177
os <<
"withConstraints:"
;
178
for
(uint64_t i(0); i<t.
numberOfConstraints
(); i++) {
179
os << t.
constraint
(i);
180
}
181
}
182
183
return
os;
184
}
185
186
}
// namespace end
187
}
// namespace end
188
}
// namespace end
LinguisticGraphVertex
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Definition
LinguisticGraph.h:100
LinguisticProcessingCommon.h
Lima::AnalysisContent
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
Definition
AnalysisContent.h:37
Lima::LinguisticProcessing::Automaton::Constraint
Definition
constraint.h:38
Lima::LinguisticProcessing::Automaton::TransitionUnit
Definition
transitionUnit.h:52
Lima::LinguisticProcessing::Automaton::TransitionUnit::m_keep
bool m_keep
Definition
transitionUnit.h:119
Lima::LinguisticProcessing::Automaton::TransitionUnit::numberOfConstraints
uint64_t numberOfConstraints() const
Definition
transitionUnit.h:148
Lima::LinguisticProcessing::Automaton::TransitionUnit::popConstraints
void popConstraints(ConstraintCheckList &) const
Definition
transitionUnit.cpp:127
Lima::LinguisticProcessing::Automaton::TransitionUnit::printValue
virtual std::string printValue() const
Definition
transitionUnit.h:80
Lima::LinguisticProcessing::Automaton::TransitionUnit::setNegative
void setNegative(const bool)
Definition
transitionUnit.h:136
Lima::LinguisticProcessing::Automaton::TransitionUnit::setHead
void setHead(const bool)
Definition
transitionUnit.h:139
Lima::LinguisticProcessing::Automaton::TransitionUnit::keep
bool keep() const
Definition
transitionUnit.h:133
Lima::LinguisticProcessing::Automaton::TransitionUnit::constraint
const Constraint & constraint(const uint64_t) const
Definition
transitionUnit.h:145
Lima::LinguisticProcessing::Automaton::TransitionUnit::m_head
bool m_head
Definition
transitionUnit.h:122
Lima::LinguisticProcessing::Automaton::TransitionUnit::setActionHash
void setActionHash(const std::string &actionHash)
Definition
transitionUnit.h:143
Lima::LinguisticProcessing::Automaton::TransitionUnit::m_constraints
std::vector< Constraint > m_constraints
Definition
transitionUnit.h:127
Lima::LinguisticProcessing::Automaton::TransitionUnit::checkConstraints
bool checkConstraints(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &vertex, AnalysisContent &analysis, ConstraintCheckList &) const
Definition
transitionUnit.cpp:109
Lima::LinguisticProcessing::Automaton::TransitionUnit::getId
const std::string & getId() const
Definition
transitionUnit.h:140
Lima::LinguisticProcessing::Automaton::TransitionUnit::compareProperties
bool compareProperties(const TransitionUnit &t) const
Definition
transitionUnit.cpp:90
Lima::LinguisticProcessing::Automaton::TransitionUnit::getActionHash
const std::string & getActionHash() const
Definition
transitionUnit.h:142
Lima::LinguisticProcessing::Automaton::TransitionUnit::setKeep
void setKeep(const bool)
Definition
transitionUnit.h:134
Lima::LinguisticProcessing::Automaton::TransitionUnit::operator=
TransitionUnit & operator=(const TransitionUnit &transition)
Definition
transitionUnit.cpp:68
Lima::LinguisticProcessing::Automaton::TransitionUnit::~TransitionUnit
virtual ~TransitionUnit()
Definition
transitionUnit.cpp:61
Lima::LinguisticProcessing::Automaton::TransitionUnit::TransitionUnit
TransitionUnit()
Definition
transitionUnit.cpp:32
Lima::LinguisticProcessing::Automaton::TransitionUnit::m_negative
bool m_negative
Definition
transitionUnit.h:121
Lima::LinguisticProcessing::Automaton::TransitionUnit::setId
void setId(const std::string &id)
Definition
transitionUnit.h:141
Lima::LinguisticProcessing::Automaton::TransitionUnit::head
bool head() const
Definition
transitionUnit.h:137
Lima::LinguisticProcessing::Automaton::TransitionUnit::m_id
std::string m_id
Definition
transitionUnit.h:123
Lima::LinguisticProcessing::Automaton::TransitionUnit::addConstraint
void addConstraint(const Constraint &)
Definition
transitionUnit.h:151
Lima::LinguisticProcessing::Automaton::TransitionUnit::copyProperties
void copyProperties(const TransitionUnit &t)
Definition
transitionUnit.cpp:78
Lima::LinguisticProcessing::Automaton::TransitionUnit::negative
bool negative() const
Definition
transitionUnit.h:135
Lima::LinguisticProcessing::LinguisticAnalysisStructure::AnalysisGraph
An AnalysisData containing a LinguisticGraph with a language and an id.
Definition
AnalysisGraph.h:47
Lima::LinguisticProcessing::Automaton::PUSH
@ PUSH
Definition
constraintCheckList.h:37
Lima::LinguisticProcessing::Automaton::operator<<
std::ostream & operator<<(std::ostream &os, const DFFSPos &x)
Definition
automaton.cpp:371
Lima::LinguisticProcessing::Automaton::ConstraintCheckList
std::vector< ConstraintCheckListElement > ConstraintCheckList
Definition
constraintCheckList.h:105
Lima::LinguisticProcessing::LinguisticAnalysisStructure
Definition
DepTripleDumper.h:45
Lima
NAUTITIA.
Definition
AmosePluginsManager.h:15
std
STL namespace.
strwstrtools.h
transitionUnit.h
lima_linguisticprocessing
src
linguisticProcessing
core
Automaton
transitionUnit.cpp
Generated by
1.9.8