Re: Creating specific facts from generic facts?

41 views
Skip to first unread message

Artem Novikov

unread,
Oct 11, 2012, 7:23:00 AM10/11/12
to clip...@googlegroups.com
You must specify a slot name

(modify ?ne (id (nth$ ?cnt1 $?names)))


среда, 10 октября 2012 г., 4:22:15 UTC+8 пользователь John Whelan написал:
I have been attempting to generate 'specific facts from generic facts. The basic use case is that I want to have a generic framework from which I call business-logic specific rules. In general, the framework will have no idea as to what types of facts need to be generated. Where I'm running into problems is in the 'modify' code. I believe that using run-time resolved slot name is causing me problems, but I could be wrong. The specific code that I have at present is:

(defrule PopulateNnElementFromGenElement
   ?ge <- (genElement (id ?id) (names $?names) (values $?values) (multinames $?multinames) (multivalues $?multivalues) )
   ?ne <- (nnElement (id ?id))
   =>
   ; for loop through the names
   (loop-for-count (?cnt1 1 (length$ $?names)) do
     (printout t "(nth$ ?cnt1 $?names)  = " (nth$ ?cnt1 $?names) crlf)
     (printout t "(nth$ ?cnt1 $?values) = " (nth$ ?cnt1 $?values) crlf)
     ;(modify ?ne ( (nth$ ?cnt1 $?names) (nth$ ?cnt1 $?values) ) )
   )
   (printout t "PopulateNnElementFromGenElement!" crlf)

   ; TODO: do the same thing for multinames/multivalues
   ;(deftemplate genElement
   ;(multislot names)
   ;(multislot values)
   ;(multislot multinames)
   ;(multislot multivalues))
)

When I uncomment the modify statement I get the following error.

[PRNTUTIL2] Syntax Error:  Check appropriate syntax for duplicate/modify function.

ERROR:
(defrule MAIN::PopulateNnElementFromGenElement
   ?ge <- (genElement (id ?id) (names $?names) (values $?values) (multinames $?multinames) (multivalues $?multivalues))
   ?ne <- (nnElement (id ?id))
   =>
   (loop-for-count (?cnt1 1 (length$ $?names))  do
      (printout t "(nth$ ?cnt1 $?names)  = " (nth$ ?cnt1 $?names) crlf)
      (printout t "(nth$ ?cnt1 $?values) = " (nth$ ?cnt1 $?values) crlf)
      (modify ?ne ((

otherwise I get the expected output.

(nth$ ?cnt1 $?names)  = type
(nth$ ?cnt1 $?values) = node
(nth$ ?cnt1 $?names)  = weight
(nth$ ?cnt1 $?values) = 50
PopulateNnElementFromGenElement!

Any way around this? (I hope it isn't that I'm doing something stupid...) Thanks.

John Whelan

unread,
Oct 11, 2012, 11:05:20 AM10/11/12
to clip...@googlegroups.com
Bummer...

I was hoping to find a way around doing that because it greatly impacts the generic nature of the rule.

I have hit a problem in my looping code. I believe that the root cause of this other problem is since a 'modify' is "equivalent to retracting the present fact and asserting the modified fact" that my use of "modify ?ne" is only good for the first modification. (I suppose that I'll have to find a way to either reassign 'ne' or have a rule triggered for each possible slot name in the 'concrete' fact...

sigh...
Reply all
Reply to author
Forward
0 new messages