I want to use GRAKN to model knowledge about an autonomous car. In one example, I want to derive which velocity I have to propose to the autonomous car. I know the maximum speed of the car, I know the speed limit of the road and if the speed limit on the road is not exceeding the maximum speed of the car, I want to propose the car to drive the allowed speed limit. maximum-speed, speed-limit and proposed-speed are attributes of cars or roads. In my example I want to assign the value of 'speed-limit' as the value of 'proposed-speed'. Is this possible in GRAKN?
The following is what I tried. I know it is incorrect, but I expect the solution to look something like this, but than assigning values instead of the whole attribute.
define
max-speed sub attribute, datatype double;
proposed-speed sub attribute, datatype double;
speed-limit sub attribute, datatype double;
drives-on sub relation,
relates vehicle-role,
relates type-of-road;
vehicle sub entity,
has max-speed,
has proposed-speed,
plays vehicle-role;
car sub vehicle;
road-type sub entity,
has speed-limit,
plays type-of-road;
highway sub road-type;
proposed-speed-by-road-type sub rule,
when {
$x isa vehicle, has max-speed $s;
$y isa road-type, has speed-limit $z;
($x,$y) isa drives-on;
$z <= $s;
}, then {
$x has proposed-speed $z;
};
proposed-speed-by-car-max sub rule,
when {
$x isa vehicle, has max-speed $s;
$y isa road-type, has speed-limit $z;
($x,$y) isa drives-on;
$z > $s;
}, then {
$x has proposed-speed $s;
};
insert
$owncar isa car, has max-speed 190;
$highway isa highway, has speed-limit 130;
(vehicle-role: $owncar, type-of-road: $highway) isa drives-on;`
Now, if I query the following: match $x id V82016, has proposed-speed $z; get;
I get:
grakn.core.server.exception.TransactionException-The type [car] is not allowed to have an attribute of type [speed-limit]. Please check server logs for the stack trace.
I get this, because this is not correct. So what I would like is to extract the value of 'speed-limit' and assign it to proposed-speed. Is this possible?
This is possible. Your example is correct. The only condition at the moment is that the respective attribute data types are the same and the types are allowed to have them. Under the hood a new attribute is created with the value copied. We are planning to expand the use case to cover compatible pairs of data types.
It works as expected on current master branch. In general it should also work with 1.5.7, however 1.5.7 has a problem with computing rule equalities which may lead to incorrect result. The problem should be absent in the 1.5.8 release.
Hope that helps!