Awali
Another Weighted Automata library
description_types.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef DYN_CONTEXT_DESCRIPTION_TYPES_HH
18 #define DYN_CONTEXT_DESCRIPTION_TYPES_HH
19 
20 #include<vector>
21 #include<memory>
22 
23 namespace awali {
24 namespace dyn {
25 namespace context {
26 
30 
31  using context_description = std::shared_ptr<context_description_impl>;
32  using labelset_description = std::shared_ptr<labelset_description_impl>;
33  using weightset_description = std::shared_ptr<weightset_description_impl>;
34 
35 
36  enum class CTypes {
38  };
39 
40  struct WTypes {
41  static const int RATEXP = -1;
42  static const int SERIES = -2;
43  static const int TUPLE = -3;
44  };
45 
48  std::vector<std::string> alphabet = {};
49  std::vector<int> int_alphabet = {};
50  std::vector<labelset_description> children_ = {};
51 
52  inline bool operator==(labelset_description_impl const& other) const {
53  bool b = type_ == other.type_
54  && alphabet == other.alphabet
55  && int_alphabet == other.int_alphabet
56  && (children_.size() == other.children_.size());
57  if (!b)
58  return b;
59  for (size_t i = 0; i < children_.size(); ++i)
60  if ( !(*(children_[i]) == *(other.children_[i])) )
61  return false;
62  return true;
63  }
64 
65  inline bool is_lao() const { return (type_ == CTypes::ONESET); }
66  inline bool is_lan() const { return (type_ == CTypes::NULLABLE); }
67  inline bool is_lat() const { return (type_ == CTypes::TUPLE);}
68  inline bool is_lal() const {
70  inline bool is_law() const {
71  return (type_ == CTypes::WORDSET || type_ == CTypes::INTWORDSET );}
72 
73  inline bool letters_are_int() const {
75  return true;
76  if(is_lan() || is_lan()) {
77  for (auto child : children_)
78  if (!child->letters_are_int())
79  return false;
80  return true;
81  }
82  return false;
83  }
84 
85  inline bool letters_are_char() const {
87  return true;
88  if(is_lan() || is_lan()) {
89  for (auto child : children_)
90  if (!child->letters_are_int())
91  return false;
92  return true;
93  }
94  return false;
95  }
96 
97  size_t tape_number() const {
98  if (!is_lat())
99  return 1;
100  return children_.size();
101  }
102 
103  };
104 
108 
109  inline labelset_description labelset() const { return ls_; }
110  inline weightset_description weightset() const { return ws_; }
111 
112  inline bool operator==(context_description_impl const& other) const {
113  return ls_ == other.labelset() && ws_ == other.weightset(); }
114  };
115 
116 
118  int type_;
120  std::vector<weightset_description> children_ = {};
121  int characteristic = -1;
122  inline bool operator==(weightset_description_impl const& other) const {
123  if (!( type_ == other.type_
124  && ( (ct_ == nullptr && other.ct_ == nullptr)
125  || *ct_ == *(other.ct_))
126  && children_.size() == other.children_.size()
127  && characteristic == other.characteristic))
128  return false;
129  for (size_t i = 0; i < children_.size(); ++i)
130  if ( !(*(children_[i]) == *(other.children_[i])) )
131  return false;
132  return true;
133  }
134  };
135 
136  //***********************
137 
138  inline
140  return std::make_shared<labelset_description_impl>();
141  }
142 
143  inline
145  return std::make_shared<weightset_description_impl>();
146  }
147 
148  inline
150  return std::make_shared<context_description_impl>();
151  }
152 
153  //**************************
154 
155 }}} //end of namespaces awali::dyn::context, awali::dyn, and awali
156 
157 #endif
std::shared_ptr< weightset_description_impl > weightset_description
Definition: description_types.hh:33
context_description make_context_description()
Definition: description_types.hh:149
CTypes
Definition: description_types.hh:36
std::shared_ptr< labelset_description_impl > labelset_description
Definition: description_types.hh:32
labelset_description make_labelset_description()
Definition: description_types.hh:139
std::shared_ptr< context_description_impl > context_description
Definition: description_types.hh:31
weightset_description make_weightset_description()
Definition: description_types.hh:144
Main namespace of Awali.
Definition: ato.hh:22
Definition: description_types.hh:40
static const int RATEXP
Definition: description_types.hh:41
static const int TUPLE
Definition: description_types.hh:43
static const int SERIES
Definition: description_types.hh:42
Definition: description_types.hh:105
weightset_description weightset() const
Definition: description_types.hh:110
bool operator==(context_description_impl const &other) const
Definition: description_types.hh:112
labelset_description ls_
Definition: description_types.hh:106
labelset_description labelset() const
Definition: description_types.hh:109
weightset_description ws_
Definition: description_types.hh:107
Definition: description_types.hh:46
bool letters_are_char() const
Definition: description_types.hh:85
bool is_lat() const
Definition: description_types.hh:67
std::vector< labelset_description > children_
Definition: description_types.hh:50
size_t tape_number() const
Definition: description_types.hh:97
bool is_lao() const
Definition: description_types.hh:65
bool is_lan() const
Definition: description_types.hh:66
bool is_law() const
Definition: description_types.hh:70
bool letters_are_int() const
Definition: description_types.hh:73
bool operator==(labelset_description_impl const &other) const
Definition: description_types.hh:52
CTypes type_
Definition: description_types.hh:47
bool is_lal() const
Definition: description_types.hh:68
std::vector< int > int_alphabet
Definition: description_types.hh:49
std::vector< std::string > alphabet
Definition: description_types.hh:48
Definition: description_types.hh:117
bool operator==(weightset_description_impl const &other) const
Definition: description_types.hh:122
int type_
Definition: description_types.hh:118
int characteristic
Definition: description_types.hh:121
std::vector< weightset_description > children_
Definition: description_types.hh:120
context_description ct_
Definition: description_types.hh:119