sets the output-format for ClojureBatchFilter to use the process fn format

This commit is contained in:
Ben Mabey 2010-11-08 10:22:26 -07:00
parent adff41dafe
commit 19a827d8b3
2 changed files with 16 additions and 7 deletions

View file

@ -318,7 +318,8 @@
approach is to copy the Instance with the copy method or Instance
constructor and return a modified version of the copy.
- :determine-dataset-format
This function will receive the dataset's weka.core.Instances object.
This function will receive the dataset's weka.core.Instances object with
no actual Instance objects (i.e. just the format enocded in the attributes).
You must return a Instances object that contains the new format of the
filtered dataset. Passing this fn is optional. If you are not changing
the format of the dataset then by omitting a function will use the
@ -335,13 +336,19 @@
- :process
This function will receive the entire dataset as a weka.core.Instances
objects. A processed Instances object should be returned with the
new Instance objects added to it.
new Instance objects added to it. The format of the dataset (Instances)
that is returned from this will be returned from the filter (see below).
- :determine-dataset-format
This function will receive the dataset's weka.core.Instances object.
This function will receive the dataset's weka.core.Instances object with
no actual Instance objects (i.e. just the format enocded in the attributes).
You must return a Instances object that contains the new format of the
filtered dataset. Passing this fn is optional. If you are not changing
the format of the dataset then by omitting a function will use the
current format.
filtered dataset. Passing this fn is optional.
For many batch filters you need to process the entire dataset to determine
the correct format (e.g. filters that operate on nominal attributes). For
this reason the clj-batch filter will *always* use format of the dataset
that the process fn outputs. In other words, if you need to operate on the
entire dataset before determining the format then this should be done in the
process-fn and nothing needs to be passed for this fn.
For examples on how to use the filters, especially the clojure filters, you may
refer to filters_test.clj of clj-ml."

View file

@ -51,7 +51,9 @@ public class ClojureBatchFilter
protected Instances process(Instances instances) throws Exception {
try {
return (Instances) processFn.invoke((Object) instances);
Instances result = (Instances) processFn.invoke((Object) instances);
this.setOutputFormat(result);
return result;
} catch (Exception e) {
// Weka silently eats any exceptions in filters so we need to report on it...
System.out.println("Unable to filter instances (dataset) with a clojure fn! The exception was:\n" +