python - Replace each variable with specific values associated to them -
for university's project i'm developing inference engine written in python , i'm trying introduce in features clips has, 1 of them variables.
actually, in grammar provide way in order specify condition in rule has got variables in using '?' character. in particular, can have rule defined in way:
(rule (father ?x ?y) (assert (parent ?x ?y))
supposing in working memory there these facts:
(father john tom) (father john liz) (father alex mat) (father alex andrew)
with defined rule assert these facts doing variable pattern matching:
(parent john tom) (parent john liz) (parent alex mat) (parent alex andrew)
this situation in , i'm able correctly match each variable possible values present in wm.
in case create dictionary keys variables's identifier (?x or ?y) , values values present in wm associate variables (e.g {?x:[john, alex], ?y:[tom, liz, andrew]})
my question is: how can correctly dispose variables' possible values in correct manner in order facts should asserted?
thank in advance,
alessandro suglia
something maybe?
bank = { ("john","tom"): ("father", "parent"), ("john","liz"): ("father", "parent"), ("alex","mat"): ("father", "parent"), ("alex","andrew"): ("father",)} x = ("john", "alex") y = ("tom","liz","mat","andrew") def assert_then_xy(trait1, trait2): my_x in x: my_y in y: if (my_x,my_y) in bank.keys(): if trait1 in bank[my_x,my_y] , not trait2 in bank[my_x,my_y]: print "{} {} {}, not {}".format(my_x,my_y,trait1,trait2) else: print "{} {} not located".format(my_x,my_y) >>> assert_then_xy("father", "parent") john mat not located john andrew not located alex tom not located alex liz not located alex andrew father, not parent >>> assert_then_xy("parent", "father") john mat not located john andrew not located alex tom not located alex liz not located >>>
Comments
Post a Comment