Its is posible to define a relation between a class and a instance?


#1

Its is posible to define a relation between a class (schema node) and a instance (data node)?

The context:

define 
	
	name sub attribute, datatype string;

	wine_color sub relation,
		relates wine_color_s,
		relates wine_color_o;	
	
	wine sub entity, key name, plays wine_color_s;
	cabernet_sauvignon sub wine;
	color sub entity, key name, plays wine_color_o;

insert 
	$x isa color, has name 'red';
	$x isa cabernet_sauvignon, has name 'forman_cabernet_sauvignon';

I try:

match 
    $s has name 'forman_cabernet_sauvignon'; 
    $o has name 'red'; 
insert $r (wine_color_s: $s, wine_color_o: $o) isa wine_color;

It works, I get:

{$r id V40968368 (wine_color_o: id V16408, wine_color_s: id V12416) isa wine_color; $s id V12416 isa cabernet_sauvignon; $o id V16408 isa color;}

Then I try:

match 
    $s type cabernet_sauvignon; $o has name 'red'; 
insert $r (wine_color_s: $s, wine_color_o: $o) isa wine_color;

It doesn’t work, I get:

Error: UNKNOWN: The concept [Base Type [ENTITY_TYPE] - Id [V37088]  - Label [cabernet_sauvignon] - Abstract [false] ] is not of type [interface grakn.core.concept.thing.Thing]. Please check server logs for the stack trace.

#2

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

define cabernet_sauvignon_red sub rule,
when {
$s isa cabernet_sauvignon;
$o has name ‘red’;
}, then {
(wine_color_s: $s, wine_color_o: $o) isa wine_color;
};

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


#3

From how I understand it, the problem is in “$s type cabernet_sauvignon”. The word “type” is not right here, try “isa”.


#4

Hi @jeposadap

I don’t think I quite understand, what you’re trying to accomplish here.

Is modelling wine_color as a relation intentional, rather than having the color attribute to be owned by the wine entity?


#7

I need to establish a default relationship for all individuals (data nodes) belonging to a class (schema node). I think he doesn’t present a good example. Then I allow myself to present one that I consider best:

The context:

define
name sub attribute, datatype string;

wine_region sub relation,
relates wine_region_s,
relates wine_region_o;

wine sub entity, key name, plays wine_region_s;

region sub entity, key name, plays wine_region_o;

french_wine sub wine;
insert

$x isa region, has name ‘france’;

When I try:

match
$s type french_wine; $o has name ‘france’;
insert $r (wine_region_s: $s, wine_region_o: $o) isa wine_region;

It doesn’t work. I was able to make this definition indirectly through a rule:

define french_wine_region sub rule,
when {
$s isa french_wine;
$o has name ‘france’;
}, then {
(wine_region_s: $s, wine_region_o: $o) isa wine_region;
};

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