Clips: Restriction in the variable of a vector to search - clips

This is the Clips code that i am trying to arrange. I have some vector in de BH and I want to search among them, those which ?P is common between them. Moreover in the second vector to search the restriction is that ?E can only be that types. Please help me.
(defrule padre
(es-padre ?P ?H)
(?E & :(tigre | leopardo | jirafa | cebra | avestruz | pinguino | albatros) ?P)
=>
(assert (?E ?H))
)
Is there any solution implementing a Switch case, or the unique solution is making more rules?

You have multiple syntax errors, so it's hard to tell what you're trying to do. To start, the first field of a pattern or fact you're asserting can't be a variable. If you include examples in your question (such as the facts you're asserting and what should happen when your rule executes) it will make it easier to answer your question.

Related

How normalize case sensitive input using read in CLIPS?

I am a beginner in CLIPS. I need to interact with the user using read function. My problem is if the user says Yes is different to YES and to yes.
I was looking a long time in the documentation but I couldn't find any to normalize my input. I try with things like upper or normalize but don't exist in CLIPS.
Look in the CLIPS 6.4 Basic Programming Guide (http://www.clipsrules.net/Documentation.html) under section 12.3, String Functions. Section 12.3.7, Converting a String to Uppercase, describes the upcase function, and section 12.3.8, Converting a String to Lowercase, describes the lowcase function.
CLIPS (6.4 2/9/21)
CLIPS> (lowcase (read))
Yes
yes
CLIPS> (upcase (read))
no
NO
CLIPS>

Get rule body in CLIPS

I am new to CLIPS development and I need to retrieve a rule body and store it in string in order to parse it. I tried to redirect the defrule stream but without success.
Is there any way to do it like that or does it exist a special command that I would have forgotten.
(defrule one
(fact a)
=>
(assert (fact b)))
(bind ?str (ppdefrule one))
one rule displaying but ?str is empty
Thank you for your time and consideration.
There's not a clean way to do this out of the box, but there's a C API for retrieving the text, so you could extend CLIPS with a user-defined function to allow you to do this. The alternative would be to use dribble-on/dribble-off to capture the output in a file, but this would also display the output to the screen each time you retrieved the rule text.

Forward Chaining using variables in rules in CLIPS

So, I'm trying to make a "golf club recommendation system" for a 18 hole course. Now, after having defined the basic templates for the golfcourse, golf club and the golf player, I'm stuck due to the large search space this particular problem presents. So currently I have:
(defrule teeoff
?g <- (golfer (position "tee"))
=>
(retract ?g)
(assert (golfer (position "fairway") (Current_club "driver") (Yardage 650))
After this, the ball is on fairway and can have a combination of factors say, it can be on sand, it can be on rough or it could be on a normal green. My question is instead of making a rule for every possibility can I have one or two rules like:
(defrule makemove
?m <- (golfer (position ?x))
?go <- (golfcourse (obstacles ?$y)
=>
(assert (golfer (Current_club ?c)))
If not, then what alternatives do I have?
I suggest to you to design an object or attribute to manage the ground_material (sand, green, ...) and include it inside the rule.
You can write rule for each ground or use IF-THEN condition inside a single rule.
Hope this helps you.
bye
Nic

CLIPS: Retrieving a fact and getting a pointer to it

I am working with CLIPS embedded in a C program, so I have to do everything by C function calls and can't use the CLIPS command line.
Let's say I have asserted a few facts like this:
AssertString("(pizza 1)");
AssertString("(cauliflower 7)");
AssertString("(cheesecake 0)");
Obviously I do not get (let alone retain) any pointers to my facts at this point. When I want to retract a fact later by using Retract(factPtr), I obviously need the pointer to the fact I want to retract. So, after the lines above, how would I find the fact (cauliflower 7) again and get a pointer to it?
Do I have to get the entire fact list by GetFactList([...]), loop through it and compare strings? If so, how would I do that in the multifield DATA_OBJECT this function returns? Or is there a better way?
I would be grateful for any ideas or even code examples.
You can use the fact query functions to query the fact-list and perform actions. You can invoke this through the EvalFunction:
DATA_OBJECT result;
Eval("(do-for-all-facts ((?f pizza)) (eq ?f:implied (create$ 1)) (retract ?f))",&result);
Eval("(do-for-all-facts ((?f cauliflower)) TRUE (retract ?f))",&result);
In the first call, only the pizza fact with the value 1 is retracted. In the second call, all cauliflower facts are retracted.

Flora-2 diamond inheritance

Flora-2 is an eccentric language and I know this is a long shot but I haven't found any active resources devoted to it so I'm trying here. Its so popular... there is no stackoverflow tag for it. If you know anything about the status and future of Flora-2 and XSB Prolog, I'd love to hear that, too.
Can someone explain Flora-2 diamond-inheritance rules to me? The manual has an example but doesn't show the results of the example. The wording seems to be the opposite of what I see in the interpreter and in the diamond.flr demo. Here's the demo:
c[f*->g].
c1[f(a)*->a]::c.
c2[f(b)*->b]::c.
o:c1.
o:c2.
?- ?X[?Y->?Z].
(What I see happens with or without the base class c)
The manual says:
At the level of methods of arity > 1, a conflict is considered to have taken place if there are two non-overwritten definitions of the same method attached to two different superclasses. When deciding whether a conflict has taken place we disregard the arguments of the method. For instance, in
a:c. c[m(k)*->f]. a:d. d[m(u)*->f].
a multiple inheritance conflict has taken place even though in one case the method m is applied to object k, while in the other it is applied to object u.
(I'm pretty sure they mean arity >= 1 but the results are similar for arity 2 as well)
So I take that to mean that the inheritance of f has a conflict so its undefined (although I'm a bit confused about what 'undefined' means, in a related section it says "inheritance does not take place"). Here's what I get when I run the diamond:
?X = o
?Y = f
?Z = g
?X = o
?Y = f(a)
?Z = a
I expected only the first solution, although I'd think that the second solution would at least make some sense if it also had the solution
?X = o
?Y = f(b)
?Z = b
... but it didn't.
FYI, I'm using the latest stable XSB and the latest Flora-2 release... 0.95.
Stumbled upon this 2+ years after the question was asked. You should have asked it on the flora-users mailing list.
Anyway, this seems to have been a bug in that version of Flora-2. I see that the current version gives a correct answer
?X = o
?Y = f
?Z = g
That is, the two conflicting inheritances canceled each other out, as the manual describes.
I'm not familiar with Flora-2 syntax but I have a smilar example of the well-known diamond-inheritance problem in Logtalk. You can find it here:
https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/diamonds
See the NOTES.txt and source file comments for information on semantics, default inheritance rules, and user-overriding of default inheritance rules. You can run the example using the latest CVS version of XSB. See the SCRIPT.txt file for sample queries.

Resources