Import Certain Text Data

Question

I would like to read input text file into lists.

File content:

/* ignore comments */

/*TaskID <space> Duration <space> Dependency <comma> <Dependency>...*/

 

A 1

B 2 A(-1)

C 3 B,A

D 4 D

 

How do I avoid reading comments and store each line in a proper order?

Desired result:

task = {A,B,C,D}

 

duration = {1,2,3,4}

 

dependency = {, A(-1), BA, D}

 

Answer

Remove comments and empty space, read the other data into a 2D table, and join up values of each column into a row. It’s complicated to do it in Java. You can handle it in SPL (Structured Process Language) and then embed the script into the Java application. (For Java invocation, see How to Call an SPL Script in Java):

A

1

=file("source.csv").read@n()

2

=A1.to(4,)

3

=A2.regex("(.*) (.*)  (.*)";a,b,c)

4

=A3.fno().(A3.field(~).concat@c())

A1: Read in the content of source.csv.

 undefined

A2: Get data from the 4th row.

undefined

A3: Match each of A2’s members with a regular expression to split the sequence into a 2D table.

undefined

A4: Concatenate values of each column into a row.

undefined