adds dataset-replace-attribute!

This commit is contained in:
Ben Mabey 2010-11-08 10:37:02 -07:00
parent 285e45717a
commit ccc12c2d5c
2 changed files with 15 additions and 0 deletions

View file

@ -342,3 +342,13 @@
"Removes and returns the first instance in the dataset"
[dataset]
(dataset-extract-at dataset 0))
(defn dataset-replace-attribute!
"Replaces the specified attribute with the given one. (The attribute should be a weka.core.Attribute)
This function only modifies the format of the dataset and does not deal with any instances.
The intention is for this to be used on data-formats and not on datasets with data."
[dataset attr-name new-attr]
(let [attr-pos (index-attr dataset attr-name)]
(doto dataset
(.deleteAttributeAt attr-pos)
(.insertAttributeAt new-attr attr-pos))))

View file

@ -128,3 +128,8 @@
(is (= [(.attribute ds 2)] (nominal-attributes ds)))
(is (= [(.attribute ds 0) (.attribute ds 1)] (numeric-attributes ds)))
(is (= '(:a :b :c) (attribute-names ds)))))
(deftest replacing-attributes
(let [ds (make-dataset "test" [:a {:b [:foo :bar]}] [[1 :foo] [2 :bar]])
_ (dataset-replace-attribute! ds :b (nominal-attribute :b [:baz :shaz]))]
(is (= [:a {:b [:shaz :baz]}] (dataset-format ds)))))