1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// farextract.cc 2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License"); 4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License. 5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at 6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// http://www.apache.org/licenses/LICENSE-2.0 8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software 10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS, 11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and 13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License. 14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc. 16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: riley@google.com (Michael Riley) 17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Modified: jpr@google.com (Jake Ratkiewicz) to use new arc dispatch 18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// \file 20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Extracts component FSTs from an finite-state archive. 21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/extensions/far/main.h> 24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/extensions/far/farscript.h> 25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(filename_prefix, "", "Prefix to append to filenames"); 27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(filename_suffix, "", "Suffix to append to filenames"); 28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_int32(generate_filenames, 0, 29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson "Generate N digit numeric filenames (def: use keys)"); 305b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander GutkinDEFINE_string(keys, "", 315b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin "Extract set of keys separated by comma (default) " 325b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin "including ranges delimited by dash (default)" ); 335b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander GutkinDEFINE_string(key_separator, ",", "Separator for individual keys"); 345b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander GutkinDEFINE_string(range_delimiter, "-", "Delimiter for ranges of keys"); 35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonint main(int argc, char **argv) { 37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson namespace s = fst::script; 38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson string usage = "Extracts FSTs from a finite-state archive.\n\n Usage:"; 40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson usage += argv[0]; 41dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin usage += " [in1.far in2.far...]\n"; 42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson std::set_new_handler(FailedNewHandler); 44dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin SET_FLAGS(usage.c_str(), &argc, &argv, true); 45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson vector<string> ifilenames; 47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson for (int i = 1; i < argc; ++i) 48dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin ifilenames.push_back(strcmp(argv[i], "") != 0 ? argv[i] : ""); 49dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin if (ifilenames.empty()) ifilenames.push_back(""); 50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson const string &arc_type = fst::LoadArcTypeFromFar(ifilenames[0]); 52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson s::FarExtract(ifilenames, arc_type, FLAGS_generate_filenames, 545b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin FLAGS_keys, FLAGS_key_separator, FLAGS_range_delimiter, 555b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin FLAGS_filename_prefix, FLAGS_filename_suffix); 56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson return 0; 58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} 59