Parse a csv file having two structures
The csv file below has two structures. The first two lines has one structure and the lines beginning from the 3rd line to the last has the other. Each structure is standardized.
CENTER_LABEL,LAYOUT,TYPE,WEIGHTED_TYPE,DIFFICUTLY,HINT,INITIAL,MASK,LEFT_LABEL,LEFT_VALUE_LIMIT
,,,AUTOMATIC,,,0,,,1
COLUMN_VALUE,CORRECT,CORRECT_ID,FEEDBACK,INITIAL,OTHER,PERCENT,ROW_VALUE,SEQUENCE
<p>c2</p>,false,,,false,false,50,<p>r1</p>,1
<p>c1</p>,false,,,false,false,0,<p>r2</p>,0
<p>c1</p>,false,,,false,false,0,<p>r1</p>,0
<p>c2</p>,false,,,false,false,50,<p>r2</p>,1
Task: Use Java to parse the csv file into two standard two-dimensional tables. One is:
CENTER_LABEL |
LAYOUT |
TYPE |
WEIGHTED_TYPE |
DIFFICUTLY |
HINT |
INITIAL |
MASK |
LEFT_LABEL |
LEFT_VALUE_LIMIT |
|
1 |
AUTOMATIC |
0 |
1 |
And the other is:
COLUMN_VALUE |
CORRECT |
CORRECT_ID |
FEEDBACK |
INITIAL |
OTHER |
PERCENT |
ROW_VALUE |
SEQUENCE |
|
1 |
<p>c2</p> |
FALSE |
FALSE |
FALSE |
50 |
<p>r1</p> |
1 |
||
2 |
<p>c1</p> |
FALSE |
FALSE |
FALSE |
0 |
<p>r2</p> |
0 |
||
3 |
<p>c1</p> |
FALSE |
FALSE |
FALSE |
0 |
<p>r1</p> |
0 |
Write the following SPL script:
A |
B |
|
1 |
=file("data.csv").import@si() |
|
2 |
=A1.to(,2).concat("\n") |
=A2.import@tc() |
3 |
=A1.to(3,).concat("\n") |
=A3.import@tc() |
4 |
return B2,B3 |
A1: Read the file as a sequence made up of rows to parse it.
A2: Get the first two lines and use the enter key to concatenate them into a string.
B2: Parse the string as a two-dimensional table having column headers and separated by the comma.
Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL