FST  openfst-1.8.3
OpenFst Library
properties.h
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 //
18 // FST property bits.
19 
20 #ifndef FST_PROPERTIES_H_
21 #define FST_PROPERTIES_H_
22 
23 #include <sys/types.h>
24 
25 #include <cstddef>
26 #include <cstdint>
27 #include <vector>
28 
29 #include <fst/compat.h>
30 #include <fst/log.h>
31 #include <string_view>
32 
33 namespace fst {
34 
35 // The property bits here assert facts about an FST. If individual bits are
36 // added, then the composite properties below, the property functions and
37 // property names in properties.cc, and TestProperties() in test-properties.h
38 // should be updated.
39 
40 // BINARY PROPERTIES
41 //
42 // For each property below, there is a single bit. If it is set, the property is
43 // true. If it is not set, the property is false.
44 
45 // The Fst is an ExpandedFst.
46 inline constexpr uint64_t kExpanded = 0x0000000000000001ULL;
47 
48 // The Fst is a MutableFst.
49 inline constexpr uint64_t kMutable = 0x0000000000000002ULL;
50 
51 // An error was detected while constructing/using the FST.
52 inline constexpr uint64_t kError = 0x0000000000000004ULL;
53 
54 // TRINARY PROPERTIES
55 //
56 // For each of these properties below there is a pair of property bits, one
57 // positive and one negative. If the positive bit is set, the property is true.
58 // If the negative bit is set, the property is false. If neither is set, the
59 // property has unknown value. Both should never be simultaneously set. The
60 // individual positive and negative bit pairs should be adjacent with the
61 // positive bit at an odd and lower position.
62 
63 // ilabel == olabel for each arc.
64 inline constexpr uint64_t kAcceptor = 0x0000000000010000ULL;
65 // ilabel != olabel for some arc.
66 inline constexpr uint64_t kNotAcceptor = 0x0000000000020000ULL;
67 
68 // ilabels unique leaving each state.
69 inline constexpr uint64_t kIDeterministic = 0x0000000000040000ULL;
70 // ilabels not unique leaving some state.
71 inline constexpr uint64_t kNonIDeterministic = 0x0000000000080000ULL;
72 
73 // olabels unique leaving each state.
74 inline constexpr uint64_t kODeterministic = 0x0000000000100000ULL;
75 // olabels not unique leaving some state.
76 inline constexpr uint64_t kNonODeterministic = 0x0000000000200000ULL;
77 
78 // FST has input/output epsilons.
79 inline constexpr uint64_t kEpsilons = 0x0000000000400000ULL;
80 // FST has no input/output epsilons.
81 inline constexpr uint64_t kNoEpsilons = 0x0000000000800000ULL;
82 
83 // FST has input epsilons.
84 inline constexpr uint64_t kIEpsilons = 0x0000000001000000ULL;
85 // FST has no input epsilons.
86 inline constexpr uint64_t kNoIEpsilons = 0x0000000002000000ULL;
87 
88 // FST has output epsilons.
89 inline constexpr uint64_t kOEpsilons = 0x0000000004000000ULL;
90 // FST has no output epsilons.
91 inline constexpr uint64_t kNoOEpsilons = 0x0000000008000000ULL;
92 
93 // ilabels sorted wrt < for each state.
94 inline constexpr uint64_t kILabelSorted = 0x0000000010000000ULL;
95 // ilabels not sorted wrt < for some state.
96 inline constexpr uint64_t kNotILabelSorted = 0x0000000020000000ULL;
97 
98 // olabels sorted wrt < for each state.
99 inline constexpr uint64_t kOLabelSorted = 0x0000000040000000ULL;
100 // olabels not sorted wrt < for some state.
101 inline constexpr uint64_t kNotOLabelSorted = 0x0000000080000000ULL;
102 
103 // Non-trivial arc or final weights.
104 inline constexpr uint64_t kWeighted = 0x0000000100000000ULL;
105 // Only trivial arc and final weights.
106 inline constexpr uint64_t kUnweighted = 0x0000000200000000ULL;
107 
108 // FST has cycles.
109 inline constexpr uint64_t kCyclic = 0x0000000400000000ULL;
110 // FST has no cycles.
111 inline constexpr uint64_t kAcyclic = 0x0000000800000000ULL;
112 
113 // FST has cycles containing the initial state.
114 inline constexpr uint64_t kInitialCyclic = 0x0000001000000000ULL;
115 // FST has no cycles containing the initial state.
116 inline constexpr uint64_t kInitialAcyclic = 0x0000002000000000ULL;
117 
118 // FST is topologically sorted.
119 inline constexpr uint64_t kTopSorted = 0x0000004000000000ULL;
120 // FST is not topologically sorted.
121 inline constexpr uint64_t kNotTopSorted = 0x0000008000000000ULL;
122 
123 // All states reachable from the initial state.
124 inline constexpr uint64_t kAccessible = 0x0000010000000000ULL;
125 // Not all states reachable from the initial state.
126 inline constexpr uint64_t kNotAccessible = 0x0000020000000000ULL;
127 
128 // All states can reach a final state.
129 inline constexpr uint64_t kCoAccessible = 0x0000040000000000ULL;
130 // Not all states can reach a final state.
131 inline constexpr uint64_t kNotCoAccessible = 0x0000080000000000ULL;
132 
133 // If NumStates() > 0, then state 0 is initial, state NumStates() - 1 is final,
134 // there is a transition from each non-final state i to state i + 1, and there
135 // are no other transitions.
136 inline constexpr uint64_t kString = 0x0000100000000000ULL;
137 
138 // Not a string FST.
139 inline constexpr uint64_t kNotString = 0x0000200000000000ULL;
140 
141 // FST has at least one weighted cycle.
142 inline constexpr uint64_t kWeightedCycles = 0x0000400000000000ULL;
143 
144 // FST has no weighted cycles. Any cycles that may be present are unweighted.
145 inline constexpr uint64_t kUnweightedCycles = 0x0000800000000000ULL;
146 
147 // COMPOSITE PROPERTIES
148 
149 // Properties of an empty machine.
150 inline constexpr uint64_t kNullProperties =
151  kAcceptor | kIDeterministic | kODeterministic | kNoEpsilons | kNoIEpsilons |
152  kNoOEpsilons | kILabelSorted | kOLabelSorted | kUnweighted | kAcyclic |
153  kInitialAcyclic | kTopSorted | kAccessible | kCoAccessible | kString |
155 
156 // Properties of a string FST compiled into a string.
157 inline constexpr uint64_t kCompiledStringProperties =
158  kAcceptor | kString | kUnweighted | kIDeterministic | kODeterministic |
159  kILabelSorted | kOLabelSorted | kAcyclic | kInitialAcyclic |
160  kUnweightedCycles | kTopSorted | kAccessible | kCoAccessible;
161 
162 // Properties that are preserved when an FST is copied.
163 inline constexpr uint64_t kCopyProperties =
164  kError | kAcceptor | kNotAcceptor | kIDeterministic | kNonIDeterministic |
165  kODeterministic | kNonODeterministic | kEpsilons | kNoEpsilons |
166  kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons | kILabelSorted |
167  kNotILabelSorted | kOLabelSorted | kNotOLabelSorted | kWeighted |
168  kUnweighted | kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic |
169  kTopSorted | kNotTopSorted | kAccessible | kNotAccessible | kCoAccessible |
170  kNotCoAccessible | kString | kNotString | kWeightedCycles |
172 
173 // Properties that are intrinsic to the FST.
174 inline constexpr uint64_t kIntrinsicProperties =
175  kExpanded | kMutable | kAcceptor | kNotAcceptor | kIDeterministic |
176  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
177  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
178  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
179  kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic |
180  kInitialAcyclic | kTopSorted | kNotTopSorted | kAccessible |
181  kNotAccessible | kCoAccessible | kNotCoAccessible | kString | kNotString |
182  kWeightedCycles | kUnweightedCycles;
183 
184 // Properties that are (potentially) extrinsic to the FST.
185 inline constexpr uint64_t kExtrinsicProperties = kError;
186 
187 // Properties that are preserved when an FST start state is set.
188 inline constexpr uint64_t kSetStartProperties =
189  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
190  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
191  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
192  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
193  kWeighted | kUnweighted | kCyclic | kAcyclic | kTopSorted | kNotTopSorted |
194  kCoAccessible | kNotCoAccessible | kWeightedCycles | kUnweightedCycles;
195 
196 // Properties that are preserved when an FST final weight is set.
197 inline constexpr uint64_t kSetFinalProperties =
198  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
199  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
200  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
201  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
202  kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic | kTopSorted |
203  kNotTopSorted | kAccessible | kNotAccessible | kWeightedCycles |
205 
206 // Properties that are preserved when an FST state is added.
207 inline constexpr uint64_t kAddStateProperties =
208  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
209  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
210  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
211  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
212  kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic |
213  kInitialAcyclic | kTopSorted | kNotTopSorted | kNotAccessible |
214  kNotCoAccessible | kNotString | kWeightedCycles | kUnweightedCycles;
215 
216 // Properties that are preserved when an FST arc is added.
217 inline constexpr uint64_t kAddArcProperties =
218  kExpanded | kMutable | kError | kNotAcceptor | kNonIDeterministic |
219  kNonODeterministic | kEpsilons | kIEpsilons | kOEpsilons |
220  kNotILabelSorted | kNotOLabelSorted | kWeighted | kCyclic | kInitialCyclic |
221  kNotTopSorted | kAccessible | kCoAccessible | kWeightedCycles;
222 
223 // Properties that are preserved when an FST arc is set.
224 inline constexpr uint64_t kSetArcProperties = kExpanded | kMutable | kError;
225 
226 // Properties that are preserved when FST states are deleted.
227 inline constexpr uint64_t kDeleteStatesProperties =
228  kExpanded | kMutable | kError | kAcceptor | kIDeterministic |
229  kODeterministic | kNoEpsilons | kNoIEpsilons | kNoOEpsilons |
230  kILabelSorted | kOLabelSorted | kUnweighted | kAcyclic | kInitialAcyclic |
231  kTopSorted | kUnweightedCycles;
232 
233 // Properties that are preserved when FST arcs are deleted.
234 inline constexpr uint64_t kDeleteArcsProperties =
235  kExpanded | kMutable | kError | kAcceptor | kIDeterministic |
236  kODeterministic | kNoEpsilons | kNoIEpsilons | kNoOEpsilons |
237  kILabelSorted | kOLabelSorted | kUnweighted | kAcyclic | kInitialAcyclic |
238  kTopSorted | kNotAccessible | kNotCoAccessible | kUnweightedCycles;
239 
240 // Properties that are preserved when an FST's states are reordered.
241 inline constexpr uint64_t kStateSortProperties =
242  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
243  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
244  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
245  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
246  kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic |
247  kInitialAcyclic | kAccessible | kNotAccessible | kCoAccessible |
248  kNotCoAccessible | kWeightedCycles | kUnweightedCycles;
249 
250 // Properties that are preserved when an FST's arcs are reordered.
251 inline constexpr uint64_t kArcSortProperties =
252  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
253  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
254  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
255  kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic |
256  kInitialAcyclic | kTopSorted | kNotTopSorted | kAccessible |
257  kNotAccessible | kCoAccessible | kNotCoAccessible | kString | kNotString |
258  kWeightedCycles | kUnweightedCycles;
259 
260 // Properties that are preserved when an FST's input labels are changed.
261 inline constexpr uint64_t kILabelInvariantProperties =
262  kExpanded | kMutable | kError | kODeterministic | kNonODeterministic |
263  kOEpsilons | kNoOEpsilons | kOLabelSorted | kNotOLabelSorted | kWeighted |
264  kUnweighted | kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic |
265  kTopSorted | kNotTopSorted | kAccessible | kNotAccessible | kCoAccessible |
266  kNotCoAccessible | kString | kNotString | kWeightedCycles |
268 
269 // Properties that are preserved when an FST's output labels are changed.
270 inline constexpr uint64_t kOLabelInvariantProperties =
271  kExpanded | kMutable | kError | kIDeterministic | kNonIDeterministic |
272  kIEpsilons | kNoIEpsilons | kILabelSorted | kNotILabelSorted | kWeighted |
273  kUnweighted | kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic |
274  kTopSorted | kNotTopSorted | kAccessible | kNotAccessible | kCoAccessible |
275  kNotCoAccessible | kString | kNotString | kWeightedCycles |
277 
278 // Properties that are preserved when an FST's weights are changed. This
279 // assumes that the set of states that are non-final is not changed.
280 inline constexpr uint64_t kWeightInvariantProperties =
281  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
282  kNonIDeterministic | kODeterministic | kNonODeterministic | kEpsilons |
283  kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons |
284  kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted |
285  kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic | kTopSorted |
286  kNotTopSorted | kAccessible | kNotAccessible | kCoAccessible |
287  kNotCoAccessible | kString | kNotString;
288 
289 // Properties that are preserved when a superfinal state is added and an FST's
290 // final weights are directed to it via new transitions.
291 inline constexpr uint64_t kAddSuperFinalProperties =
292  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor |
293  kNonIDeterministic | kNonODeterministic | kEpsilons | kIEpsilons |
294  kOEpsilons | kNotILabelSorted | kNotOLabelSorted | kWeighted | kUnweighted |
295  kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic | kNotTopSorted |
296  kNotAccessible | kCoAccessible | kNotCoAccessible | kNotString |
297  kWeightedCycles | kUnweightedCycles;
298 
299 // Properties that are preserved when a superfinal state is removed and the
300 // epsilon transitions directed to it are made final weights.
301 inline constexpr uint64_t kRmSuperFinalProperties =
302  kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic |
303  kODeterministic | kNoEpsilons | kNoIEpsilons | kNoOEpsilons |
304  kILabelSorted | kOLabelSorted | kWeighted | kUnweighted | kCyclic |
305  kAcyclic | kInitialCyclic | kInitialAcyclic | kTopSorted | kAccessible |
306  kCoAccessible | kNotCoAccessible | kString | kWeightedCycles |
308 
309 // All binary properties.
310 inline constexpr uint64_t kBinaryProperties = 0x0000000000000007ULL;
311 
312 // All trinary properties.
313 inline constexpr uint64_t kTrinaryProperties = 0x0000ffffffff0000ULL;
314 
315 // COMPUTED PROPERTIES
316 
317 // 1st bit of trinary properties.
318 inline constexpr uint64_t kPosTrinaryProperties =
319  kTrinaryProperties & 0x5555555555555555ULL;
320 
321 // 2nd bit of trinary properties.
322 inline constexpr uint64_t kNegTrinaryProperties =
323  kTrinaryProperties & 0xaaaaaaaaaaaaaaaaULL;
324 
325 // All properties.
326 inline constexpr uint64_t kFstProperties =
327  kBinaryProperties | kTrinaryProperties;
328 
329 // PROPERTY FUNCTIONS and STRING NAMES (defined in properties.cc).
330 
331 // Below are functions for getting property bit vectors when executing
332 // mutation operations.
333 inline uint64_t SetStartProperties(uint64_t inprops);
334 
335 template <typename Weight>
336 uint64_t SetFinalProperties(uint64_t inprops, const Weight &old_weight,
337  const Weight &new_weight);
338 
339 inline uint64_t AddStateProperties(uint64_t inprops);
340 
341 template <typename A>
342 uint64_t AddArcProperties(uint64_t inprops, typename A::StateId s, const A &arc,
343  const A *prev_arc);
344 
345 inline uint64_t DeleteStatesProperties(uint64_t inprops);
346 
347 inline uint64_t DeleteAllStatesProperties(uint64_t inprops,
348  uint64_t staticProps);
349 
350 inline uint64_t DeleteArcsProperties(uint64_t inprops);
351 
352 uint64_t ClosureProperties(uint64_t inprops, bool star, bool delayed = false);
353 
354 uint64_t ComplementProperties(uint64_t inprops);
355 
356 uint64_t ComposeProperties(uint64_t inprops1, uint64_t inprops2);
357 
358 uint64_t ConcatProperties(uint64_t inprops1, uint64_t inprops2,
359  bool delayed = false);
360 
361 uint64_t DeterminizeProperties(uint64_t inprops, bool has_subsequential_label,
362  bool distinct_psubsequential_labels);
363 
364 uint64_t FactorWeightProperties(uint64_t inprops);
365 
366 uint64_t InvertProperties(uint64_t inprops);
367 
368 uint64_t ProjectProperties(uint64_t inprops, bool project_input);
369 
370 uint64_t RandGenProperties(uint64_t inprops, bool weighted);
371 
372 uint64_t RelabelProperties(uint64_t inprops);
373 
374 uint64_t ReplaceProperties(const std::vector<uint64_t> &inprops, size_t root,
375  bool epsilon_on_call, bool epsilon_on_return,
376  bool out_epsilon_on_call, bool out_epsilon_on_return,
377  bool replace_transducer, bool no_empty_fst,
378  bool all_ilabel_sorted, bool all_olabel_sorted,
379  bool all_negative_or_dense);
380 
381 uint64_t ReverseProperties(uint64_t inprops, bool has_superinitial);
382 
383 uint64_t ReweightProperties(uint64_t inprops, bool added_start_epsilon);
384 
385 uint64_t RmEpsilonProperties(uint64_t inprops, bool delayed = false);
386 
387 uint64_t ShortestPathProperties(uint64_t props, bool tree = false);
388 
389 uint64_t SynchronizeProperties(uint64_t inprops);
390 
391 uint64_t UnionProperties(uint64_t inprops1, uint64_t inprops2,
392  bool delayed = false);
393 
394 // Definitions of inlined functions.
395 
396 uint64_t SetStartProperties(uint64_t inprops) {
397  auto outprops = inprops & kSetStartProperties;
398  if (inprops & kAcyclic) {
399  outprops |= kInitialAcyclic;
400  }
401  return outprops;
402 }
403 
404 uint64_t AddStateProperties(uint64_t inprops) {
405  return inprops & kAddStateProperties;
406 }
407 
408 uint64_t DeleteStatesProperties(uint64_t inprops) {
409  return inprops & kDeleteStatesProperties;
410 }
411 
412 uint64_t DeleteAllStatesProperties(uint64_t inprops, uint64_t staticprops) {
413  const auto outprops = inprops & kError;
414  return outprops | kNullProperties | staticprops;
415 }
416 
417 uint64_t DeleteArcsProperties(uint64_t inprops) {
418  return inprops & kDeleteArcsProperties;
419 }
420 
421 // Definitions of template functions.
422 
423 template <typename Weight>
424 uint64_t SetFinalProperties(uint64_t inprops, const Weight &old_weight,
425  const Weight &new_weight) {
426  auto outprops = inprops;
427  if (old_weight != Weight::Zero() && old_weight != Weight::One()) {
428  outprops &= ~kWeighted;
429  }
430  if (new_weight != Weight::Zero() && new_weight != Weight::One()) {
431  outprops |= kWeighted;
432  outprops &= ~kUnweighted;
433  }
434  outprops &= kSetFinalProperties | kWeighted | kUnweighted;
435  return outprops;
436 }
437 
444 // if s currently has no arcs.
445 template <typename Arc>
446 uint64_t AddArcProperties(uint64_t inprops, typename Arc::StateId s,
447  const Arc &arc, const Arc *prev_arc) {
448  using Weight = typename Arc::Weight;
449  auto outprops = inprops;
450  if (arc.ilabel != arc.olabel) {
451  outprops |= kNotAcceptor;
452  outprops &= ~kAcceptor;
453  }
454  if (arc.ilabel == 0) {
455  outprops |= kIEpsilons;
456  outprops &= ~kNoIEpsilons;
457  if (arc.olabel == 0) {
458  outprops |= kEpsilons;
459  outprops &= ~kNoEpsilons;
460  }
461  }
462  if (arc.olabel == 0) {
463  outprops |= kOEpsilons;
464  outprops &= ~kNoOEpsilons;
465  }
466  if (prev_arc) {
467  if (prev_arc->ilabel > arc.ilabel) {
468  outprops |= kNotILabelSorted;
469  outprops &= ~kILabelSorted;
470  }
471  if (prev_arc->olabel > arc.olabel) {
472  outprops |= kNotOLabelSorted;
473  outprops &= ~kOLabelSorted;
474  }
475  }
476  if (arc.weight != Weight::Zero() && arc.weight != Weight::One()) {
477  outprops |= kWeighted;
478  outprops &= ~kUnweighted;
479  }
480  if (arc.nextstate <= s) {
481  outprops |= kNotTopSorted;
482  outprops &= ~kTopSorted;
483  }
484  outprops &= kAddArcProperties | kAcceptor | kNoEpsilons | kNoIEpsilons |
485  kNoOEpsilons | kILabelSorted | kOLabelSorted | kUnweighted |
486  kTopSorted;
487  if (outprops & kTopSorted) {
488  outprops |= kAcyclic | kInitialAcyclic;
489  }
490  return outprops;
491 }
492 
493 namespace internal {
494 
495 extern const std::string_view PropertyNames[];
496 
497 // For a binary property, the bit is always returned set. For a trinary (i.e.,
498 // two-bit) property, both bits are returned set iff either corresponding input
499 // bit is set.
500 inline uint64_t KnownProperties(uint64_t props) {
501  return kBinaryProperties | (props & kTrinaryProperties) |
502  ((props & kPosTrinaryProperties) << 1) |
503  ((props & kNegTrinaryProperties) >> 1);
504 }
505 
506 // Tests compatibility between two sets of properties.
507 inline bool CompatProperties(uint64_t props1, uint64_t props2) {
508  const auto known_props1 = KnownProperties(props1);
509  const auto known_props2 = KnownProperties(props2);
510  const auto known_props = known_props1 & known_props2;
511  const auto incompat_props = (props1 & known_props) ^ (props2 & known_props);
512  if (incompat_props) {
513  uint64_t prop = 1;
514  for (int i = 0; i < 64; ++i, prop <<= 1) {
515  if (prop & incompat_props) {
516  LOG(ERROR) << "CompatProperties: Mismatch: "
518  << ": props1 = " << (props1 & prop ? "true" : "false")
519  << ", props2 = " << (props2 & prop ? "true" : "false");
520  }
521  }
522  return false;
523  } else {
524  return true;
525  }
526 }
527 
528 } // namespace internal
529 } // namespace fst
530 
531 #endif // FST_PROPERTIES_H_
constexpr uint64_t kAddStateProperties
Definition: properties.h:207
uint64_t ConcatProperties(uint64_t inprops1, uint64_t inprops2, bool delayed=false)
Definition: properties.cc:95
constexpr uint64_t kCyclic
Definition: properties.h:109
uint64_t AddArcProperties(uint64_t inprops, typename A::StateId s, const A &arc, const A *prev_arc)
constexpr uint64_t kStateSortProperties
Definition: properties.h:241
constexpr uint64_t kNotString
Definition: properties.h:139
uint64_t RandGenProperties(uint64_t inprops, bool weighted)
Definition: properties.cc:234
constexpr uint64_t kArcSortProperties
Definition: properties.h:251
constexpr uint64_t kMutable
Definition: properties.h:49
constexpr uint64_t kWeightedCycles
Definition: properties.h:142
constexpr uint64_t kDeleteArcsProperties
Definition: properties.h:234
constexpr uint64_t kWeightInvariantProperties
Definition: properties.h:280
uint64_t SetStartProperties(uint64_t inprops)
Definition: properties.h:396
constexpr uint64_t kOEpsilons
Definition: properties.h:89
constexpr uint64_t kInitialCyclic
Definition: properties.h:114
uint64_t ComposeProperties(uint64_t inprops1, uint64_t inprops2)
Definition: properties.cc:73
constexpr uint64_t kCoAccessible
Definition: properties.h:129
uint64_t RmEpsilonProperties(uint64_t inprops, bool delayed=false)
Definition: properties.cc:358
bool CompatProperties(uint64_t props1, uint64_t props2)
Definition: properties.h:507
constexpr uint64_t kBinaryProperties
Definition: properties.h:310
constexpr uint64_t kNotAccessible
Definition: properties.h:126
constexpr uint64_t kNotTopSorted
Definition: properties.h:121
uint64_t ShortestPathProperties(uint64_t props, bool tree=false)
Definition: properties.cc:373
constexpr uint64_t kTrinaryProperties
Definition: properties.h:313
uint64_t AddStateProperties(uint64_t inprops)
Definition: properties.h:404
uint64_t DeleteAllStatesProperties(uint64_t inprops, uint64_t staticProps)
Definition: properties.h:412
constexpr uint64_t kError
Definition: properties.h:52
uint64_t DeleteStatesProperties(uint64_t inprops)
Definition: properties.h:408
constexpr uint64_t kRmSuperFinalProperties
Definition: properties.h:301
constexpr uint64_t kInitialAcyclic
Definition: properties.h:116
#define LOG(type)
Definition: log.h:53
constexpr uint64_t kCompiledStringProperties
Definition: properties.h:157
constexpr uint64_t kDeleteStatesProperties
Definition: properties.h:227
constexpr uint64_t kUnweightedCycles
Definition: properties.h:145
constexpr uint64_t kEpsilons
Definition: properties.h:79
constexpr uint64_t kNotOLabelSorted
Definition: properties.h:101
uint64_t SetFinalProperties(uint64_t inprops, const Weight &old_weight, const Weight &new_weight)
Definition: properties.h:424
constexpr uint64_t kTopSorted
Definition: properties.h:119
constexpr uint64_t kNegTrinaryProperties
Definition: properties.h:322
constexpr uint64_t kODeterministic
Definition: properties.h:74
uint64_t RelabelProperties(uint64_t inprops)
Definition: properties.cc:326
constexpr uint64_t kSetFinalProperties
Definition: properties.h:197
constexpr uint64_t kExtrinsicProperties
Definition: properties.h:185
constexpr uint64_t kNonIDeterministic
Definition: properties.h:71
constexpr uint64_t kIntrinsicProperties
Definition: properties.h:174
constexpr uint64_t kNotILabelSorted
Definition: properties.h:96
uint64_t ReverseProperties(uint64_t inprops, bool has_superinitial)
Definition: properties.cc:337
uint64_t ClosureProperties(uint64_t inprops, bool star, bool delayed=false)
Definition: properties.cc:38
uint64_t UnionProperties(uint64_t inprops1, uint64_t inprops2, bool delayed=false)
Definition: properties.cc:393
constexpr uint64_t kNoOEpsilons
Definition: properties.h:91
constexpr uint64_t kOLabelSorted
Definition: properties.h:99
constexpr uint64_t kNotAcceptor
Definition: properties.h:66
constexpr uint64_t kCopyProperties
Definition: properties.h:163
constexpr uint64_t kAcyclic
Definition: properties.h:111
uint64_t ReplaceProperties(const std::vector< uint64_t > &inprops, size_t root, bool epsilon_on_call, bool epsilon_on_return, bool out_epsilon_on_call, bool out_epsilon_on_return, bool replace_transducer, bool no_empty_fst, bool all_ilabel_sorted, bool all_olabel_sorted, bool all_negative_or_dense)
Definition: properties.cc:251
uint64_t FactorWeightProperties(uint64_t inprops)
Definition: properties.cc:155
constexpr uint64_t kNoEpsilons
Definition: properties.h:81
uint64_t KnownProperties(uint64_t props)
Definition: properties.h:500
uint64_t ReweightProperties(uint64_t inprops, bool added_start_epsilon)
Definition: properties.cc:347
constexpr uint64_t kAccessible
Definition: properties.h:124
constexpr uint64_t kIDeterministic
Definition: properties.h:69
constexpr uint64_t kOLabelInvariantProperties
Definition: properties.h:270
constexpr uint64_t kNullProperties
Definition: properties.h:150
uint64_t ComplementProperties(uint64_t inprops)
Definition: properties.cc:60
constexpr uint64_t kIEpsilons
Definition: properties.h:84
constexpr uint64_t kAddArcProperties
Definition: properties.h:217
constexpr uint64_t kILabelInvariantProperties
Definition: properties.h:261
constexpr uint64_t kILabelSorted
Definition: properties.h:94
constexpr uint64_t kFstProperties
Definition: properties.h:326
constexpr uint64_t kUnweighted
Definition: properties.h:106
uint64_t InvertProperties(uint64_t inprops)
Definition: properties.cc:169
uint64_t DeterminizeProperties(uint64_t inprops, bool has_subsequential_label, bool distinct_psubsequential_labels)
Definition: properties.cc:130
constexpr uint64_t kNonODeterministic
Definition: properties.h:76
const std::string_view PropertyNames[]
Definition: properties.cc:429
constexpr uint64_t kPosTrinaryProperties
Definition: properties.h:318
constexpr uint64_t kString
Definition: properties.h:136
uint64_t DeleteArcsProperties(uint64_t inprops)
Definition: properties.h:417
uint64_t ProjectProperties(uint64_t inprops, bool project_input)
Definition: properties.cc:195
constexpr uint64_t kNotCoAccessible
Definition: properties.h:131
constexpr uint64_t kWeighted
Definition: properties.h:104
constexpr uint64_t kExpanded
Definition: properties.h:46
constexpr uint64_t kSetStartProperties
Definition: properties.h:188
uint64_t SynchronizeProperties(uint64_t inprops)
Definition: properties.cc:381
constexpr uint64_t kNoIEpsilons
Definition: properties.h:86
constexpr uint64_t kSetArcProperties
Definition: properties.h:224
constexpr uint64_t kAddSuperFinalProperties
Definition: properties.h:291
constexpr uint64_t kAcceptor
Definition: properties.h:64