|
Hi,
I have tried to use defquery and
understand its behaviour, but it seems to have a side affect with it which I do
not yet understand. I am trying to solve a problem using defquery.
The problem:
I have a few deftemplates. These
deftemplates have some slots that link them together logically.
ex
(deftemplate example
(slot exampleno)
)
(deftemplate answer
(slot answerstring)
(slot exampleno)
)
I have a
logical connection between answer and example. So if I change the exampleno in
one template I want to change it in another template. To do that I find the fact
in the fact list using defquery then modify the value for the corresponding
templates. I have sent a piece of my code below. A help with it would be
appreciated. But it has got a side affect as mentioned. The engine asserts some
facts and keeps on reseting, from the time the defquery runs. I could get
around the problem with defining a rule each for all the templates I have but it
becomes too cumbersome and it may be more time consuming. So I wrote a function
with defquery, to find all the templates related to each other and update them
all at one place. I would like to know how can I use the defquery to give me the
result I want, without the side affect. Also I would like to know if I can do
the same by writing a funcion in java, and how. The fuction code is given below.
Also below the code is a "watch rules" output. Also which would be the best way
to solve the problem without side effects.
1) Defqueries as shown below(without the side
effects) , if not, then how would I go about it?
2) Write a rule for every template I want to update
or change
3) write a function in java? For this option if you
could give me a hint on how to use it, it would be appreciated.
Thank you
chetan bhatia.
CODE :
(deffunction duplicatesentences
(?sn)
(printout t "I am going to run query") (bind ?a (run-query search-sanGyA ?sn)) (bind ?b (run-query search-kriya ?sn)) (bind ?c (run-query search-avya ?sn)) (bind ?d (run-query search-viSeSn3 ?sn)) (set-fact-duplication TRUE) (while (?a hasMoreElements) (bind ?to-print (fact-id (call (call (call ?a nextElement) fact 1) getFactId))) (bind ?temp (assert ?to-print)) (modify ?temp (snumber (eval (str-cat ?sn @0)))) (printout t ?temp) ) (while (?b hasMoreElements) (bind ?to-print (fact-id (call (call (call ?b nextElement) fact 1) getFactId))) (bind ?temp (assert ?to-print)) (modify ?temp (snumber (eval (str-cat ?sn @0)))) ) (while (?c hasMoreElements) (bind ?to-print (fact-id (call (call (call ?c nextElement) fact 1) getFactId))) (bind ?temp (assert ?to-print)) (modify ?temp (snumber (eval (str-cat ?sn @0)))) ) (while (?d hasMoreElements) (bind ?to-print (fact-id (call (call (call ?d nextElement) fact 1) getFactId))) (bind ?temp (assert ?to-print)) (modify ?temp (snumber (eval (str-cat ?sn @0)))) ) (set-fact-duplication FALSE) (printout t "")
) RULES OUTPUT :
FIRE 1 find-language f-3
FIRE 2 counter-initiate f-0, FIRE 3 parse-granTa f-4, f-2 FIRE 4 parse-vAkya f-34 FIRE 5 do-parse f-35 FIRE 6 duplicate-sentences f-37,, FIRE 7 duplicate-rest f-41 I am going to run query ***************** side effect FIRE 1 do-parse f-36 *****************started firing again FIRE 2 duplicate-sentences f-44,, FIRE 3 do-parse f-43 FIRE 4 duplicate-sentences f-49,, FIRE 5 do-parse f-48 FIRE 6 duplicate-sentences f-54,, FIRE 7 do-parse f-53 FIRE 8 duplicate-sentences f-59,, FIRE 9 do-parse f-58 FIRE 10 duplicate-sentences f-64,, FIRE 1 do-parse f-63 FIRE 2 duplicate-sentences f-70,, FIRE 3 do-parse f-69 FIRE 4 duplicate-sentences f-75,, FIRE 5 do-parse f-74 FIRE 6 duplicate-sentences f-80,, FIRE 7 do-parse f-79 FIRE 8 duplicate-sentences f-86,, FIRE 9 do-parse f-85 FIRE 10 duplicate-sentences f-91,, FIRE 1 do-parse f-90 FIRE 2 duplicate-sentences f-97,, FIRE 3 do-parse f-96 FIRE 4 duplicate-sentences f-102,, FIRE 5 do-parse f-101 FIRE 6 duplicate-sentences f-107,, FIRE 7 do-parse f-106 FIRE 8 duplicate-sentences f-112,, FIRE 9 do-parse f-111 FIRE 10 duplicate-sentences f-117,, FIRE 1 do-parse f-116 FIRE 2 duplicate-sentences f-123,, FIRE 3 do-parse f-122 FIRE 4 duplicate-sentences f-128,, FIRE 5 do-parse f-127 FIRE 6 duplicate-sentences f-133,, FIRE 7 do-parse f-132 FIRE 8 duplicate-sentences f-138,, FIRE 9 do-parse f-137 FIRE 10 duplicate-sentences f-143,, <Fact-147><Fact-148><Fact-149>FIRE 8 get-common-viSeSn3 f-3, f-40,, f-153,, f-47, f-154 FIRE 9 get-common-viSeSn3 f-3, f-40,, f-153,, f-47, f-154 FIRE 10 get-common-viSeSn3 f-3, f-162,, f-163,, f-52, f-155 FIRE 11 combine-sanGyA-viSeSn3 f-57,, f-147, f-167, f-168, I AM GOING TO ASSERT IN SANGYA-VISESN
FIRE 12 get-common-viSeSn3 f-3, f-94,, f-156,, f-100, f-157 FIRE 13 get-common-viSeSn3 f-3, f-173,, f-174,, f-105, f-158 FIRE 14 get-common-viSeSn3 f-3, f-176,, f-177,, f-110, f-159 FIRE 15 get-common-viSeSn3 f-3, f-179,, f-180,, f-115, f-160 FIRE 16 do-parse f-142 FIRE 17 duplicate-sentences f-186,, FIRE 18 duplicate-rest f-190 I am going to run query FIRE 1 do-parse f-185 FIRE 2 duplicate-sentences f-193,, FIRE 3 do-parse f-192 FIRE 4 duplicate-sentences f-198,, FIRE 5 do-parse f-197 FIRE 6 duplicate-sentences f-203,, FIRE 7 do-parse f-202 FIRE 8 order f-3 FIRE 9 initialize f-34, f-207 FIRE 10 parseorder f-208, f-34 FIRE 1 parseorder f-209, f-34 FIRE 2 parseorder f-212, f-34 FIRE 3 parseorder f-214, f-34 FIRE 4 parseorder f-216, f-34 FIRE 5 parseorder f-218, f-34 FIRE 6 parseorder f-220, f-34 FIRE 7 parseorder f-222, f-34 FIRE 8 parseorder f-224, f-34 <Fact-229><Fact-230><Fact-231><Fact-232><Fact-233><Fact-234><Fact-235><Fact-236><Fact-237><Fact-238>18 |
