13 #include <boost/iostreams/filter/gzip.hpp> 14 #include <boost/iostreams/filtering_streambuf.hpp> 15 #include <boost/iostreams/device/array.hpp> 16 #include <boost/iostreams/device/file.hpp> 21 DEFINE_string (idxlimits,
"",
"sentence index limits 'min:max'");
22 DEFINE_string (idxscript,
"",
"script containing a list of sentence ids");
28 for (std::vector<TupleArcFst *>::iterator it = cachedLattices.begin();
29 it != cachedLattices.end(); ++it) {
35 boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
36 in.push (boost::iostreams::gzip_decompressor() );
37 in.push (boost::iostreams::file_source (
ExpandPath (m_pattern, s) ) );
38 std::istream is (&in);
39 TupleArcFst32* fst32 = TupleArcFst32::Read (is, fst::FstReadOptions() );
42 cerr <<
"ERROR: unable to load vector lattice: " <<
ExpandPath (m_pattern,
46 if (fst32->Properties (fst::kNotTopSorted,
true) ) {
47 cerr <<
"ERROR: Input lattices are not topologically sorted: " <<
'\n';
58 if (FLAGS_lats.empty() ) {
59 cerr <<
"ERROR: mandatory parameter not specified: 'lats'\n";
62 if (!FLAGS_idxlimits.empty() ) {
65 if (!FLAGS_idxscript.empty() ) {
68 if (
ids.size() == 0) {
70 <<
"ERROR: must specify either 'idxlimits' or 'idxscript' parameters" 74 tracer <<
"idx min=" <<
ids.front() <<
'\n';
75 tracer <<
"idx max=" <<
ids.back() <<
'\n';
76 m_pattern = FLAGS_lats;
78 cachedLattices.push_back (0);
79 for (std::vector<Sid>::const_iterator sit =
ids.begin(); sit !=
ids.end();
81 cachedLattices.push_back (LoadLattice (*sit) );
83 tracer <<
ids.size() <<
" vector lattices loaded\n";
88 const bool use_cache)
const {
90 return cachedLattices[s];
92 return LoadLattice (s);
TupleArcFst * GetVectorLattice(const Sid s, const bool use_cache) const
fst::TropicalWeightTpl< F > Map(double)
void Initialize(const bool use_cache)
void InitializeFromLimits(std::vector< Sid > &ids, const std::string limits)
std::string ExpandPath(std::string pattern, const int idx)
DEFINE_string(lats,"","path to vector lattices")
void InitializeFromScript(std::vector< Sid > &ids, const std::string filename)