HELP! Question about multi-dimensional data sorting in CLIPS

53 views
Skip to first unread message

Cindy Chen

unread,
Feb 19, 2014, 10:46:40 AM2/19/14
to clip...@googlegroups.com
Hi there,

Glad to find this group! I am new to CLIPS, although I have went through the basic programming guide but I am not sure about the complexity of my idea if I use CLIPS. 
Could anyone tell me which of the following plan would be easier to do in relatively short time? Thanks in advance!

The main idea: 
I want to sort a 100x2 table (from stored external files) according to the contents (numbers) in 1st column, say, from the largest to the smallest. And then I will need the corresponding contents (characters) in the 2nd column and print them out following the sorted order. 

Example:
Here are the contents in original files:
3, aa
5, bb
2, cc
8, dd
After sorting the 1st column:
8, dd
5, bb
3, aa
2, cc
And I need to print out in order:
dd
bb
aa
cc
That's all I need.

There are two plans:
1) I would use CLIPS itself to realize by using "sort" function. But the difficulty here is that I don't know how to sort a multi-dimensional data (while preserving the 2nd column) in CLIPS. It seems that CLIPS doesn't have "array" data type; so I don't know if there is any way to do that.
2) I would use C++ to read the external files and sort the result; then pass the result to CLIPS and let it print out the results one by one. The difficulty here lies in the interface between C++ and CLIPS. Could you give me any advice? An example code is highly appreciated. 

Thank you very much and I am looking forward the answers. 

-Cindy

Artem Novikov

unread,
Feb 20, 2014, 5:01:43 PM2/20/14
to clip...@googlegroups.com
(deftemplate v
    (slot f)
    (slot s))

(assert (v (f 3)(s aa)))
(assert (v (f 5)(s bb)))
(assert (v (f 8)(s dd)))

(defrule Out
    ?f1 <- (v (f ?fa)(s ?sa))
    (not (v (f ?fb&:(> ?fb ?fa))))
=>
    (retract ?f1)
    (printout t ?fa crlf))


(run)
8
5
3

среда, 19 февраля 2014 г., 17:46:40 UTC+2 пользователь Cindy Chen написал:
Reply all
Reply to author
Forward
0 new messages