All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
copy-int-vector-vector.cc
Go to the documentation of this file.
1 // bin/copy-int-vector-vector.cc
2 
3 // Copyright 2012 Johns Hopkins University (Author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 
23 
24 
25 int main(int argc, char *argv[]) {
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 }
84 
85 
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
void Write(const std::string &key, const T &value) const
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int main(int argc, char *argv[])
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
#define KALDI_ERR
Definition: kaldi-error.h:127
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *wxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_LOG
Definition: kaldi-error.h:133
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.