Re: JESS: multislot pattern matching using "accumulate"
"Wolfgang Laun" <[email protected]>
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <26396_1290460213_oAML65KX027061_AANLkTikLG_=JpZw=SYE8Ofwz36t9iE_57tBdxX=-kivx@mail.gmail.com> |
(clear)
(deftemplate dataset
(slot name)
(multislot variables)
(slot has-errors)
(multislot errors)
)
(deffacts vt
(dataset
(name "test1")
(variables "good" "6ad" "ug/y")
(has-errors nil)))
(defglobal ?*varok* =
(lambda (?var)
(return (regexp "[\\p{Alpha}_}][\\p{Alnum}_.}]*" ?var))))
(deffunction filter-out (?lambda $?args)
(bind ?res (list))
(foreach ?arg $?args
(if (not (call ?lambda ?arg)) then
(bind ?res (list ?res ?arg))))
(return ?res))
(defrule dataset-variables
?dataset <- (dataset (variables $?variables) (has-errors nil))
=>
(bind ?errors (filter-out ?*varok* $?variables))
(modify ?dataset
(errors ?errors)
(has-errors (> (length$ ?errors) 0) ))
)
(reset)
(run)
(facts)
-W
On 22 November 2010 16:12, Wolfgang Laun <[email protected]> wrote:
> What about storing the list in another slot of variables?
>
> Also, the accumulate could be replaced by a Lisp function (filter)
> called in the consequence, the likes of which you might have seed in
> your lisping days. If you feel reckless, the actual filter can be
> passed in as a lambda.
>
> -W
>
>
> On 21 November 2010 20:07, Donald Winston <[email protected]> wrote:
> >
> > (defrule VALIDATE:dataset-variables
> > (page "edit-dataset.xslt")
> > ?dataset <- (dataset (variables $?) (has-errors FALSE))
> > ?errors <- (accumulate (bind ?list (new java.util.ArrayList))
> > (?list add ?var)
> > ?list
> > (dataset (variables $? ?var&:
> > (not (regexp "^[a-zA-Z_][a-zA-Z0-9_\\.]*$" ?var)) $?)))
> > =>
> > (printout t "errors = " (?errors toString) crlf)
> > (modify ?dataset
> > ; TODO: set variablesErrors for each variable in ?errors"
> > (has-errors TRUE)))
> > It looks like this works and is very cool but if I have more then one
> > dataset how do I get the ?dataset and ?errors to correlate?
> > test-facts.clp
> > ...
> > (page "edit-dataset.xslt")
> > (dataset
> > (name "testdata")
> > (nobs "120")
> > (nvars "10")
> > (variables "X1" "X-2" "X3")
> > (submitEditDatasetForm "Submit"))
> > ...
> > This copy of Jess will expire in 106 day(s).
> > executing...
> > errors = [X-2]
> > f-0 (MAIN::initial-fact)
> > f-1 (MAIN::nextPage "edit-dataset.xslt")
> > f-2 (MAIN::R nil)
> > f-3 (MAIN::subscription-prices (maxDataElements 500) (monthlyPrice 25)
> > (yearlyPrice 100))
> > f-4 (MAIN::upload-info (uploadDirectory "/tmp/Rserv") (filename
> > "test.csv") (contentType "text/plain") (contentTypeError "") (length 53)
> > (format "fwf") (separationChar ",") (columnWidths "2 8 10 5 15")
> > (hasColumnNames "TRUE") (submitUploadForm nil) (submitDatasetForm nil)
> > (submitShowDatasetForm nil) (has-errors FALSE))
> > f-5 (MAIN::page "edit-dataset.xslt")
> > f-6 (MAIN::dataset (name "testdata") (nameError "") (nobs "120") (nvars
> > "10") (variables "X1" "X-2" "X3") (variableErrors ) (variableTypes )
> > (submitEditDatasetForm "Submit") (has-errors TRUE) (isFree TRUE))
> > f-7 (MAIN::purchase-info (creditCardNumber "1408 0412 3456 7893")
> > (creditCardNumberError "") (creditCardType "") (securityCode "143")
> > (securityCodeError "") (expirationDate "05-2010") (expirationDateError
> "")
> > (nameOnCard "Donald P Winston") (nameOnCardError "") (subscription nil)
> > (subscriptionError "") (submitPurchaseSubscriptionForm nil) (has-errors
> > FALSE))
> > For a total of 8 facts in all modules.
> > Donald Paul Winston
> > [email protected]
> >
> >
> >
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
> in the BODY of a message to [email protected], NOT to the list
> (use your own address!) List problems? Notify [email protected].
> --------------------------------------------------------------------
>
>