Infer existence of an entity?

I would like to create a rule which infers the existence of an entity if it doesn’t already exist. For example, all jedi masters have an apprentice:

apprenticeship sub relation,
  relates apprentice,
  relates master;

Is there a way to infer that if there is a jedi master, there is always an apprentice, and create the apprentice?

rule masters-always-have-an-apprentice:
  when {
    $p1 isa person, has status "master";  # There is a jedi master
    not {(apprentice: $p2, master $p1) isa apprenticeship;}; # That master has no apprentice
  } then {
    $p2 isa person, has status "padawan"; # Create an apprentice
    (apprentice: $p2, master $p1) isa apprenticeship; # Create an apprenticeship relation

I would like it to create both the apprentice and the apprenticeship relation… It appears from the error message that I can only use a rule to create an attribute ownership or a relation.

Is there some way to do this? Or perhaps a workaround?

Hi @thayne

Rules can only infer relations or attributes or attribute ownerships at this point in time.

There’s a further restriction in place that we derive from horn clauses that we can only have 1 conclusion at a time for a rule. We may relax this in the future, but for the time being we allow exactly this set of rule forms: Rules | Vaticle

We have found many problems can be modeled within these restrictions, so hopefully your domain will also find a way to fit!