Skip to content

Instantly share code, notes, and snippets.

@edobashira edobashira/Makefile
Created Aug 18, 2014

What would you like to do?
#include <fst/compose.h>
#include <fst/shortest-path.h>
#include <fst/vector-fst.h>
#include <fst/extensions/far/far.h>
using namespace std;
using namespace fst;
int main(int argc, char **argv) {
string usage = "Apply an fst to far archieve.\n\n Usage: ";
usage += argv[0];
usage += "model.fst in.far [out.far]\n";
SET_FLAGS(usage.c_str(), &argc, &argv, true);
if (argc < 3 || argc > 4) {
return 1;
StdFst *model = StdFst::Read(argv[1]);
if (!model)
LOG(FATAL) << "Failed to read model from : " << argv[1];
FarReader<StdArc> *reader = FarReader<StdArc>::Open(argv[2]);
if (!reader)
LOG(FATAL) << "Failed ro read FAR arhieve from : " << argv[2];
FarWriter<StdArc> *writer =
FarWriter<StdArc>::Create(argc == 4 ? argv[3] : "");
for (; !reader->Done(); reader->Next()) {
const StdFst &fst = reader->GetFst();
StdVectorFst cfst;
Compose(fst, *model, &cfst);
StdVectorFst ofst;
ShortestPath(cfst, &ofst);
writer->Add(reader->GetKey(), ofst);
delete model;
delete reader;
delete writer;
return 0;
all: farcompose
CXXFLAGS=-O2 -std=c++11
LDFLAGS=-L/usr/local/lib -L/usr/local/lib/fst
farcompose: farcompose.o
$(CXX) $^ -o $@ $(LDFLAGS) $(LDLIBS) -lfst -lfstfar
rm -rf *.o farcompose ${includes}
$(CXX) $(CXXFLAGS) -c $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.