[cxml-devel] Real-world example: with attachment

Steven Nunez steve_nunez at yahoo.com
Mon Jun 11 08:04:38 UTC 2012


Hi Ray,

Thanks. It does seems easier with xpath. Perhaps it's my stubbornness that keeps me hammering away at cxml-stp. If no one comes up with a good example for STP, I think I'll take the path of least resistance and do as you suggest.

Cheers,
- Steve


________________________________
 From: Raymond Wiker <rwiker at gmail.com>
To: Steven Nunez <steve_nunez at yahoo.com> 
Cc: "cxml-devel at common-lisp.net" <cxml-devel at common-lisp.net> 
Sent: Monday, June 11, 2012 5:14 PM
Subject: Re: [cxml-devel] Real-world example: with attachment
 

On Jun 11, 2012, at 05:50 , Steven Nunez wrote:
(defun algorithm-name (model)
>  "Returns the algorithm for the model"
>  (stp:filter-recursively (stp:of-name "algorithmName" (stp:namespace-uri model)) model))
>

I'd do something like the following:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun algorithm-name (model)
  (xpath:with-namespaces ((nil "http://www.dmg.org/PMML-4_0"))
    (xpath:string-value (xpath:evaluate "//RegressionModel/@algorithmName" model))))

(defun model-coefficient-list (model)
  (xpath:with-namespaces ((nil "http://www.dmg.org/PMML-4_0"))
    (let ((regression-model-node (xpath:first-node (xpath:evaluate "//RegressionModel" model)))
          (*read-eval* nil))
      `(,(xpath:string-value (xpath:evaluate "@modelName" regression-model-node))
        ,@(xpath:map-node-set->list
           (lambda (node)
             (list
              (xpath:string-value (xpath:evaluate "@name" node))
              ;; note: xpath:number-value may work here, depending on
              ;; your implementation... does not work with Lispworks
              ;; 6.1 under Mac OS X
              (read-from-string (xpath:string-value (xpath:evaluate "@coefficient" node)))))
           (xpath:evaluate "RegressionTable/NumericPredictor" regression-model-node))))))

#||
(defparameter *model*
  (cxml:parse #p"/Users/raw/Desktop/polynomial-regression.xml" (cxml-stp:make-builder)))

(cxml-stp:serialize *model* (cxml:make-string-sink :indentation 4))

(algorithm-name *model*)

(model-coefficient-list *model*)
||#
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Notes:

1) I'm not sure that model-coefficient-list does what you need.

2) It might be appropriate to use cxml-stp:attribute-value instead of xpath:string-value/xpath:evaluate.

3) Since there are multiple coefficients with the same name (where some have an "exponent" attribute), I guess you'd either need to filter out some of the coefficients, build names that somehow incorporate the exponent, or add the exponent to the list structure returned.

Hope this helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cxml-devel/attachments/20120611/93cdadd5/attachment.html>


More information about the cxml-devel mailing list