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"
20#include <iostream>
21
22using namespace std;
24
25namespace Lima {
26namespace LinguisticProcessing {
27namespace Automaton {
28
29/***********************************************************************/
30// constructors
31/***********************************************************************/
33 m_keep(true),
34 m_negative(false),
35 m_head(false),
36 m_actionHash(""),
37 m_constraints(vector<Constraint>(0))
38{
39}
40
41TransitionUnit::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
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/***********************************************************************/
64
65/***********************************************************************/
66// copy
67/***********************************************************************/
69 if (this != &t) {
71 }
72 return *this;
73}
74
75/***********************************************************************/
76// functions to treat common properties to all kind of transitions
77/***********************************************************************/
79 setKeep(t.keep());
81 setHead(t.head());
82 setId(t.getId()),
84 m_constraints.clear();
85 for (uint64_t i(0); i<t.numberOfConstraints(); i++) {
87 }
88}
89
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/***********************************************************************/
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
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
139ostream& 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
162QDebug& 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
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
const Constraint & constraint(const uint64_t) const
void setActionHash(const std::string &actionHash)
bool checkConstraints(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &vertex, AnalysisContent &analysis, ConstraintCheckList &) const
bool compareProperties(const TransitionUnit &t) const
TransitionUnit & operator=(const TransitionUnit &transition)
An AnalysisData containing a LinguisticGraph with a language and an id.
std::ostream & operator<<(std::ostream &os, const DFFSPos &x)
std::vector< ConstraintCheckListElement > ConstraintCheckList
NAUTITIA.
STL namespace.