按条件对 csv 文件进行检索

例题描述和简单分析

有 csv 文件 books.csv,如下:

"book_id","books_count","authors","original_publication_year","title","work_text_reviews_count","ratings_1","ratings_2","ratings_3","ratings_4","ratings_5","ratings_count","work_ratings_count","average_rating"

1,321,"author1",2013,"title1",81786,171184,194374,347116,148563,179728,1040965,1095481,2.82

2,399,"author2",2018,"title2",90118,184637,195711,325457,120472,153599,979876,988025,2.84

3,269,"author3",2007,"title3",81776,155035,145240,308206,142679,168599,919759,977895,2.85

4,229,"author4",2016,"title4",116917,184987,159633,389774,119616,142820,996830,1038375,2.76

5,356,"author5",2001,"title5",117952,167016,102358,345956,148374,131290,894994,924198,2.88

...

要求:

1、列出所有满足 5 星好评(ratings_5)超过 15 万次的书的标题(title)

2、列出所有满足评论数(reviews)至少 10 万次,3 星好评至少占 40% 的书的标题(title)

结果如下:

题目 1:

title1

title2

title3

title7

title8

题目 2:

title28

title33

title34

title39

title41

解法及简要说明

在集算器中编写脚本 p1.dfx,如下所示:


A

1

=file("books.csv").import@qct()

2

=A1.select(ratings_5>150000).(title)

3

=A1.select(reviews>100000 &&   ratings_3/ratings_count>0.4).(title)

简要说明:

A1  读取带表头的 csv 文件

A2  找出所有 ratings_5 数量超过 15 万的 title

A3  找出所有 reviews 大于 10 万且 3 星好评至少占 40% 的 title

JAVA 集成这段代码的方法可参考:《Java 如何调用 SPL 脚本》

问答搜集

https://stackoverflow.com/questions/61187096/simplest-way-to-read-csv-file-of-10000-lines-in-java-and-list-items-based-on-cer