文本结构化再计算,前两行结构不同,是所有记录都共有的一些字段值

【问题】

Using for loop to read in data from text file using Scanner class

I'm currently stuck on a programming assignment which requires me to read in data from a text file then process it. The file looks like this:
CS1 2012 Group 1
8
5,5,5,6,5,8,9,5,6,8, good, very good, excellent, good
7,7,8,7,6,7,8,8,9,7,very good, Good, excellent, very good
8,7,6,7,8,7,5,6,8,7 ,GOOD, VERY GOOD, GOOD, AVERAGE
9,9,9,8,9,7,9,8,9,9 ,Excellent, very good, very good, excellent
7,8,8,7,8,7,8,9,6,8 ,very good, good, excellent, excellent
6,5,6,4,5,6,5,6,6,6 ,good, average, good, good
7,8,7,7,6,8,7,8,6,6 ,good, very good, good, very good
5,7,6,7,6,7,6,7,7,7 ,excellent, very good, very good, very good
The first 2 lines are read in then assigned to fields, the remaining lines are the ones I have to process. I've been told to use .useDelimiter("[]*(,)[]*") but so far haven't really been able to put it to good use. 
Once the data has been read in I have to convert the Strings into integers using a switch statement and work out an average feedback score e.g excellent = 5 very good = 4 good =3. Maybe i'm just not thinking clear but I've already spent about 5 hours trying to figure this out to no avail so any guidance would be appreciated. Thanks!

别人的回答:

write the code in simple steps.
First make a loop and in the loop read a line and print it
continue until all the lines have been read and printed.
When that works, then worry about how to parse the contents of a line and use the data it contains.

【回答】

       这是结构化数据中的简单计算,JAVA处理这类问题确实比较麻烦,但用SPL就方便多了。SPL可以为JAVA提供结构化计算能力,还很容易集成(可参考Java 如何调用 SPL 脚本。针对你的问题(猜测例子中部分数据大小写有问题,稍作调整之后),SPL代码如下:

 


A

1

=file("E:\\s.txt").read@n()

2

=A1.to(3,)

3

=A2.concat("\n")

4

=A3.import@c()

5

>A4.run(_11=case(_11,"average":2,"good":3,"very   good":4,"excellent":5),_12=case(_12,"average":2,"good":3,"very   good":4,"excellent":5),_13=case(_13,"average":2,"good":3,"very   good":4,"excellent":5),_14=case(_14,"average":2,"good":3,"very   good":4,"excellent":5))

6

=A4.fno().(A4.field(~).avg())

7

=A4.record(A6)

 

A1:读取s.txt中的内容, 返回成串序列,每行作为一个成员

undefined

A2:读取A1中第3行到最后一行的内容。

undefined

A3:将序列成员以分隔符“\n”分隔拼成一个字符串。

A4: 用字符串中读出的内容作为记录并返回成序表

undefined

A5:修改最后4列的数据,使excellent = 5very good = 4good =3average=2

undefined

A6:对每列进行平均计算,返回成序列。

undefined

A7:A6填入A4

undefined