From bc3efe3fc7b7685edc0f5aae33e8c8412ff52798 Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Tue, 9 Oct 2012 03:26:03 +0200 Subject: [PATCH] factoring out the make-dataframe2 methods into relevant files. We don-t know about the methods until we specify the storage structure. Signed-off-by: AJ Rossini --- src/data/dataframe-array.lisp | 27 ++++++++++++++++++++++++++- src/data/dataframe-listoflist.lisp | 12 +++++++++++- src/data/dataframe-matrixlike.lisp | 9 ++++++++- src/data/dataframe.lisp | 38 ++------------------------------------ 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/data/dataframe-array.lisp b/src/data/dataframe-array.lisp index 27e9a78..f3ce63f 100644 --- a/src/data/dataframe-array.lisp +++ b/src/data/dataframe-array.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2010-01-22 07:54:51 tony> +;;; Time-stamp: <2012-10-09 03:17:34 tony> ;;; Creation: <2009-03-12 17:14:56 tony> ;;; File: dataframe-array.lisp ;;; Author: AJ Rossini @@ -32,6 +32,30 @@ based on lisp arrays. An obvious alternative could be a dataframe-matrix-like which uses the lisp-matrix classes.")) +(defmethod make-dataframe2 ((data dataframe-array) + &key vartypes varlabels caselabels doc) + (check-dataframe-params data vartypes varlabels caselabels doc) + (let ((newcaselabels (if caselabels + caselabels + (make-labels "C" (ncases data)))) + (newvarlabels (if varlabels + varlabels + (make-labels "V" (nvars data)))) + ;; also should determine most restrictive possible (compsci + ;; and/or statistical) variable typing (integer, double, + ;; string, symbol, *). FIXME: until we get the mixed typing system in place, we will just leave null + (newvartypes (if vartypes + vartypes + (make-labels "*" (nvars data))))) + (make-instance 'dataframe-array + :storage data + :nrows (length newcaselabels) + :ncols (length newvarlabels) + :case-labels newcaselabels + :var-labels newvarlabels + :var-types newvartypes))) + + (defmethod nrows ((df dataframe-array)) "specializes on inheritance from matrix-like in lisp-matrix." (array-dimension (dataset df) 0)) @@ -77,3 +101,4 @@ idx1/2 is row/col or case/var." (xref df (position (elt cases i) (case-labels df)) (position (elt vars j) (var-labels df)))))))) + diff --git a/src/data/dataframe-listoflist.lisp b/src/data/dataframe-listoflist.lisp index ce23e2a..b2e5ae7 100644 --- a/src/data/dataframe-listoflist.lisp +++ b/src/data/dataframe-listoflist.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2012-10-06 08:56:53 tony> +;;; Time-stamp: <2012-10-09 03:18:49 tony> ;;; Creation: <2009-03-12 17:14:56 tony> ;;; File: dataframe-listoflist.lisp ;;; Author: AJ Rossini @@ -32,10 +32,20 @@ (:documentation "example implementation of dataframe-like objects using list-of-list data storage.")) + +(defmethod make-dataframe2 ((data dataframe-listoflist) + &key vartypes varlabels caselabels doc + ;; (vartypes sequence) (varlabels sequence) (caselabels sequence) (doc string) + ) + (check-dataframe-params data vartypes varlabels caselabels doc) + (build-dataframe 'dataframe-listoflist)) + + (defmethod nrows ((df dataframe-listoflist)) "specializes on inheritance from listoflist in lisp-matrix." (length (dataset df))) + (defmethod ncols ((df dataframe-listoflist)) "specializes on inheritance from listoflist. This approach assumes that the list of list is in a coherent form, that is that it maps diff --git a/src/data/dataframe-matrixlike.lisp b/src/data/dataframe-matrixlike.lisp index 6839f76..d4fd36b 100644 --- a/src/data/dataframe-matrixlike.lisp +++ b/src/data/dataframe-matrixlike.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2009-09-25 08:02:52 tony> +;;; Time-stamp: <2012-10-09 03:21:09 tony> ;;; Creation: <2009-03-12 17:14:56 tony> ;;; File: dataframe-matrixlike.lisp ;;; Author: AJ Rossini @@ -35,6 +35,13 @@ (:documentation "example implementation of dataframe-like using storage based on lisp-matrix structures.")) +(defmethod make-dataframe2 ((data dataframe-matrixlike) + &key vartypes varlabels caselabels doc) + "" + (check-dataframe-params data vartypes varlabels caselabels doc) + (build-dataframe 'dataframe-matrixlike)) + + (defmethod nrows ((df dataframe-matrixlike)) "specializes on inheritance from matrix-like in lisp-matrix." (matrix-dimension (dataset df) 0)) diff --git a/src/data/dataframe.lisp b/src/data/dataframe.lisp index 98477fb..b90be94 100644 --- a/src/data/dataframe.lisp +++ b/src/data/dataframe.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2012-10-08 17:46:02 tony> +;;; Time-stamp: <2012-10-09 03:21:23 tony> ;;; Creation: <2008-03-12 17:18:42 blindglobe@gmail.com> ;;; File: dataframe.lisp ;;; Author: AJ Rossini @@ -292,41 +292,7 @@ that that list is a valid listoflist dataframe structure." ;; (macroexpand '(build-dataframe 'test))) (defgeneric make-dataframe2 (data &key vartypes varlabels caselabels doc) - (:documentation "trial generic dispatch. Data should be in table format desired for use.") - (:method ((data dataframe-array) - &key vartypes varlabels caselabels doc) - (check-dataframe-params data vartypes varlabels caselabels doc) - (let ((newcaselabels (if caselabels - caselabels - (make-labels "C" (ncases data)))) - (newvarlabels (if varlabels - varlabels - (make-labels "V" (nvars data)))) - ;; also should determine most restrictive possible (compsci - ;; and/or statistical) variable typing (integer, double, - ;; string, symbol, *). FIXME: until we get the mixed typing system in place, we will just leave null - (newvartypes (if vartypes - vartypes - (make-labels "*" (nvars data))))) - (make-instance 'dataframe-array - :storage data - :nrows (length newcaselabels) - :ncols (length newvarlabels) - :case-labels newcaselabels - :var-labels newvarlabels - :var-types newvartypes))) - (:method ((data dataframe-matrixlike) - &key vartypes varlabels caselabels doc - ;; (vartypes sequence) (varlabels sequence) (caselabels sequence) (doc string) - ) - (check-dataframe-params data vartypes varlabels caselabels doc) - (build-dataframe 'dataframe-matrixlike)) - (:method ((data dataframe-listoflist) - &key vartypes varlabels caselabels doc - ;; (vartypes sequence) (varlabels sequence) (caselabels sequence) (doc string) - ) - (check-dataframe-params data vartypes varlabels caselabels doc) - (build-dataframe 'dataframe-listoflist))) + (:documentation "testing generic dispatch. Data should be in table format desired for use.")) (defun make-dataframe (newdata &key (vartypes nil) -- 2.11.4.GIT