368.5. Samples
368.5.1. Read + Filter + Write
第一个示例演示了如何使用文件组件读取 CSV 文件,然后将其传递到 Weka。在 Weka 中,我们对数据集应用几个过滤器,然后将其传递到文件组件以进行写入。
@Override public void configure() throws Exception { // Use the file component to read the CSV file from("file:src/test/resources/data?fileName=sfny.csv") // Convert the 'in_sf' attribute to nominal .to("weka:filter?apply=NumericToNominal -R first") // Move the 'in_sf' attribute to the end .to("weka:filter?apply=Reorder -R 2-last,1") // Rename the relation .to("weka:filter?apply=RenameRelation -modify sfny") // Use the file component to write the Arff file .to("file:target/data?fileName=sfny.arff") }
此处我们执行与上述操作相同的操作,无需使用文件组件。
@Override public void configure() throws Exception { // Initiate the route from somewhere .from("...") // Use Weka to read the CSV file .to("weka:read?path=src/test/resources/data/sfny.csv") // Convert the 'in_sf' attribute to nominal .to("weka:filter?apply=NumericToNominal -R first") // Move the 'in_sf' attribute to the end .to("weka:filter?apply=Reorder -R 2-last,1") // Rename the relation .to("weka:filter?apply=RenameRelation -modify sfny") // Use Weka to write the Arff file .to("weka:write?path=target/data/sfny.arff"); }
在本例中,客户端将提供输入路径或其它受支持的类型。查看 WekaTypeConverters
用于支持的输入类型集合。
@Override public void configure() throws Exception { // Initiate the route from somewhere .from("...") // Convert the 'in_sf' attribute to nominal .to("weka:filter?apply=NumericToNominal -R first") // Move the 'in_sf' attribute to the end .to("weka:filter?apply=Reorder -R 2-last,1") // Rename the relation .to("weka:filter?apply=RenameRelation -modify sfny") // Use Weka to write the Arff file .to("weka:write?path=target/data/sfny.arff"); }