Is't possible to assign a value to an attribute in a class (schema node)?


#1

I try:

define cabernet_sauvignon sub wine, has flavor 'moderate_flavor';

and I get:

mismatched input ''moderate_flavor'' expecting {'match', 'define', 'undefine', 'insert', 'compute'}


#2

I’d do it like this:

define

name sub attribute, datatype string;
flavor sub attribute, datatype string;

wine sub entity,
has name;
has flavor;

insert $w isa wine, has name “Cabernet Sauvignon”, has flavor “moderate”;


#3

Thanks for your prompt response. What you suggest is correct, but the model requires that ‘cabernet_sauvignon’ be a class and not an entity.

I was able to make this definition indirectly through a rule:

define cabernet_sauvignon_flavor sub rule,
when {
$ s isa cabernet_sauvignon;
}, then {
$ s has flavor ‘moderate_flavor’;
};

But it is not possible to do it directly, that is, in the definition of the class?


#4

I guess if you need it you can just make it like this:

define

name sub attribute, datatype string;
flavor sub attribute, datatype string;

wine sub entity,
has name;
has flavor;

cabernet_sauvignon sub wine;

insert $w isa cabernet_sauvignon, has flavor “moderate”;


#5

you’re right about using a rule for your use-case, and the answer given by @kristall can get you there.

having:

define

  name sub attribute, datatype string;
  flavor sub attribute, datatype string;

  wine sub entity,
    has name;
    has flavor;

cabernet_sauvignon sub wine;

you can infer cabernet_sauvignon using the following rule definition:

define

  wine_with_moderate_flavor_is_cabernet_sauvignon sub rule,
    when {
      $x isa wine, has flavor "moderate";
    }, then {
      $x isa cabernet_sauvignon;
    }