用户登录
用户注册

分享至

R语言读入数据库的中英名词互译测试并计分脚本(考试用)

  • 作者: 寄予你肆意心动
  • 来源: 51数据库
  • 2020-08-06

    1. 分子生物学中英文.csv,输入文件,两列,以tab键分隔的txt文本,没有列名

    2. 错误的名解.csv, 如果在测试中拼写错误,会写出到这个文件,可用这个容易犯错的名词进行新的测试

    3. 注意加载data.table包,因为R语言readline函数,使用脚本不能很好交互,暂时只能在R交互模式下(终端输入R)运行

    4. 这里使用write写出文件或者标准输出,readline读入键盘输入,value进行得分统计

 

library(data.table)


dt <- fread("分子生物学中英文.csv", sep = "\t", header =F) 
fileConn<-file("错误的名解.csv")  

value = 0
for(i in 1:nrow(dt)){
    write(paste0(i," question"), stdout())
    write(dt[i,V1], stdout())
    input <-  readline()
    if(length(input) == 0){
        print("Input can not be nothing")
        next()
    }
    if(input != dt[i,V2]){
        write(dt[i,V2], stdout())
        writeLines(paste(dt[i,V1], dt[i,V2], sep = "\t"), fileConn)
        input <- readline()
        write("Next!", stdout())
    }else{
        value = value + 1
    }
}
print(paste0("Score ",value))
close(fileConn)

 

原文链接:http://www.cnblogs.com/ywliao/p/10498212.html

软件
前端设计
程序设计
Java相关