HFST, python setup

248 views Asked by At

I am building a morphological parser with hfst, but am running into problems with installation.
I have successfully downloaded the hfst package, and it is present in the site-packages directory of my python framework. I can import it in python without a problem.
However, when I try to run some of the commands from the quickstart page, I get syntax errors:

>>> import hfst
>>> hfst-lexc -v -f foma finntreebank.lexc -o finntreebank.inverted.hfst
  File "<stdin>", line 1
    hfst-lexc -v -f foma finntreebank.lexc -o finntreebank.inverted.hfst
                       ^
SyntaxError: invalid syntax  

Is the problem that I need to install foma? Or is the interface between the C++ and python not working? It's been difficult to figure this out with the documentation.

Is there a resource for guidance on how to install and use C++ libraries in python?

1

There are 1 answers

0
unhammer On

hfst-lexc -v -f foma finntreebank.lexc -o finntreebank.inverted.hfst is a command that you can run in a Unix shell / command line. It is not Python code.

If you're on Ubuntu or Mac, you can open the Terminal and cd to the directory of that file and run the command there.

See https://hfst.github.io/python/3.12.1/QuickStart.html for some examples of how to use HFST from Python. I don't know if a lexc command is available from the Python API, but it would probably be simplest to just run that example from the command line. You can still use the resulting .hfst file from Python to do lookups and such.