OpenFST Transducer first steps

203 views Asked by At

I'm a newbie in OpenFST and trying to create a simple transducers for words in C++. The main purpose is to make a composition of transducers and get a difference criterion for two words. The problem is that I don't know (and can't find tutorials) how I can make transducer for words "cat", "bat" and compose it. The simple code don't return me shortest way. Also I don't understand clearly parameters of StdArc. My code below:

  int main(int argc, char *argv[])
{
    char firstword[] = "cat";
    char secondword[] = "bath";

    VectorFst<StdArc> fst1;
    int start_flag = 1;
    int i = 0;
    for (i = 0; i < 3; i++)
    {
        fst1.AddState();
        if(start_flag)
        {
            fst1.SetStart(i);
            start_flag = 0;
        }
        fst1.AddArc(i, StdArc(firstword[i], firstword[i+1],i, i+1);
    }
    fst1.AddState();
    fst1.SetFinal(i,0);


    VectorFst<StdArc> fst2;
    start_flag = 1;
    i = 0;
    for (i = 0; i < 4; i++)
    {
        fst2.AddState();
        if(start_flag)
        {
            fst2.SetStart(i);
            start_flag = 0;
        }
        fst2.AddArc(i, StdArc(secondword[i],secondword[i+1],i,i+1));
    }
    fst2.AddState();
    fst2.SetFinal(i,0);

    VectorFst<StdArc> fst3;
    Compose(fst1, fst2, &fst3);

    vector<StdArc::Weight> distance;
    ShortestDistance(fst3, &distance, true);

    return 1;
}

Thanks for your help guys!

0

There are 0 answers