Inferred attributes problem?


#1

Hello, I’m trying to learn about inferred attributes with code from the example-inference which is part of the sample-projects. I’d like to display a link between the city ‘Roma’ and the inferred world region in the grakn visualizer.

I run query:

match $x isa city has name ‘Roma’ has local-district $d has inf-world-region $ir; offset 0; limit 30; get;

and get error message: The type [city] is not allowed to have an attribute of type [world-region]
How to fix this ? Thanks!

define

country sub entity
has name
has countrycode
has continent
has world-region
has inf-local-district
plays contains-city;

city sub entity
has name
has local-district
has inf-continent
has inf-world-region
plays in-country;

name sub attribute datatype string;
countrycode sub attribute datatype string;
continent sub attribute datatype string;
world-region sub attribute datatype string;
local-district sub attribute datatype string;
inf-local-district sub attribute datatype string;
inf-continent sub attribute datatype string;
inf-world-region sub attribute datatype string;

has-city sub relationship
relates contains-city
relates in-country;
contains-city sub role;
in-country sub role;

insert $country0 isa country has name “Italy” has countrycode “ITA” has continent “Europe” has world-region “Southern Europe”;
match $country0 isa country has countrycode “ITA”;
insert $city0 isa city has name “Roma” has local-district “Latium”;
(contains-city: $country0, in-country: $city0) isa has-city;

define
city-in-region sub rule
when
{(contains-city: $country1, in-country: $city1) isa has-city;
$country1 has world-region $region1;
}then
{$city1 has inf-world-region $region1;};
city-in-continent sub rule
when
{(contains-city: $country1, in-country: $city1) isa has-city;
$country1 has continent $continent1;
}then
{$city1 has inf-continent $continent1;};
country-in-district sub rule
when
{(contains-city: $country1, in-country: $city1) isa has-city;
$city1 has local-district $district1;
}then
{$country1 has inf-local-district $district1;};


#2

Your definition of city doesn’t allow it to have an attribute of type world-region. Corrected definition should look like this:

city sub entity
has name
has local-district
has inf-continent
has inf-world-region
has world-region
plays in-country;

#3

Ok, got it to work! Thank you so much!