private void loadRelevanceInformation(String filename) { logger.info("Loading relevance feedback assessments from " + filename); try { queryidRelDocumentMap = new THashMap<String, List<FeedbackWithDocno>>(); BufferedReader br = Files.openFileReader(filename); // THashSet<String> queryids = new THashSet<String>(); String line = null; int assessmentsCount = 0; while ((line = br.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; String[] parts = line.split("\\s+"); FeedbackWithDocno doc = new FeedbackWithDocno(); doc.docno = parts[2]; doc.relevance = Byte.parseByte(parts[3]); List<FeedbackWithDocno> list = queryidRelDocumentMap.get(parts[0]); if (list == null) { queryidRelDocumentMap.put(parts[0], list = new ArrayList<FeedbackWithDocno>()); } list.add(doc); assessmentsCount++; } br.close(); logger.info("Total " + assessmentsCount + " assessments found"); } catch (IOException ioe) { logger.error("Problem loading relevance feedback assessments from " + filename, ioe); } }
/** {@inheritDoc} */ public FeedbackDocument[] getFeedbackDocuments(Request request) { // get docids of the feedback documents String queryid = request.getQueryID(); List<FeedbackWithDocno> list = queryidRelDocumentMap.get(queryid); // deal with undefined case if (list == null) return new FeedbackDocument[0]; // dela with empty case if (list.size() == 0) return new FeedbackDocument[0]; final List<FeedbackDocument> rtrList = new ArrayList<FeedbackDocument>(list.size()); for (FeedbackWithDocno doc : list) { try { doc.docid = metaIndex.getDocument("docno", doc.docno); } catch (IOException ioe) { logger.warn( "IOException while looking for docid for feedback document " + doc.docno + " of query " + request.getQueryID(), ioe); } if (doc.docid < 0) { logger.warn( "Could not find docid for feedback document " + doc.docno + " of query " + request.getQueryID()); continue; } doc.score = -1; doc.rank = -1; logger.info("(" + (rtrList.size() + 1) + ") Feedback document:" + doc.docno); rtrList.add(doc); } logger.info( "Found " + (rtrList.size()) + " feedback documents for query " + request.getQueryID()); return rtrList.toArray(new FeedbackDocument[0]); }