Conditionals in Graql and GRAKN?


#1

Hi, I’m wondering if there is any support for conditionals natively within Graql?
What I’m trying to achieve is something like:

IF isa recipe has sauce “curry”, has seasoning “rock_salt”;
THEN insert $p isa cook has forename “Aziz”, has middle-name “Aba”, has surname “Sharma”;

Can’t seem to find references to such functionality in the online documentation, so any tips welcome!


#2

Hi @gmkun

match insert may be what you’re looking for.

In a match insert query, the insert query is executed for every instance that is found in the dataset via the preceding match clause. In your example, if no recipe with curry and rock salt is found, then the insert query never runs. If n recipes are found, then the insert also runs n times.

If match insert doesn’t answer your question, then I believe you’d need to achieve the desired outcome by running multiple queries using one of the Grakn Clients.


#3

Hi @soroush, thanks for the quick reply!

What I’m trying to achieve here is basically recreate the deCheem inference framework (see here) in GRAKN.
The idea is to set a backdrop of assumptions and known statements, and then allow questions to be asked of it. Some of the statements in the backdrops are only true under certain asking/query conditions, which means the statements that will be taken into account needs to change for every set of questions asked.

I indeed saw the match-insert documentation, but the shortcoming of that is that once the insert has taken place, it persists until a update/delete has been done on that statement, correct? This means that in any case I’ll have to create client-side logic to do a rinse-and-repeat logic on every run to make sure there are no ‘cross-contamination’ of statements between sessions.

Let me know if my understanding is correct!