All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
copy-int-vector-vector.cc File Reference
Include dependency graph for copy-int-vector-vector.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file copy-int-vector-vector.cc.

References kaldi::ClassifyRspecifier(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), kaldi::kNoRspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

25  {
26  try {
27  using namespace kaldi;
28 
29  const char *usage =
30  "Copy vectors of vectors of integers, or archives thereof\n"
31  "\n"
32  "Usage: copy-int-vector-vector [options] vector-in-(rspecifier|rxfilename) "
33  "vector-out-(wspecifierwxfilename)\n";
34 
35  bool binary = true;
36  ParseOptions po(usage);
37 
38  po.Register("binary", &binary, "Write in binary mode");
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 2) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  std::string in_fn = po.GetArg(1),
47  out_fn = po.GetArg(2);
48 
49  bool archive_in = (ClassifyRspecifier(in_fn, NULL, NULL) != kNoRspecifier),
50  archive_out = (ClassifyRspecifier(out_fn, NULL, NULL) != kNoRspecifier);
51 
52  if (archive_in != archive_out)
53  KALDI_ERR << "Cannot mix Tables/archives and non-Trables.";
54 
55  if (archive_in) {
56  int num_done = 0;
57  Int32VectorVectorWriter writer(out_fn);
59  for (; !reader.Done(); reader.Next(), num_done++)
60  writer.Write(reader.Key(), reader.Value());
61  KALDI_LOG << "Copied " << num_done << " items.";
62  return (num_done != 0 ? 0 : 1);
63  } else {
64  KALDI_ERR << "Non-archive reading and writing of vector<vector<int32> > "
65  "not yet implemented.";
66  // There doesn't seem to be a standard way of writing them, when
67  // not appearing in tables.
68  /* std::vector<std::vector<int32> > vec;
69  {
70  bool binary_in;
71  Input ki(in_fn, &binary_in);
72  ReadIntegerVectorVector(ki.Stream(), binary_in, &vec);
73  }
74  Output ko(out_fn, binary);
75  WriteIntegerVectorVector(ko.Stream(), binary, vec);
76  KALDI_LOG << "Copied vector<vector<int32> > to " << vector_out_fn; */
77  return 0;
78  }
79  } catch(const std::exception &e) {
80  std::cerr << e.what();
81  return -1;
82  }
83 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:127
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *wxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
#define KALDI_LOG
Definition: kaldi-error.h:133