HFST: API CVS Repository

The repository is in corpus.csc.fi in directory /c/appl/ling/koskenni/cvsrepo/hfst/. The repository contains the following files:

  • hfst.h: A header file for HFST and HWFST tools.

  • hfst_defs_private.h, hfst_defs_public.h: Typecasting between different transducer representations.

  • functions.h, datatypes.h: Function declarations and datatype definitions.

  • sfst/hsfst.C: HFST API functions. Most of the code is copied from SFST.

  • fst/lib/hofst.C: HWFST API functions. Some of the code is copied from SFST.

  • hfst-utf8-scanner.ll, hfst-compiler.yy: Flex parser and Bison compiler for tools hfst-calculate and hwfst-calculate. Mostly copied from SFST.

  • hfst- * .C: Source files for HFST tools. Some of the code is copied from SFST.

  • config-file: A configuration file for creating Doxygen documentation of the HFST interface. The documentation is in files hfst.h, functions.h and datatypes.h.

  • sfst/ * : The SFST files needed in HFST and HWFST.

  • fst/lib/ * : The OpenFst files needed in HWFST.

  • Makefile: A makefile for creating HFST libraries and tools.

  • README: Contains the same information as this page.

  • xre/: experimental flex & yacc parser for Xerox style regular expressions to HFST


Call Makefile by command make in the directory hfst.

The HFST tools and libraries

When Makefile is run, a set of HFST tools is created. More information on the tools is in HfstCommandLineToolFunctionalities.

Makefile also creates the following libraries:

  • libhfst.a: A static library file that contains all HFST and HWFST object files. If you are using HWFST, include the library options -lpthread -lm -ldl in the linking command.

  • libhfst.so: A dynamic library file that contains all files needed by HFST and HWFST.

Using HFST in your own programs

See http://www.ling.helsinki.fi/kieliteknologia/tutkimus/hfst/documentation.shtml for HFST API documentation.

Static linking

Include the file 'hfst.h' in your source code. Translate the source code:

g++ -DSGIext -I. -o program.o -c program.cpp
and link to HFST:
g++ -static program.o -L. -lhfst -lpthread -lm -ldl -o program.exe

If you are not using HWFST functions, you can exclude the library options -lpthread -lm -ldl.

Dynamic linking

Include the file 'hfst.h' in your source code. Translate the source code:

g++ -DSGIext -fPIC -I. -o program.o -c program.cpp
and link to HFST:
g++ -Wl,-L. -Wl,-rpath,. program.o -lhfst -o program.exe


When using HWFST transducers, every time you call functions 'def_alphabet', 'result' or 'write to file', the symbol table is written in file 'symbol_table' in the current directory. When you call function 'read_transducer' or 'read_transducer_text' it reads the symbol table from the file 'symbol_table'.

When using HWFST tools, using std::cerr, std::cout and std::cin might cause problems as OpenFst uses the pthread library. Use either fprintf and fscanf or protect the code in the following way:

// create a mutex and initialize it
pthread_mutex_t the_mutex;
#ifdef _PTHREADS_DRAFT4     // for user threads
pthread_mutex_init(&the_mutex, pthread_mutexattr_default);
#else                       // for kernel threads
pthread_mutex_init(&the_mutex, (pthread_mutexattr_t *)NULL);

cout << "something" ... ;

-- ErikAxelson - 28 Jul 2008

Topic revision: r6 - 2012-04-10 - ErikAxelson
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback