The SVN url has been changed by SourceForge. In your repository root, or in an individual module, run the command:
svn switch --relocate


From Apertium
(Redirected from HFST)
Jump to: navigation, search


hfst is the Helsinki finite-state toolkit. This is formalism-compatible with both lexc and twolc, so, kind of like foma is to xfst. It is currently being used in apertium-sme-nob, apertium-fin-sme, apertium-kaz-tat and in few other pairs which involve Turkic languages.

The IRC channel is #hfst at (you may try irc:// if your browser supports it, or enter #hfst into if you want a web client). The HFST Wiki has some very good documentation (see especially the page HfstReadme when you run into compilation problems).

HFST is actually created as a set of wrappers over several possible back-ends, Foma, OpenFST, SFST, …. The latest versions of HFST include the back-ends you need, so there's no reason to install any of these backends separately.

[edit] Building and installing HFST

[edit] Install prerequisites

You will need the regular build dependencies:

  • automake, autoconf, libtool, flex, bison, g++, libreadline-dev

If you've already installed apertium/lttoolbox these should be installed already; if not, they should be easily installable with your package manager, e.g.

  • Ubuntu: sudo apt-get install automake autoconf libtool flex bison g++ libreadline-dev
  • Arch Linux: sudo pacman -S base-devel
  • MacOS X users should install the general Prerequisites_for_Mac_OS_X first, then sudo port install bison readline

[edit] Download HFST

Either use the latest release (recommended for users), or go with the bleeding-edge SVN version (recommended for developers).

[edit] From SVN

$ svn co svn:// hfst3
$ cd hfst3/
$ ./

(The autogen step is only needed when using SVN, not with the tarball.)

[edit] Released tarball

Download the latest release, named something like hfst-X.Y.Z.tar.gz, from, then

$ tar -xzf hfst-X.Y.Z.tgz
$ cd hfst-X.Y.Z/

(replacing X.Y.Z for the version you downloaded)

[edit] Configure

In the configure step, you can turn on/off features and backends and such. The OpenFST backend is included in the HFST distribution, while foma and SFST are not and are not recommended since they typically lead to more trouble than it's worth.

For most users, this should work:

$ ./configure --enable-proc --without-foma --enable-lexc --enable-all-tools

The above command will configure it to be installed to /usr/local in the make install step (below).

If you want hfst and back-ends installed somewhere else, you can do

$ ./configure --enable-proc --without-foma --enable-lexc --enable-all-tools  --prefix=/home/USERNAME/local/

Note: When we say USERNAME we mean your username, you need to replace it with your username, if you don't know what it is, you can find out by typing whoami

You can also add --with-unicode-handler=glib (or --with-unicode-handler=ICU) to the ./configure step if you have glib (or ICU) installed and want better Unicode Case_folding.

[edit] Compile and install

If your autotools version is older than 1.14 (check with automake --version), first do:

$ scripts/scripts/

Build by running

$ make

Then you need to install (Note: you need to use sudo make install if you installed it in /usr/local (or did not give a --prefix in the configure step); otherwise, no sudo!)

$ make install

And finally, unless you have a Mac, you may need to do:

$ sudo ldconfig

[edit] Troubleshooting

When doing "make" with old autotools (pre 1.14?)

make[5]: *** No rule to make target `xre_parse.hh', needed by `xre_lex.ll'.  Stop.

Run scripts/ and then make again.

If, during the ./configure step, you see
checking for GNU libc compatible malloc... no
checking for GNU libc compatible realloc... no
and then during make a bunch of errors like:
/usr/local/include/sfst/mem.h:37:57: error: 'malloc' was not declared in this scope
, try the following:
sudo ldconfig
export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

and then ./configure and make.

If, during make, you see errors like error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

try instead

make CXXFLAGS=-fpermissive

If, when compiling a dictionary, you end up in a "foma" prompt where you can type stuff, you should remove anything related to foma or "hfst-xfst" from your system, and build HFST anew as described above.

For more advices on installation problems, have a look at the Hfst Readme page.

See also Foma, OpenFST and SFST for problems regarding the back-ends.

[edit] Using

$ svn co
$ cd fao/src
$ make -f Makefile.hfst

$ echo "orð" | hfst-lookup ../bin/fao-morph.hfst
orð	orð+N+Neu+Sg+Nom+Indef
orð	orð+N+Neu+Sg+Acc+Indef
orð	orð+N+Neu+Pl+Nom+Indef
orð	orð+N+Neu+Pl+Acc+Indef


To compile lexc code, first concatenate all the lexc files:

$ cat fao-lex.txt noun-fao-lex.txt noun-fao-morph.txt adj-fao-lex.txt \
adj-fao-morph.txt verb-fao-lex.txt verb-fao-morph.txt adv-fao-lex.txt \
abbr-fao-lex.txt acro-fao-lex.txt pron-fao-lex.txt punct-fao-lex.txt \
numeral-fao-lex.txt pp-fao-lex.txt cc-fao-lex.txt cs-fao-lex.txt \
interj-fao-lex.txt det-fao-lex.txt > ../tmp/lexc-all.txt

To compile this, just use the hfst-lexc program,

hfst-lexc < ../tmp/lexc-all.txt > ../bin/lexc-fao.bin

To compile the twol rules, just use the hfst-twolc program,

$ hfst-twolc twol-fao.txt > twol-fao.bin

And then to compose the lexicon and rule file, use hfst-compose-intersect:

$ hfst-compose-intersect -l lexc-fao.bin twol-fao.bin -o fao-gen.hfst

This will create a generator, if you want an analyser, you just need to invert the generator with hfst-invert:

$ hfst-invert fao-gen.hfst -o fao-morph.hfst

[edit] HFST2 vs HFST3

There have been some changes. Notably:

  • In twol files, a / in alphabetic symbols has to be escaped, e.g. %+Der%/st instead of %+Der/st.
  • In twol files, you can no longer have Sets on the left-hand side of a rule, so write Vx:Vy /<= _ ; where Vx in Set1 Vy in Set2 ; where you before would have Set1:Set2 /<= _ ;
  • The old -r option to hfst-twolc is now uppercase: -R
  • hfst-lookup-optimize is gone, use instead hfst-fst2fst -O -i infile.hfst -o outfile.hfst.ol
  • hfst-lexc needs the outfile option to be before the lexc (input), e.g. hfst-lexc -o outfile.hfst mylexicon.lexc
  • hfst-compose-intersect uses -1 (number one) instead of -l (letter L), and -2 for the rule-file. E.g. hfst-compose-intersect -1 lexicon.hfst -2 rules.twol.hfst -o generator.hfst

[edit] See also

[edit] External links

Personal tools