369.5. 샘플

369.5.1. 읽기 + 필터 + 쓰기

이 첫 번째 예제에서는 파일 구성 요소로 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");
    }