aboutsummaryrefslogtreecommitdiff
path: root/src/include/fst/script/relabel.h
blob: 6bbb4c50bccccccd245566b9e7a6a128778b06a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright 2005-2010 Google, Inc.
// Author: jpr@google.com (Jake Ratkiewicz)

#ifndef FST_SCRIPT_RELABEL_H_
#define FST_SCRIPT_RELABEL_H_

#include <utility>
using std::pair; using std::make_pair;
#include <algorithm>
#include <vector>
using std::vector;

#include <fst/script/arg-packs.h>
#include <fst/script/fst-class.h>
#include <fst/relabel.h>

namespace fst {
namespace script {

// 1
typedef args::Package<MutableFstClass *,
                      const SymbolTable *, const SymbolTable *, bool,
                      const SymbolTable *, const SymbolTable *,
                      bool> RelabelArgs1;

template<class Arc>
void Relabel(RelabelArgs1 *args) {
  MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>();

  Relabel(ofst, args->arg2, args->arg3, args->arg4,
          args->arg5, args->arg6, args->arg7);
}

// 2
typedef args::Package<MutableFstClass*,
                      const vector<pair<int64, int64> > &,
                      const vector<pair<int64, int64> > > RelabelArgs2;

template<class Arc>
void Relabel(RelabelArgs2 *args) {
  MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>();

  // In case int64 is not the same as Arc::Label,
  // copy the reassignments
  typedef typename Arc::Label Label;

  vector<pair<Label, Label> > converted_ipairs(args->arg2.size());
  copy(args->arg2.begin(), args->arg2.end(), converted_ipairs.begin());

  vector<pair<Label, Label> > converted_opairs(args->arg3.size());
  copy(args->arg3.begin(), args->arg3.end(), converted_opairs.begin());

  Relabel(ofst, converted_ipairs, converted_opairs);
}

// 3
typedef args::Package<MutableFstClass*, const SymbolTable*,
                      const SymbolTable*> RelabelArgs3;
template<class Arc>
void Relabel(args::Package<MutableFstClass*, const SymbolTable*,
             const SymbolTable*> *args) {
  MutableFst<Arc> *fst = args->arg1->GetMutableFst<Arc>();
  Relabel(fst, args->arg2, args->arg3);
}


// 1
void Relabel(MutableFstClass *ofst,
             const SymbolTable *old_isyms, const SymbolTable *relabel_isyms,
             bool attach_new_isyms,
             const SymbolTable *old_osyms, const SymbolTable *relabel_osyms,
             bool attch_new_osyms);

// 2
void Relabel(MutableFstClass *ofst,
             const vector<pair<int64, int64> > &ipairs,
             const vector<pair<int64, int64> > &opairs);


// 3
void Relabel(MutableFstClass *fst,
             const SymbolTable *new_isymbols,
             const SymbolTable *new_osymbols);


}  // namespace script
}  // namespace fst

#endif  // FST_SCRIPT_RELABEL_H_