Cambridge SMT System
vecmap.main.cpp
Go to the documentation of this file.
1 //Copyright (c) 2012, University of Cambridge
2 //All rights reserved.
3 //
4 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met://
5 //
6 // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 // * Neither the name of the University of Cambridge nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9 //
10 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 
12 #include <iostream>
13 
14 #include <fst/fstlib.h>
15 #include <fst/flags.h>
16 
17 #include "tropical-sparse-tuple-weight.h"
18 #include "tropical-sparse-tuple-weight-decls.h"
19 
20 DEFINE_bool (expand, false,
21  "convert a 32 bit tuple arc to a 64 bit tuple arc");
22 
23 DEFINE_bool (stdarc, false,
24  "map 32 bit vector weights to a single stdarc dimension");
25 
26 DEFINE_bool (tuplearc, false,
27  "map a single 32 bit stdarc dimension to a sparse tuple arc");
28 
29 DEFINE_int32 (k, 0, "vector dimension to map");
30 
31 DEFINE_bool (dot, false, "perform a dot product on the vector weights");
32 
33 int main (int argc, char **argv) {
34  std::string usage = "vecmap\n\n Usage:";
35  usage += argv[0];
36  InitFst (usage.c_str(), &argc, &argv, true);
37  if (argc != 1) {
38  cerr << "ERROR: invalid arguments" << endl;
39  return 1;
40  }
42  if (FLAGS_tuplearc) {
43  fst = new TupleArcFst32;
44  fst::StdVectorFst* stdfst = fst::StdVectorFst::Read (cin,
45  fst::FstReadOptions() );
46  fst::StdToVector<float> m (FLAGS_k);
47  fst::Map (*stdfst, fst, StdToSparseMapper (m) );
48  delete stdfst;
49  } else {
50  fst = TupleArcFst32::Read (cin, fst::FstReadOptions() );
51  }
52  if (FLAGS_stdarc || FLAGS_dot) {
53  fst::StdVectorFst stdfst;
54  if (FLAGS_stdarc) {
55  fst::VectorToStd<float> m (FLAGS_k);
56  fst::Map (*fst, &stdfst, SparseToStdMapper (m) );
57  } else {
59  fst::Map (*fst, &stdfst,
60  fst::GeneralMapper<TupleArc32, fst::ArcTpl<FeatureWeight32>, fst::DotProductMap<float> >
61  (m) );
62  }
63  stdfst.Write (std::cout, fst::FstWriteOptions() );
64  } else if (FLAGS_expand) {
65  TupleArcFst doublefst;
66  fst::Expand m;
67  fst::Map (*fst, &doublefst, fst::ExpandMapper (m) );
68  doublefst.Write (std::cout, fst::FstWriteOptions() );
69  } else {
70  fst->Write (std::cout, fst::FstWriteOptions() );
71  }
72  delete fst;
73  return 0;
74 }
Definition: fstio.hpp:27
fst::TropicalWeightTpl< F > Map(double)
Implements Tropical Sparse tuple weight semiring, extending from openfst SparsePowerWeight class...
int main(int argc, char **argv)
Definition: vecmap.main.cpp:33
Functor to convert sparse tuple weight to tropical (single weight)
fst::ArcTpl< TupleW32 > TupleArc32
Functor that converts tropical to sparse tuple weight.
fst::VectorFst< TupleArc > TupleArcFst
Map functor used with generic weight mapper.
DEFINE_bool(expand, false,"convert a 32 bit tuple arc to a 64 bit tuple arc")
fst::VectorFst< TupleArc32 > TupleArcFst32
DEFINE_int32(k, 0,"vector dimension to map")