List of usage examples for org.apache.lucene.benchmark.quality QualityQuery QualityQuery
public QualityQuery(String queryID, Map<String, String> nameValPairs)
From source file:de.mpii.microblogtrack.userprofiles.TrecTopicsReader.java
License:Apache License
/** * Read quality queries from trec format topics file. * * @param reader where queries are read from. * @return the result quality queries./*from w ww . ja v a2 s. c om*/ * @throws IOException if cannot read the queries. */ public QualityQuery[] readQueries(BufferedReader reader) throws IOException { ArrayList<QualityQuery> res = new ArrayList<>(); StringBuilder sb; try { while (null != (sb = read(reader, "<top>", null, false, false))) { HashMap<String, String> fields = new HashMap<>(); // id sb = read(reader, "<num>", null, true, false); int k = sb.indexOf(":"); String id = sb.substring(k + 1).trim(); // title read(reader, "<title>", null, true, false); sb.setLength(0); String line = reader.readLine(); // while ((line = reader.readLine()) != null) { // if (line.startsWith("<desc>")) { // break; // } // if (sb.length() > 0) { // sb.append(' '); // } // sb.append(line); // } String title = line.trim(); // description read(reader, "<desc>", null, false, false); sb.setLength(0); line = null; while ((line = reader.readLine()) != null) { if (line.startsWith("<narr>")) { break; } if (sb.length() > 0) { sb.append(' '); } sb.append(line); } String description = sb.toString().trim(); // narrative sb.setLength(0); while ((line = reader.readLine()) != null) { if (line.startsWith("</top>")) { break; } if (sb.length() > 0) { sb.append(' '); } sb.append(line); } String narrative = sb.toString().trim(); // we got a topic! fields.put("title", title); fields.put("description", description); fields.put("narrative", narrative); QualityQuery topic = new QualityQuery(id, fields); res.add(topic); } } finally { reader.close(); } // sort result array (by ID) QualityQuery qq[] = res.toArray(new QualityQuery[0]); Arrays.sort(qq); return qq; }
From source file:it.unipd.dei.ims.lucene.clef.applications.BatchRetrieval.java
License:Apache License
public static QualityQuery[] getQualityQueries(String topicPath, String[] topicFields) throws Exception { File fXmlFile = new File(topicPath); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = null; try {/*from ww w . j a v a2 s. c o m*/ dBuilder = dbFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new Exception("ParserConfigurationException when parsing topic file " + topicPath); } org.w3c.dom.Document doc = null; try { doc = dBuilder.parse(fXmlFile); } catch (SAXException e) { e.printStackTrace(); throw new Exception("SAXException when parsing topic file " + topicPath); } catch (IOException e) { e.printStackTrace(); throw new Exception("IOException when parsing topic file " + topicPath); } doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("topic"); QualityQuery[] qqs = new QualityQuery[nList.getLength()]; for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String queryId = eElement.getElementsByTagName("identifier").item(0).getTextContent(); Map<String, String> queryFields = new HashMap<String, String>(); for (String topicField : topicFields) { queryFields.put(topicField, eElement.getElementsByTagName(topicField).item(0).getTextContent()); } qqs[i] = new QualityQuery(queryId, queryFields); } } return qqs; }