1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License"); 3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License. 4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at 5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// http://www.apache.org/licenses/LICENSE-2.0 7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software 9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS, 10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and 12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License. 13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc. 15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: jpr@google.com (Jake Ratkiewicz) 16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/extensions/far/compile-strings.h> 18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <iostream> 19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fstream> 20dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin#include <sstream> 21dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin 22dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander GutkinDEFINE_string(far_field_separator, "\t", 23dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin "Set of characters used as a separator between printed fields"); 24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonnamespace fst { 26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Compute the minimal length required to 28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// encode each line number as a decimal number 29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonint KeySize(const char *filename) { 30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson ifstream istrm(filename); 31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson istrm.seekg(0); 32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson string s; 33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson int nline = 0; 34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson while (getline(istrm, s)) 35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson ++nline; 36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson istrm.seekg(0); 37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson return nline ? ceil(log10(nline + 1)) : 1; 38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} 39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} // namespace fst 41