Home | History | Annotate | Download | only in script
      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 (at) google.com (Jake Ratkiewicz)
     16 
     17 #ifndef FST_SCRIPT_RANDEQUIVALENT_H_
     18 #define FST_SCRIPT_RANDEQUIVALENT_H_
     19 
     20 #include <fst/script/arg-packs.h>
     21 #include <fst/script/fst-class.h>
     22 #include <fst/script/randgen.h>  // for RandArcSelection
     23 #include <fst/randequivalent.h>
     24 
     25 namespace fst {
     26 namespace script {
     27 
     28 // 1
     29 typedef args::Package<const FstClass&, const FstClass&,
     30                       int32, float, int, int> RandEquivalentInnerArgs1;
     31 typedef args::WithReturnValue<bool,
     32                               RandEquivalentInnerArgs1> RandEquivalentArgs1;
     33 
     34 template<class Arc>
     35 void RandEquivalent(RandEquivalentArgs1 *args) {
     36   const Fst<Arc> &fst1 = *(args->args.arg1.GetFst<Arc>());
     37   const Fst<Arc> &fst2 = *(args->args.arg2.GetFst<Arc>());
     38 
     39   args->retval = RandEquivalent(fst1, fst2, args->args.arg3, args->args.arg4,
     40                                 args->args.arg5, args->args.arg6);
     41 }
     42 
     43 // 2
     44 typedef args::Package<const FstClass &, const FstClass &, int32,
     45                       ssize_t, float,
     46                       const RandGenOptions<RandArcSelection> &>
     47   RandEquivalentInnerArgs2;
     48 
     49 typedef args::WithReturnValue<bool,
     50                               RandEquivalentInnerArgs2> RandEquivalentArgs2;
     51 
     52 template<class Arc>
     53 void RandEquivalent(RandEquivalentArgs2 *args) {
     54   const Fst<Arc> &fst1 = *(args->args.arg1.GetFst<Arc>());
     55   const Fst<Arc> &fst2 = *(args->args.arg2.GetFst<Arc>());
     56   const RandGenOptions<RandArcSelection> &opts = args->args.arg6;
     57   int32 seed = args->args.arg3;
     58 
     59   if (opts.arc_selector == UNIFORM_ARC_SELECTOR) {
     60     UniformArcSelector<Arc> arc_selector(seed);
     61     RandGenOptions< UniformArcSelector<Arc> >
     62         ropts(arc_selector, opts.max_length, opts.npath);
     63 
     64     args->retval = RandEquivalent(fst1, fst2, args->args.arg4,
     65                                   args->args.arg5, ropts);
     66   } else if (opts.arc_selector == FAST_LOG_PROB_ARC_SELECTOR) {
     67     FastLogProbArcSelector<Arc> arc_selector(seed);
     68     RandGenOptions< FastLogProbArcSelector<Arc> >
     69         ropts(arc_selector, opts.max_length, opts.npath);
     70 
     71     args->retval = RandEquivalent(fst1, fst2, args->args.arg4,
     72                                   args->args.arg5, ropts);
     73   } else {
     74     LogProbArcSelector<Arc> arc_selector(seed);
     75     RandGenOptions< LogProbArcSelector<Arc> >
     76         ropts(arc_selector, opts.max_length, opts.npath);
     77     args->retval = RandEquivalent(fst1, fst2, args->args.arg4,
     78                                   args->args.arg5, ropts);
     79   }
     80 }
     81 
     82 
     83 // 1
     84 bool RandEquivalent(const FstClass &fst1,
     85                     const FstClass &fst2,
     86                     int32 seed = time(0),
     87                     ssize_t num_paths = 1,
     88                     float delta = fst::kDelta,
     89                     int path_length = INT_MAX);
     90 
     91 // 2
     92 bool RandEquivalent(const FstClass &fst1,
     93                     const FstClass &fst2,
     94                     int32 seed,
     95                     ssize_t num_paths,
     96                     float delta,
     97                     const fst::RandGenOptions<
     98                       fst::script::RandArcSelection> &opts);
     99 
    100 }  // namespace script
    101 }  // namespace fst
    102 
    103 
    104 
    105 #endif  // FST_SCRIPT_RANDEQUIVALENT_H_
    106