Cambridge SMT System
tropical-sparse-tuple-weight-funcs.h
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
22 #ifndef TROPICALSPARSETUPLEWEIGHTFUNCS_H_
23 #define TROPICALSPARSETUPLEWEIGHTFUNCS_H_
24 
25 namespace fst {
26 
28 inline void listSparseFeatureIndices ( VectorFst<TupleArc32>& myfst,
29  unordered_set<uint>& idx ) {
30  typedef TupleArc32::StateId StateId;
31  for ( StateIterator< VectorFst<TupleArc32> > si ( myfst ); !si.Done();
32  si.Next() ) {
33  StateId state_id = si.Value();
34  for ( MutableArcIterator< VectorFst<TupleArc32> > ai ( &myfst, si.Value() );
35  !ai.Done(); ai.Next() ) {
36  const TupleW32 w = ai.Value().weight;
37  for ( SparseTupleWeightIterator<FeatureWeight32, int> it ( w ); !it.Done();
38  it.Next() ) {
39  idx.insert ( it.Value().first );
40  }
41  }
42  }
43 };
44 
45 }
46 
47 #endif /* TROPICALSPARSETUPLEWEIGHTFUNCS_H_ */
Definition: fstio.hpp:27
Implements Tropical Sparse tuple weight semiring, extending from openfst SparsePowerWeight class...
void listSparseFeatureIndices(VectorFst< TupleArc32 > &myfst, unordered_set< uint > &idx)
Traverses a machine and returns the indices actually used for the sparse vector weight tropical semir...