Home | History | Annotate | Download | only in pdt
      1 // pdtinfo.cc
      2 
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 //
     15 // Copyright 2005-2010 Google, Inc.
     16 // Author: riley (at) google.com (Michael Riley)
     17 //
     18 // \file
     19 // Prints out various information about a PDT such as number of
     20 // states, arcs and parentheses.
     21 //
     22 
     23 #include <fst/extensions/pdt/pdtscript.h>
     24 #include <fst/util.h>
     25 
     26 DEFINE_string(pdt_parentheses, "", "PDT parenthesis label pairs.");
     27 
     28 int main(int argc, char **argv) {
     29   namespace s = fst::script;
     30 
     31   string usage = "Prints out information about a PDT.\n\n  Usage: ";
     32   usage += argv[0];
     33   usage += " in.pdt\n";
     34 
     35 
     36   std::set_new_handler(FailedNewHandler);
     37   SetFlags(usage.c_str(), &argc, &argv, true);
     38   if (argc > 2) {
     39     ShowUsage();
     40     return 1;
     41   }
     42 
     43   string in_name = (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : "";
     44 
     45   s::FstClass *ifst = s::FstClass::Read(in_name);
     46   if (!ifst) return 1;
     47 
     48   if (FLAGS_pdt_parentheses.empty()) {
     49     LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided";
     50     return 1;
     51   }
     52 
     53   vector<pair<int64, int64> > parens;
     54   fst::ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false);
     55 
     56   s::PrintPdtInfo(*ifst, parens);
     57 
     58   return 0;
     59 }
     60