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

Incomplete Documentation on Entities #6

Closed GregGelfond closed 1 month ago

GregGelfond commented 2 months ago

In keeping with finding a potentially more elegant, or natural expression of the "Zebra Puzzle", I'm trying to understand how to use entities. Consider the following declarations:

A house goes from 1 to 5.
A color is one of Red, Green, Blue, Yellow, Ivory.
A beverage is one of Coffee, Tea, Milk, Water, Juice.
A person is one of Englishman, Spaniard, Ukrainian, Norwegian, Japanese.
A pet is one of Dog, Horse, Zebra, Snail, Fox.
A cigarette is one of Chesterfields, LuckyStrikes, Kools, OldGold, Parliaments.

This works, and "creates" the appropriate (i.e., intuitive ASP encoding of the basic types/objects). If I want to move to some alternative representation such as this one (using entities):

An address goes from 1 to 5.
A color is one of Red, Green, Blue, Yellow, Ivory.

A house is identified by an address and has a color.

Then I have the intuitive compilation of address and color, but nothing really for house. The documentation here is a bit sparse, so I'm curious about:

  1. How do I create individual houses?
  2. How would I write a choice rule to assign potential colors to houses?
dodaro commented 2 months ago

The sentence

A house is identified by an address and has a color.

is a way to explicitly define concepts, but it is not translated to ASP. You can use the attributes of your definition later on in the CNL.

As for example, to create an individual house: A house is identified by an address, and has a color. There is a house with address 1, and with color equal to Red.

Then, you can assign colours to house: Whenever there is a address, then we can have exactly 1 a house with color C such that there is a color C.

GregGelfond commented 2 months ago

Is there any form of syntactic sugar that would allow for something like the following:

An address goes from 1 to 5.
A color is one of Red, Green, Blue, Yellow, Ivory.

A house is identified by an address and has a color.

For every address there is exactly 1 house.

// Alternatively: Every address identifies exactly 1 house.
dodaro commented 2 months ago

I am not sure, what do you want to obtain in this case?

In general, you can use the form "verb to" to create new definitions.

An address goes from 1 to 5. A color is one of Red, Green, Blue, Yellow, Ivory. Every address can be assigned to exactly 1 color.

GregGelfond commented 2 months ago

There's possibly a conflict of intuitions on my part.

When I see:

A house is identified by an address and has a color.

My intuition is that I have a collection of houses "right off the bat", each uniquely identified by an address. So using your sample as snippets, my intuition suggests:

address(1..5). % <- from the declaration of address

house(H) :- address(H).
% ^ derived from the declaration of house, which
% asserts that each house is uniquely identified by an address.

I can then also use a binary predicate house/2 to talk about the color of a house. So the C is the color of house H would be analogous to house(H,C). This also suggests a simpler form using the possessive house H's color...

In general I'm trying to develop some best practices of CNL to determine when to use entities. From a KR perspective it feels a bit natural to say that a house is identified by its address and has a color (and an owner, etc.).

I would then be able to say for example:

Every house has exactly 1 color.
It is prohibited for the number of houses that have color C to be greater than 1.

// Or alternatively: It is prohibited for the number of houses with the same color to be greater than 1.
dodaro commented 2 months ago

A sentence like

A house is identified by an address and has a color.

is an explicit definition of the concept house. You can imagine it as a description of a table in a database. So, it is not intended to create rules. This is used to refer to the attributes of the house in the other sentences (otherwise we do not know that a house has an address).

Instead, a sentence of the form

An address goes from 1 to 5.

is an implicit definition. It means that it creates a concept of address, but we don't have a high level description of what is the attribute (e.g., in your example we know that it ranges from 1 to 5 but we don't know if this is an id or another thing).

dodaro commented 2 months ago

Here you can find a possible way of describing your problem:

A house goes from 1 to 5.
A color is one of Red, Green, Blue, Yellow, Ivory.
A beverage is one of Coffee, Tea, Milk, Water, Juice.
A person is one of Englishman, Spaniard, Ukrainian, Norwegian, Japanese.
A pet is one of Dog, Horse, Zebra, Snail, Fox.
A cigarette is one of Chesterfields, LuckyStrikes, Kools, OldGold, Parliaments.

Every house can be assigned to exactly 1 color, beverage, person, pet, and cigarette.
Every color can be assigned to exactly 1 house.
It is prohibited that house 1 is not assigned to color Red.
It is required that house 1 is assigned to color Red.
It is required that a house X is assigned to color C, when a house Y is assigned to color C, where X is equal to Y+1.
It is required that a house is assigned to color Blue, when a house is assigned to pet Dog.
GregGelfond commented 1 month ago

I'm still trying to play with the notion of concepts and entities. Here's a simple example that I tried to base off your earlier example:

// Primitive Elements

A department_code is one of csci, phil, math, isqa.
A course_number is one of 1400, 3450, 4400.

// Courses

A course is identified by a department_code, and by a number.

// Example Courses

There is a course with department_code equal to csci, and with course_number equal to 3450.

When I attempt to convert this to ASP, I get the following compilation error:

cnl2asp cnl-encodings/courses.cnl
Error trying to process rule "simple_entity":

Compilation error at line 12:
    Entity "course" do not contain attribute "department_code csci".

Can you help me understand what the error is? Ultimately, I'd like to be able to have a description of a row in database table which has a list of courses provided by a college, where each course is identified by a department code + course number, and has a number of additional attributes. I'm trying to work my way "up" to that final notion, but seem to be missing something either in intuition with the syntax, or some gaps in the documentation/examples.

simocaruso commented 1 month ago

The error generated by your example should be:

Compilation error at line 12:
    Entity "course" do not contain attribute "course_number id".

Which means that "course" has not been defined with the attribute "course_number". Therefore, you should replace "course_number" with "number" as follows: There is a course with department_code equal to csci, and with number equal to 3450. or change the definition of "course".

GregGelfond commented 1 month ago

Thanks!