Problem with CSVExampleSource

VD
VD New Altair Community Member
edited November 5 in Community Q&A
Hi,

I have no problem when loading the data of the following table with Excel:

1 XXXX XX\\XX XXXX XXXX
2 XXXX XXXX XXXX XXXX
3 XXXX XXXX\ XXXX XXXX
4 XXXX XXXX\ XXXX XXXX
5 XXXX XX\\XX XXXX XXXX
6 XXXX XX\\XX XXXX XXXX
However, after saving this table with CSVExampleSetWriter and loading the file with CSVExampleSource RM complains the line 3 (and 4): "Number of columns in line 3 was unexpected, was: 5, expected: 4". I guess it's due to the character combination ...\" in the csv-file.

Due to the very huge size of my original database file I cannot open it and replace the string \" with another combination. How can I handle this problem??

I'm using RM 4.6 on WindowsXP machine.

<operator name="Root" class="Process" expanded="yes">
    <operator name="ExcelExampleSource" class="ExcelExampleSource" breakpoints="after">
        <parameter key="excel_file" value="test.xls"/>
        <parameter key="first_row_as_names" value="true"/>
    </operator>
    <operator name="CSVExampleSetWriter" class="CSVExampleSetWriter">
        <parameter key="csv_file" value="test.csv"/>
    </operator>
    <operator name="CSVExampleSource" class="CSVExampleSource">
        <parameter key="filename" value="test.csv"/>
    </operator>
</operator>


Thanks for your help and Best Regards

VD
Tagged:

Answers

  • haddock
    haddock New Altair Community Member
    G'Day,

    You're right, the single backslash "escapes" the following character, which in the problem lines is a space, ....which is also meant to be a separator. All quite annoyingly logical. It's not a problem to flip '\' to '/', like this...
    <operator name="Root" class="Process" expanded="yes">
        <operator name="backslash_in" class="CSVExampleSource">
            <parameter key="filename" value="C:\Users\CJFP\Documents\rm_workspace\slash.txt"/>
            <parameter key="read_attribute_names" value="false"/>
            <parameter key="column_separators" value=",\s*|;\s*;\s+"/>
            <parameter key="trim_lines" value="true"/>
        </operator>
        <operator name="back_2_forwards_slash" class="Replace">
            <parameter key="attributes" value=".*"/>
            <parameter key="replace_what" value="\\"/>
            <parameter key="replace_by" value="/"/>
        </operator>
        <operator name="forward_slash_out" class="CSVExampleSetWriter">
            <parameter key="csv_file" value="C:\Users\CJFP\Documents\rm_workspace\forward_slash.csv"/>
            <parameter key="write_attribute_names" value="false"/>
            <parameter key="quote_nominal_values" value="false"/>
        </operator>
        <operator name="Forward_slash_in" class="CSVExampleSource">
            <parameter key="filename" value="C:\Users\CJFP\Documents\rm_workspace\forward_slash.csv"/>
            <parameter key="read_attribute_names" value="false"/>
            <parameter key="column_separators" value=",\s*|;\s*;|\s+"/>
            <parameter key="trim_lines" value="true"/>
        </operator>
    </operator>
    /code]

    ( I just pasted the examples into slash.txt )



  • VD
    VD New Altair Community Member
    Hello Haddock,

    Wow - Thanks!!

    Best Regards

    VD