dodaro / cnl2asp

A tool for converting CNL sentences to ASP rules.
https://dodaro.github.io/cnl2asp/
Apache License 2.0
1 stars 0 forks source link

Compiler Error with Set Membership #19

Open GregGelfond opened 1 month ago

GregGelfond commented 1 month ago

Consider the following initial declarations:

Row goes from 1 to 9.

Column goes from 1 to 9.

Value goes from 1 to 9.

grid_square goes from 1 to 9.

A cell is identified by an id, and has a row, and a column.

There is a cell c1 with row equal to 1, and with column equal to 1.
There is a cell c2 with row equal to 1, and with column equal to 2.

Grid_Square S is a set.

These compile pretty much as expected:

row(1..9).
column(1..9).
value(1..9).
grid_square(1..9).
cell("c1",1,1).
cell("c2",1,2).
set(S) :- grid_square(S).

Suppose I want to say that grid_square 1 contains cells c1 and c2.

Adding the following:

Grid_Square 1 contains c1, c2.

gives the following syntax error:

Error trying to process rule "simple_entity":

Compilation error at line 21:
    Entity "contains" not declared before its usage.

If I change the line to:

Grid_Square 1 contains cell c1.
Grid_Square 1 contains cell c2.

I get the expected rules:

contain(1,"c1") :- grid_square(1), cell("c1",_,_).
contain(1,"c2") :- grid_square(1), cell("c2",_,_).

If I however try to use the shorthand (set initialization syntax):

Grid_Square 1 contains cell c1, cell c2.

Then I have a miscompile:

contain(1,"c1") :- grid_square(1), cell("c1",_,_), cell("c2",_,_).
simocaruso commented 4 weeks ago

The definition of sets is supported with the following syntax: set_name "is a set." and you can define the elements (which, currently, can only be strings) of the set by the following syntax: set_name "contains" list_of_elements .

You can have for example:

Grid_Square is a set.
Grid_Square contains c1, c2.

Moreover, set definition, as for the concept definitions, should go at the beginning of the declaration:

Row goes from 1 to 9.

Column goes from 1 to 9.

Value goes from 1 to 9.

grid_square goes from 1 to 9.

A cell is identified by an id, and has a row, and a column.

Grid_Square is a set.
Grid_Square contains c1, c2.

There is a cell c1 with row equal to 1, and with column equal to 1.
There is a cell c2 with row equal to 1, and with column equal to 2.
GregGelfond commented 4 weeks ago

In your example you have this:

grid_square goes from 1 to 9.
...
Grid_Square is a set.

In this situation, is the symbol grid_square the name of a type inhabited by the positive integers 1..9 or is it the name of a single set?

simocaruso commented 2 weeks ago

Sorry, I made a mistake. Names must be unique and they are case insensitive, thus the example is wrong and the symbols should have different names.

I also fixed a bug in using multiple sets, so please update to the latest release.