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