HFST - Helsinki Finite-State Transducer Technology - C++ API  version 3.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HfstTransition.h
Go to the documentation of this file.
1 // Copyright (c) 2016 University of Helsinki
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 3 of the License, or (at your option) any later version.
7 // See the file COPYING included with this distribution for more
8 // information.
9 
10 #ifndef _HFST_TRANSITION_H_
11 #define _HFST_TRANSITION_H_
12 
16 #include "../HfstDataTypes.h"
17 
18 #include "../hfstdll.h"
19 
20 namespace hfst {
21 
22  namespace implementations {
23 
33  template <class C> class HfstTransition
34  {
35  protected:
36  HfstState target_state; // the state where the transition leads
37  C transition_data; // the actual transition data
38 
39  /* Get the number that represents the symbol in the transition data. */
40  static unsigned int get_symbol_number
41  (const typename C::SymbolType &symbol) {
42  return C::get_symbol_number(symbol);
43  }
44 
45  public:
46 
50  HFSTDLL HfstTransition(): target_state(0)
51  {}
52 
56  typename C::SymbolType isymbol,
57  typename C::SymbolType osymbol,
58  typename C::WeightType weight):
59  target_state(s), transition_data(isymbol, osymbol, weight)
60  {}
61 
62  HFSTDLL HfstTransition(HfstState s,
63  unsigned int inumber,
64  unsigned int onumber,
65  typename C::WeightType weight,
66  bool foo):
67  target_state(s), transition_data(inumber, onumber, weight)
68  { (void)foo; }
69 
71  HFSTDLL HfstTransition(const HfstTransition<C> &another):
72  target_state(another.target_state),
73  transition_data(another.transition_data)
74  {}
75 
76  HFSTDLL ~HfstTransition() {}
77 
80  HFSTDLL bool operator<(const HfstTransition<C> &another) const {
81  if (target_state == another.target_state)
82  return (transition_data < another.transition_data);
83  return (target_state < another.target_state);
84  }
85 
88  HFSTDLL void operator=(const HfstTransition<C> &another) {
89  target_state = another.target_state;
90  transition_data = another.transition_data;
91  }
92 
94  HFSTDLL HfstState get_target_state() const {
95  return target_state;
96  }
97 
99  HFSTDLL const C & get_transition_data() const {
100  return transition_data;
101  }
102 
104  HFSTDLL typename C::SymbolType get_input_symbol() const {
105  return transition_data.get_input_symbol();
106  }
107 
109  HFSTDLL typename C::SymbolType get_output_symbol() const {
110  return transition_data.get_output_symbol();
111  }
112 
113  /* Get the internal input number of the transition. */
114  HFSTDLL unsigned int get_input_number() const {
115  return transition_data.get_input_number();
116  }
117 
118  /* Get the internal output number of the transition. */
119  HFSTDLL unsigned int get_output_number() const {
120  return transition_data.get_output_number();
121  }
122 
124  HFSTDLL typename C::WeightType get_weight() const {
125  return transition_data.get_weight();
126  }
127 
129  HFSTDLL void set_weight(float w) {
130  transition_data.set_weight(w);
131  }
132 
133  friend class ComposeIntersectFst;
134  friend class ComposeIntersectLexicon;
135  friend class ComposeIntersectRule;
136  friend class ComposeIntersectRulePair;
137  };
138 
145  typedef HfstTransition<HfstTropicalTransducerTransitionData>
147 
148  // TODO: remove?
149  typedef HfstTransition<HfstFastTransitionData> HfstFastTransition;
150 
151  }
152 
153 }
154 
155 #endif // _HFST_TRANSITION_H_
HFSTDLL C::WeightType get_weight() const
Get the weight of the transition.
Definition: HfstTransition.h:124
unsigned int HfstState
The number of a state in an HfstTransitionGraph.
Definition: HfstDataTypes.h:119
HFSTDLL HfstState get_target_state() const
Get the target state of the transition.
Definition: HfstTransition.h:94
HFSTDLL const C & get_transition_data() const
Get the transition data of the transition.
Definition: HfstTransition.h:99
HFSTDLL C::SymbolType get_output_symbol() const
Get the output symbol of the transition.
Definition: HfstTransition.h:109
HFSTDLL void set_weight(float w)
Set the weight of the transition.
Definition: HfstTransition.h:129
HFSTDLL HfstTransition()
Create a transition leading to state zero with input and output symbols and weight as given by defaul...
Definition: HfstTransition.h:50
HFSTDLL C::SymbolType get_input_symbol() const
Get the input symbol of the transition.
Definition: HfstTransition.h:104
HFSTDLL HfstTransition(const HfstTransition< C > &another)
Create a deep copy of transition another.
Definition: HfstTransition.h:71
HfstTransition< HfstTropicalTransducerTransitionData > HfstBasicTransition
An HfstTransition with transition data of type HfstTropicalTransducerTransitionData.
Definition: HfstDataTypes.h:121
HFSTDLL HfstTransition(HfstState s, typename C::SymbolType isymbol, typename C::SymbolType osymbol, typename C::WeightType weight)
Create a transition leading to state s with input symbol isymbol, output_symbol osymbol and weight we...
Definition: HfstTransition.h:55
A transition that consists of a target state and transition data represented by class C...
Definition: HfstDataTypes.h:121
HFSTDLL void operator=(const HfstTransition< C > &another)
Assign this transition the same value as transition another.
Definition: HfstTransition.h:88