1 
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 //
14 // Copyright 2005-2010 Google, Inc.
15 // Author: jpr@google.com (Jake Ratkiewicz)
16 
17 #ifndef FST_SCRIPT_DETERMINIZE_H_
18 #define FST_SCRIPT_DETERMINIZE_H_
19 
20 #include <fst/determinize.h>
21 #include <fst/script/arg-packs.h>
22 #include <fst/script/fst-class.h>
23 #include <fst/script/weight-class.h>
24 
25 namespace fst {
26 namespace script {
27 
28 struct DeterminizeOptions {
29   float delta;
30   WeightClass weight_threshold;
31   int64 state_threshold;
32   int64 subsequential_label;
33 
34   explicit DeterminizeOptions(float d = fst::kDelta,
35                               WeightClass w =
36                                 fst::script::WeightClass::Zero(),
37                               int64 n = fst::kNoStateId, int64 l = 0)
deltaDeterminizeOptions38       : delta(d), weight_threshold(w), state_threshold(n),
39         subsequential_label(l) {}
40 };
41 
42 typedef args::Package<const FstClass&, MutableFstClass*,
43                       const DeterminizeOptions &> DeterminizeArgs;
44 
45 template<class Arc>
Determinize(DeterminizeArgs * args)46 void Determinize(DeterminizeArgs *args) {
47   const Fst<Arc> &ifst = *(args->arg1.GetFst<Arc>());
48   MutableFst<Arc> *ofst = args->arg2->GetMutableFst<Arc>();
49   const DeterminizeOptions &opts = args->arg3;
50 
51   fst::DeterminizeOptions<Arc> detargs;
52   detargs.delta = opts.delta;
53   detargs.weight_threshold =
54       *(opts.weight_threshold.GetWeight<typename Arc::Weight>());
55   detargs.state_threshold = opts.state_threshold;
56   detargs.subsequential_label = opts.subsequential_label;
57 
58   Determinize(ifst, ofst, detargs);
59 }
60 
61 void Determinize(const FstClass &ifst, MutableFstClass *ofst,
62                  const DeterminizeOptions &opts =
63                    fst::script::DeterminizeOptions());
64 
65 }  // namespace script
66 }  // namespace fst
67 
68 #endif  // FST_SCRIPT_DETERMINIZE_H_
69