is_relevant <- function(qrels,docid) { docid=toString(docid) fila = subset(qrels, DOC_ID==docid) if (nrow(fila)==0) {return(0)} else { return(fila$REL) } } # judgement_list_path: RData file (created by process_multiple_queries) # qrels_path: path to the qrel file # proportion: parameter of the method (stop after n consecutive non-rels) # writes the subqrels in subqrel_file_path stopping_stop_after_n_consecutive_non_rels <- function( judgement_list_path, qrels_path, n, subqrel_file_path ) { # reads the judgment_list ... gets judgments_lists variable ... load(judgement_list_path) print(paste("Judgement list file...",judgement_list_path,"...",length(judgments_lists)," judgment list loaded.")) # reads the qrel file into an R dataframe with appropriate column names qrels_df= read.table(qrels_path,header=FALSE) names(qrels_df)=c("QUERY","DUMMY","DOC_ID","REL") print(paste("Qrel file...",qrels_path,"...",nrow(qrels_df)," judgments.")) queries= unique(qrels_df$QUERY) iq=1 qrel_lines="" for (q in queries) { #get the judgment list from judgments_lists judgments1 = judgments_lists[[iq]] # get the relevance assessments for the current query current_qrels = subset(qrels_df, QUERY==q) consecutive_non_rels=0 count=1 while(1) { if (is_relevant(current_qrels,judgments1[count])==0) { consecutive_non_rels=consecutive_non_rels+1 qrel_line= paste(q,"0",judgments1[count],"0") } else { consecutive_non_rels=0 qrel_line= paste(q,"0",judgments1[count],"1") } if (qrel_lines=="") qrel_lines=qrel_line else qrel_lines=paste(qrel_lines,qrel_line,sep="\n") if (count==length(judgments1) || consecutive_non_rels==n) break count=count+1 } iq=iq+1 } # for q in queries write(qrel_lines,subqrel_file_path) }