1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License");
3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License.
4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at
5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//     http://www.apache.org/licenses/LICENSE-2.0
7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software
9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS,
10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and
12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License.
13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc.
15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: jpr@google.com (Jake Ratkiewicz)
16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifndef FST_SCRIPT_PRINT_H_
18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define FST_SCRIPT_PRINT_H_
19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/script/arg-packs.h>
21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/script/fst-class.h>
22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/script/print-impl.h>
23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonnamespace fst {
25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonnamespace script {
26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Note: it is safe to pass these strings as references because
28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// this struct is only used to pass them deeper in the call graph.
29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Be sure you understand why this is so before using this struct
30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// for anything else!
31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonstruct FstPrinterArgs {
32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const FstClass &fst;
33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const SymbolTable *isyms;
34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const SymbolTable *osyms;
35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const SymbolTable *ssyms;
36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const bool accept;
37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const bool show_weight_one;
38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  ostream *ostrm;
39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const string &dest;
40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  FstPrinterArgs(const FstClass &fst,
42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 const SymbolTable *isyms,
43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 const SymbolTable *osyms,
44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 const SymbolTable *ssyms,
45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 bool accept,
46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 bool show_weight_one,
47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 ostream *ostrm,
48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                 const string &dest) :
49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accept(accept),
50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { }
51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson};
52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate<class Arc>
54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonvoid PrintFst(FstPrinterArgs *args) {
55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const Fst<Arc> &fst = *(args->fst.GetFst<Arc>());
56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  fst::FstPrinter<Arc> fstprinter(fst, args->isyms, args->osyms,
58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                      args->ssyms, args->accept,
59f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                      args->show_weight_one);
60f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  fstprinter.Print(args->ostrm, args->dest);
61f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}
62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonvoid PrintFst(const FstClass &fst, ostream &ostrm, const string &dest,
64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *isyms,
65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *osyms,
66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *ssyms,
67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              bool accept, bool show_weight_one);
68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Below are two printing methods with useful defaults for a few of
71f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// the fst printer arguments.
72f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate <class Arc>
73f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonvoid PrintFst(const Fst<Arc> &fst, ostream &os, const string dest = "",
74f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *isyms = NULL,
75f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *osyms = NULL,
76f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              const SymbolTable *ssyms = NULL) {
77f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  fst::FstPrinter<Arc> fstprinter(fst, isyms, osyms, ssyms, true, true);
78f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  fstprinter.Print(&os, dest);
79f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}
80f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
81f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}  // namespace script
82f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}  // namespace fst
83f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
84f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
85f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
86f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#endif  // FST_SCRIPT_PRINT_H_
87