Default values in grakn schema


#1

Adding default values in Grakn schema

I was wondering if it is possible to add default values to entities in the schema. For example, if you create a knowledgebase of vehicles and you want to add some default values for speeds of different vehicles (bike: speed = 10, car: speed = 50).
And if this is possible, is there also a way to ensure that when I add a car in the data, it gets this default speed unless I specify it otherwise?

Thanks in advance!


#2

Defining default values within a define query (in the schema) isn’t currently supported. You can issue a feature request for this in the Graql repository.

At the moment, you can accomplish this by implementing it at the application layer using one of the clients.


#3

It is possible to add default values to the schema indirectly through rules, here is an example:

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


#4

You’re correct. It is technically possible to use rules to accomplish this. Having said that, it really comes down to your intention. In this case, which involves assigning an attribute with a default value to a concept type, the desire to do so should not be hidden away from you and your development team and so the implementation should not be implemented as a rule, but at the application layer (or within the definition of the concept type in question within the schema, which is currently not supported).

Rules are most appropriate when they are used for the purpose of abstracting away underlying relationships (logic) to provide a definitive conclusion that is convenient and/or insightful.