Exemplo n.º 1
0
        // inherit javadocs
        public virtual bool IsRelevant(string docName, QualityQuery query)
        {
            QRelJudgement qrj;// = judgements.get(query.getQueryID());

            judgements.TryGetValue(query.QueryID, out qrj);
            return(qrj != null && qrj.IsRelevant(docName));
        }
Exemplo n.º 2
0
 // inherit javadocs
 public virtual int MaxRecall(QualityQuery query)
 {
     if (judgements.TryGetValue(query.QueryID, out QRelJudgement qrj) && qrj != null)
     {
         return(qrj.MaxRecall);
     }
     return(0);
 }
Exemplo n.º 3
0
        /// <seealso cref="IQualityQueryParser.Parse(QualityQuery)"/>
        public virtual Query Parse(QualityQuery qq)
        {
            QueryParser qp = queryParser.Value;

            if (qp is null)
            {
#pragma warning disable 612, 618
                qp = new QueryParser(LuceneVersion.LUCENE_CURRENT, indexField, new StandardAnalyzer(LuceneVersion.LUCENE_CURRENT));
#pragma warning restore 612, 618
                queryParser.Value = qp;
            }
            BooleanQuery bq = new BooleanQuery();
            for (int i = 0; i < qqNames.Length; i++)
            {
                bq.Add(qp.Parse(QueryParserBase.Escape(qq.GetValue(qqNames[i]))), Occur.SHOULD);
            }

            return(bq);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read quality queries from trec 1MQ format topics file.
        /// </summary>
        /// <param name="reader">where queries are read from.</param>
        /// <returns>the result quality queries.</returns>
        /// <exception cref="IOException">if cannot read the queries.</exception>
        public virtual QualityQuery[] ReadQueries(TextReader reader)
        {
            IList <QualityQuery> res = new List <QualityQuery>();
            string line;

            try
            {
                while (null != (line = reader.ReadLine()))
                {
                    line = line.Trim();
                    if (line.StartsWith("#", StringComparison.Ordinal))
                    {
                        continue;
                    }
                    // id
                    int    k  = line.IndexOf(':');
                    string id = line.Substring(0, k - 0).Trim();
                    // qtext
                    string qtext = line.Substring(k + 1).Trim();
                    // we got a topic!
                    IDictionary <string, string> fields = new Dictionary <string, string>
                    {
                        [name] = qtext
                    };
                    //System.out.println("id: "+id+" qtext: "+qtext+"  line: "+line);
                    QualityQuery topic = new QualityQuery(id, fields);
                    res.Add(topic);
                }
            }
            finally
            {
                reader.Dispose();
            }
            // sort result array (by ID)
            QualityQuery[] qq = res.ToArray();
            Array.Sort(qq);
            return(qq);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Report a search result for a certain quality query.
        /// </summary>
        /// <param name="qq">quality query for which the results are reported.</param>
        /// <param name="td">search results for the query.</param>
        /// <param name="docNameField">stored field used for fetching the result doc name.</param>
        /// <param name="searcher">index access for fetching doc name.</param>
        /// <see cref="IOException">in case of a problem.</see>
        public virtual void Report(QualityQuery qq, TopDocs td, string docNameField, IndexSearcher searcher)
        {
            if (logger == null)
            {
                return;
            }
            ScoreDoc[]       sd  = td.ScoreDocs;
            string           sep = " \t ";
            DocNameExtractor xt  = new DocNameExtractor(docNameField);

            for (int i = 0; i < sd.Length; i++)
            {
                string docName = xt.DocName(searcher, sd[i].Doc);
                logger.WriteLine(
                    qq.QueryID + sep +
                    "Q0" + sep +
                    Format(docName, 20) + sep +
                    Format("" + i, 7) + sep +
                    //nf.format(sd[i].score) + sep +
                    string.Format(nf, sd[i].Score, CultureInfo.InvariantCulture) + sep +
                    name
                    );
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Read quality queries from trec format topics file.
        /// </summary>
        /// <param name="reader">where queries are read from.</param>
        /// <returns>the result quality queries.</returns>
        /// <exception cref="IOException">if cannot read the queries.</exception>
        public virtual QualityQuery[] ReadQueries(TextReader reader)
        {
            IList <QualityQuery> res = new List <QualityQuery>();
            StringBuilder        sb;

            try
            {
                while (null != (sb = Read(reader, "<top>", null, false, false)))
                {
                    IDictionary <string, string> fields = new Dictionary <string, string>();
                    // id
                    sb = Read(reader, "<num>", null, true, false);
                    int    k  = sb.IndexOf(":", StringComparison.Ordinal);
                    string id = sb.ToString(k + 1, sb.Length - (k + 1)).Trim();
                    // title
                    sb = Read(reader, "<title>", null, true, false);
                    k  = sb.IndexOf(">", StringComparison.Ordinal);
                    string title = sb.ToString(k + 1, sb.Length - (k + 1)).Trim();
                    // description
                    Read(reader, "<desc>", null, false, false);
                    sb.Length = 0;
                    string line = null;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("<narr>", StringComparison.Ordinal))
                        {
                            break;
                        }
                        if (sb.Length > 0)
                        {
                            sb.Append(' ');
                        }
                        sb.Append(line);
                    }
                    string description = sb.ToString().Trim();
                    // narrative
                    sb.Length = 0;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("</top>", StringComparison.Ordinal))
                        {
                            break;
                        }
                        if (sb.Length > 0)
                        {
                            sb.Append(' ');
                        }
                        sb.Append(line);
                    }
                    string narrative = sb.ToString().Trim();
                    // we got a topic!
                    fields["title"]       = title;
                    fields["description"] = description;
                    fields["narrative"]   = narrative;
                    QualityQuery topic = new QualityQuery(id, fields);
                    res.Add(topic);
                }
            }
            finally
            {
                reader.Dispose();
            }
            // sort result array (by ID)
            QualityQuery[] qq = res.ToArray();
            Array.Sort(qq);
            return(qq);
        }