Skip to content

Experimental: Closer to natural language

mantkiew edited this page Jan 16, 2012 · 6 revisions

Making Clafer closer to natural language. I realize that introducing many different ways to say the same thing may be confusing but using what people already know is always easier than learning new symbols. The readability of the models is very important for communication and we want the models to be as self explanatory as possible.

“no” and “not” as alternatives for !

In natural language, we use “no” with nouns, e.g., “there are no apples”, and we use “not” with adjectives, e.g., “This apple is not red”. In clafer, we only have “!” and “no”. We also need “not”. All of these should be interchangeable. For example:

abstract AppleBasket 
    apples -> Apple *

abstract Apple
    xor color
        red
        green    
        yellow

MyApple : Apple
    [ not red 
      not yellow ]    // will be inferred green due to xor

MyAppleBasket : Basket
    [ no apples ]     // there are not apples in my basket

“a” and “an” as alternatives for cardinality 1

In natural language I say “I have an apple, a green apple, and some yellow apples in my basket”. (The following example is contrived to illustrate the keywords, not the best way of modeling such a sentence).

MyBasket : Basket
    apple : apples *
    greenApple : apples *
        [ green ]
    yellowApples : apples * 
        [ yellow ]
    [ an apple             // equivalent to # apple = 1
      a greenApple         // equivalent to # greenApple = 1
      some yellowApples ]  // that's correct today

Also, I should always be able to say “There’s a green apple” like that
an Apple          // expanded to "`Apple"
    [ green ]

as opposed to “My apple is green”

MyApple : Apple  
    [ green ]

clafer cardinality first, group cardinality after

The notation for constraints above is natural but the notation for cardinalities in clafer definitions is reversed. The following would be a more natural way, which would also be consistent with the current notation for constraints.

Consider a sentence: “Alice has a head, two hands, maybe blond hair, no mustache, and some skills. Alice is not an adult.”. The corresponding more natural Clafer model should be

Alice
   a head            // equivalent to "1 head". "one head" would also be nice.
   2 hands           // "two hands" would also be nice
   maybe blondHair   // equivalent to "? blondHair"
   no mustache       // equivalent to "0..0 mustache"
   some skill        // equivalent to "+ skill"
   not adult         // equivalent to "0..0 adult"

Here’s an example from the previous section modeled more naturally:

MyBasket : Basket
    an apple : apples
    a greenApple : apples
        [ green ]
    some yellowApples : apples
        [ yellow ]

“is” and “are” as alternatives for “=”

In natural language, we say “The participants of a meeting are Alice, Bob, and Carol. The chair of the meeting is Alice”. The corresponding model should be:

a Meeting            // equivalent to 1 `Meeting
    [ participants are Alice, Bob, Carol      // equivalent to "participants = Alice ++ Bob ++ Carol"
      chair is Alice ]                        // equivalent to "chair = Alice"