GrammaticalFramework/gf-core

pgf.PGFError: Unknown expression tag

Closed this issue ยท 4 comments

Hello GF team,
I just started to try GF with python. I tried to run the starting example showed here https://github.com/GrammaticalFramework/gf-core/blob/master/src/runtime/python/examples/translation_pipeline.py
But I get an error and I don't know how to fix it. Thank you so much for the help!

OS: Ubuntu 20.04 (It produces the same error on MacOS Monterey as well)
Python version:3.8.3

Reproduction

Install pyg with pip install pgf

create the following toy grammar files:

Food.gf

    abstract Food = {
  
      flags startcat = Phrase ;
  
      cat
        Phrase ; Item ; Kind ; Quality ;
  
      fun
        Is : Item -> Quality -> Phrase ;
        This, That : Kind -> Item ;
        QKind : Quality -> Kind -> Kind ;
        Wine, Cheese, Fish : Kind ;
        Very : Quality -> Quality ;
        Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ;
    }

FoodEng.gf

concrete FoodEng of Food = {
  
   lincat
     Phrase, Item, Kind, Quality = {s : Str} ;
  
   lin
     Is item quality = {s = item.s ++ "is" ++ quality.s} ;
     This kind = {s = "this" ++ kind.s} ;
     That kind = {s = "that" ++ kind.s} ;
     QKind quality kind = {s = quality.s ++ kind.s} ;
     Wine = {s = "wine"} ;
     Cheese = {s = "cheese"} ;
     Fish = {s = "fish"} ;
     Very quality = {s = "very" ++ quality.s} ;
     Fresh = {s = "fresh"} ;
     Warm = {s = "warm"} ;
     Italian = {s = "Italian"} ;
     Expensive = {s = "expensive"} ;
     Delicious = {s = "delicious"} ;
     Boring = {s = "boring"} ;
}

compile into a pgf file:
gf -make FoodEng.gf

Get the following message


linking ... OK
Writing Food.pgf...

Try to load the pgf file in python.

import pgf
pgffile = "./Food.pgf"
grammar = pgf.readPGF(pgffile)

Error message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pgf.PGFError: Unknown expression tag

Hello @Saibo-creator, thanks for reporting the issue!

What is your GF version? Does it work with any other PGF?
You can download this (Foods grammar compiled on my computer) to make sure that the problem isn't in your GF compiler. https://listenmaa.fi/b/Foods.pgf

If that doesn't help, you can try to install the Python bindings manually, following the steps below.

1. Install the C runtime

1.1 Download the source code at gf-core.

1.2 Go to the directory gf-core/src/runtime/c, where you find installation instructions. Follow them to install the C runtime.

2) Install the Python bindings

After installing the C runtime at gf-core/src/runtime/c, go to gf-core/src/runtime/python and run the following commands:

$ python setup.py build
$ sudo python setup.py install

Hello @krangelov , indeed, it works with pgf==1.0

Hello @Saibo-creator, thanks for reporting the issue!

What is your GF version? Does it work with any other PGF? You can download this (Foods grammar compiled on my computer) to make sure that the problem isn't in your GF compiler. https://listenmaa.fi/b/Foods.pgf

If that doesn't help, you can try to install the Python bindings manually, following the steps below.

1. Install the C runtime

1.1 Download the source code at gf-core.

1.2 Go to the directory gf-core/src/runtime/c, where you find installation instructions. Follow them to install the C runtime.

2) Install the Python bindings

After installing the C runtime at gf-core/src/runtime/c, go to gf-core/src/runtime/python and run the following commands:

$ python setup.py build
$ sudo python setup.py install

Hello @inariksit , I confirm that I get the same error with https://listenmaa.fi/b/Foods.pgf

I tried to reinstall from source by following your instruction, and I get the following error message when run python setup.py build

(pgf_from_source) โžœ  python git:(master) โœ— python setup.py build
In file included from pypgf.c:5:
In file included from /usr/local/include/gu/mem.h:9:
/usr/local/include/gu/defs.h:195:12: warning: this function declaration is not a prototype [-Wstrict-prototypes]
        void (*fp)();
                  ^
                   void
In file included from pypgf.c:5:
In file included from /usr/local/include/gu/mem.h:10:
/usr/local/include/gu/fun.h:6:21: warning: this function declaration is not a prototype [-Wstrict-prototypes]
typedef void (*GuFn)();
                    ^
                     void
In file included from pypgf.c:9:
In file included from /usr/local/include/pgf/pgf.h:49:
In file included from /usr/local/include/pgf/expr.h:7:
/usr/local/include/gu/seq.h:19:13: warning: this function declaration is not a prototype [-Wstrict-prototypes]
gu_empty_seq();
            ^
             void
pypgf.c:1740:77: error: too many arguments to function call, expected 6, have 7
                pgf_complete(self->concr, type, sentence, prefix, prefix_bind, parse_err, pyres->pool);
                ~~~~~~~~~~~~                                                              ^~~~~~~~~~~
/usr/local/include/pgf/pgf.h:253:1: note: 'pgf_complete' declared here
pgf_complete(PgfConcr* concr, PgfType* type, GuString string, 
^
3 warnings and 1 error generated.
error: command '/usr/bin/gcc' failed with exit code 1

It seems that install pgf==1.0 indeed fixed the error, but I guess the error when installing from source may still be an issue ?