label descent

Here is a little beasty that adds a lot of power to BKO.
And it is usually used in conjunction with stored_rules.

The idea is, if you are trying to do:
context.recall(a,b), and no match is found with the specific value of b, try more and more general rules.

Here is some of the python:
def label_descent(x):
  print("x:",x)
  result = [x]
  if x == "*":
    return result
  if x.endswith(": *"):
    x = x[:-3]
  while True:
    try:
      x,null = x.rsplit(": ",1)
      result.append(x + ": *")
    except:
      result.append("*")
      return result

eg, if you feed in this label "a: b: c: d: fred", it returns these trail labels:
a: b: c: d: fred
a: b: c: d: *
a: b: c: *
a: b: *
a: *
*
So given something like this:
op |a: b: c>
if that has no match, then the code next tries:
op |a: b: *>
if that has no match, then the code next tries:
op |a: *>
if that has no match, then the code next tries:
op |*>
if that has no match, then return |>.

Where we consider:
op |a: b: c>
to be a more specific rule than the more general rule:
op |a: b: *>
which is more specific than say:
op |*>

Anyway, the key code in context.recall() is (though without knowing the details of the context class it probably doesn't make a lot of sense):
    match = False
    for trial_label in label_descent(label):
      if trial_label in self.known_kets:
        if op in self.rules[trial_label]:
          rule = self.rules[trial_label][op]
          match = True
          break
    if not match:
      print("recall not found")               
      rule = ket("",0)
Take home message, this thing is seriously powerful, and useful. That's it for now.


Home
previous: current weather in adelaide in sw format
next: the self ket

updated: 19/12/2016
by Garry Morrison
email: garry -at- semantic-db.org