2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.lucene.benchmark.quality.trec;
19 import java.io.BufferedReader;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.HashMap;
25 import org.apache.lucene.benchmark.quality.QualityQuery;
28 * Read topics of TREC 1MQ track.
30 * Expects this topic format -
34 * Comment lines starting with '#' are ignored.
36 * All topics will have a single name value pair.
38 public class Trec1MQReader {
43 * Constructor for Trec's 1MQ TopicsReader
44 * @param name name of name-value pair to set for all queries.
46 public Trec1MQReader(String name) {
52 * Read quality queries from trec 1MQ format topics file.
53 * @param reader where queries are read from.
54 * @return the result quality queries.
55 * @throws IOException if cannot read the queries.
57 public QualityQuery[] readQueries(BufferedReader reader) throws IOException {
58 ArrayList<QualityQuery> res = new ArrayList<QualityQuery>();
61 while (null!=(line=reader.readLine())) {
63 if (line.startsWith("#")) {
67 int k = line.indexOf(":");
68 String id = line.substring(0,k).trim();
70 String qtext = line.substring(k+1).trim();
72 HashMap<String,String> fields = new HashMap<String,String>();
73 fields.put(name,qtext);
74 //System.out.println("id: "+id+" qtext: "+qtext+" line: "+line);
75 QualityQuery topic = new QualityQuery(id,fields);
81 // sort result array (by ID)
82 QualityQuery qq[] = res.toArray(new QualityQuery[0]);