LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
rule.h
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 rule.h
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Tue Oct 15 2002
11 * copyright Copyright (C) 2002 by CEA LIST
12 * Project Automaton
13 *
14 * @brief A rule is composed of a trigger, that can
15 * be a word or a pos (a TransitionUnit) and of two automata for
16 * the contexts around the trigger
17 *
18 ***********************************************************************/
19
20#ifndef RULE_H
21#define RULE_H
22
23#include "AutomatonExport.h"
24#include "automaton.h"
25#include "constraint.h"
29#include <iostream>
30#include <fstream>
31#include <string>
32
33namespace Lima {
34namespace LinguisticProcessing {
35namespace Automaton {
36
38{
39friend class AutomatonReader;
40friend class AutomatonWriter;
41
42 public:
43 Rule();
44/* Rule(const LimaString&, Tchar sep=CHAR_SEP_RULE); */
45 Rule(const Rule&);
46 ~Rule();
47 Rule& operator = (const Rule&);
48
49 // comparison operator (to sort rules by their weight)
50 bool operator<(const Rule& r);
51
52 void reinit();
53
54 // access functions
55 TransitionUnit* getTrigger() const;
56 Automaton const& leftAutomaton() const;
57 Automaton const& rightAutomaton() const;
59 LinguisticCode getLinguisticProperties() const;
60 const LimaString& getNormalizedForm() const;
61 uint64_t numberOfConstraints() const;
62 bool contextual() const;
63 bool negative() const;
64 const std::vector<Constraint>& getActions() const;
65 const std::vector<std::pair<LimaString,Constraint> >& getActionsWithOneArgument() const;
66 double getWeight() const { return m_weight; }
67 const std::string& getRuleId() const { return m_ruleId; }
68
69 void setTrigger(TransitionUnit*);
70 void setLeftAutomaton(const Automaton&);
71 void setRightAutomaton(const Automaton&);
72 void setType(const Common::MediaticData::EntityType&);
73 void setLinguisticProperties(const LinguisticCode&);
74 void setNormalizedForm(const LimaString&);
75 void setNumberOfConstraints(const uint64_t);
76 void incrementNumberOfConstraints();
77 void setContextual(const bool);
78 void setNegative(const bool);
79 void addAction(const Constraint& c);
80 void addAction(const Constraint& c, const LimaString& ruleElemntId);
81 void setWeight(const double& w) { m_weight=w; }
82 void setHasLeftRightConstraint(const bool v)
83 { m_hasLeftRightConstraint=v; }
84 void setRuleId(const std::string& ruleId) { m_ruleId=ruleId; }
85
102 const LinguisticGraphVertex& leftContext,
103 const LinguisticGraphVertex& rightContext,
104 const LinguisticGraphVertex& leftLimit,
105 const LinguisticGraphVertex& rightLimit,
106 AnalysisContent& analysis,
107 RecognizerMatch& leftmatch,
108 RecognizerMatch& rightmatch,
110 ForwardSearch& forward,
111 BackwardSearch& backward,
112 const AutomatonControlParams& controlParams) const;
113
114 bool executeActions(const LinguisticAnalysisStructure::AnalysisGraph& graph,
115 AnalysisContent& analysis,
116 ConstraintCheckList& constraintCheckList,
117 const bool success,
118 RecognizerMatch* result) const;
119
120 // text output
121 friend LIMA_AUTOMATON_EXPORT std::ostream& operator << (std::ostream&, const Rule&);
122 friend LIMA_AUTOMATON_EXPORT QDebug& operator << (QDebug&, const Rule&);
123
124 protected:
125 TransitionUnit* m_trigger; // the trigger
126 Automaton m_left; // left context (i.e. preceding context)
127 Automaton m_right; // right context (i.e. following context)
128 Common::MediaticData::EntityType m_type; // type of the expression
129 LinguisticCode m_lingProp; // linguistic properties associated
130 // to the recognized expression
131 LimaString m_normalizedForm; // normalized form of the expression
132 uint64_t m_numberOfConstraints; // possible agreement constraints
133 bool m_contextual; // is the expression ambiguous or not (ambiguity must
134 // be solved by context if it is the case)
135
136 bool m_negative; // the rule is negative
137 bool m_hasLeftRightConstraint; // the rule has at least one
138 // binary constraint that deals with left AND right parts
139 std::vector<Constraint> m_actions;
140 std::vector<std::pair<LimaString,Constraint> > m_actionsWithOneArgument;
141
142 double m_weight; // weight of the rule
143 std::string m_ruleId; // id of the rule
144
145 // private functions
146 //**********************************************************************
147 // helper functions for constructors and destructors
148 void init();
149 void copy(const Rule& r);
150 void freeMem();
151
152};
153
154/***********************************************************************/
155// inline access functions
156/***********************************************************************/
157inline TransitionUnit* Rule::getTrigger() const { return m_trigger; }
158inline Automaton const& Rule::leftAutomaton() const { return m_left; }
159inline Automaton const& Rule::rightAutomaton() const { return m_right; }
163inline const LimaString& Rule::getNormalizedForm() const {
164 return m_normalizedForm; }
165inline uint64_t Rule::numberOfConstraints() const {
166 return m_numberOfConstraints; }
167inline const std::vector<Constraint>& Rule::getActions() const {
168 return m_actions;
169}
170inline const std::vector<std::pair<LimaString,Constraint> >& Rule::getActionsWithOneArgument() const {
172}
173
174inline bool Rule::contextual() const { return m_contextual; }
175inline void Rule::setContextual(const bool c) { m_contextual = c; }
176
177inline bool Rule::negative() const { return m_negative; }
178inline void Rule::setNegative(const bool c) { m_negative = c; }
179inline void Rule::setNumberOfConstraints(const uint64_t n) {
181}
186inline void Rule::setLeftAutomaton(const Automaton& a) { m_left=a; }
187inline void Rule::setRightAutomaton(const Automaton& a) { m_right=a; }
190 m_lingProp=l;
191}
192inline void Rule::setNormalizedForm(const LimaString& s) {
194}
195inline void Rule::addAction(const Constraint& c) {
196m_actions.push_back(c);
197}
198inline void Rule::addAction(const Constraint& c, const LimaString& id) {
199 m_actionsWithOneArgument.push_back(std::pair<LimaString,Constraint>(id,c));
200}
201
202} // namespace end
203} // namespace end
204} // namespace end
205
206#endif
#define LIMA_AUTOMATON_EXPORT
QDebug & operator<<(QDebug &qd, const std::string &str)
Definition QsLog.cpp:39
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
␈rief a class for control parameters for the search using the automata
Definition automaton.h:44
␈rief A class for the description of automata
Definition automaton.h:87
Automaton const & leftAutomaton() const
Definition rule.h:158
Automaton const & rightAutomaton() const
Definition rule.h:159
const std::string & getRuleId() const
Definition rule.h:67
void setRightAutomaton(const Automaton &)
Definition rule.h:187
std::vector< Constraint > m_actions
Definition rule.h:139
void addAction(const Constraint &c)
Definition rule.h:195
LinguisticCode getLinguisticProperties() const
Definition rule.h:161
void setLeftAutomaton(const Automaton &)
Definition rule.h:186
void setType(const Common::MediaticData::EntityType &)
Definition rule.h:188
void setRuleId(const std::string &ruleId)
Definition rule.h:84
void setLinguisticProperties(const LinguisticCode &)
Definition rule.h:189
void setWeight(const double &w)
Definition rule.h:81
const LimaString & getNormalizedForm() const
Definition rule.h:163
void setNormalizedForm(const LimaString &)
Definition rule.h:192
void setNumberOfConstraints(const uint64_t)
Definition rule.h:179
Common::MediaticData::EntityType m_type
Definition rule.h:128
const std::vector< Constraint > & getActions() const
Definition rule.h:167
TransitionUnit * getTrigger() const
Definition rule.h:157
void setTrigger(TransitionUnit *)
Definition rule.h:185
std::vector< std::pair< LimaString, Constraint > > m_actionsWithOneArgument
Definition rule.h:140
Common::MediaticData::EntityType getType() const
Definition rule.h:160
const std::vector< std::pair< LimaString, Constraint > > & getActionsWithOneArgument() const
Definition rule.h:170
void setHasLeftRightConstraint(const bool v)
Definition rule.h:82
An AnalysisData containing a LinguisticGraph with a language and an id.
std::vector< ConstraintCheckListElement > ConstraintCheckList
NAUTITIA.
QString LimaString
Definition LimaString.h:33
static bool operator<(const QStringView &entityStr, const TextHtmlEntity &entity)