QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
metric_factory.h
Go to the documentation of this file.
1 /*
2  * QuickRank - A C++ suite of Learning to Rank algorithms
3  * Webpage: http://quickrank.isti.cnr.it/
4  * Contact: quickrank@isti.cnr.it
5  *
6  * Unless explicitly acquired and licensed from Licensor under another
7  * license, the contents of this file are subject to the Reciprocal Public
8  * License ("RPL") Version 1.5, or subsequent versions as allowed by the RPL,
9  * and You may not copy or use this file in either source code or executable
10  * form, except in compliance with the terms and conditions of the RPL.
11  *
12  * All software distributed under the RPL is provided strictly on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND
14  * LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
15  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16  * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific
17  * language governing rights and limitations under the RPL.
18  *
19  * Contributor:
20  * HPC. Laboratory - ISTI - CNR - http://hpc.isti.cnr.it/
21  */
22 #pragma once
23 
24 #include <iostream>
25 #include <climits>
26 #include <memory>
27 
28 #include "types.h"
29 
30 #include "metric/ir/tndcg.h"
31 #include "metric/ir/ndcg.h"
32 #include "metric/ir/dcg.h"
33 #include "metric/ir/map.h"
34 
35 namespace quickrank {
36 namespace metric {
37 namespace ir {
38 
39 std::shared_ptr<Metric> ir_metric_factory(std::string metric,
40  size_t cutoff) {
41  std::transform(metric.begin(), metric.end(),
42  metric.begin(), ::toupper);
43  if (metric == Dcg::NAME_)
44  return std::shared_ptr<Metric>(new Dcg(cutoff));
45  else if (metric == Ndcg::NAME_)
46  return std::shared_ptr<Metric>(new Ndcg(cutoff));
47  else if (metric == Tndcg::NAME_)
48  return std::shared_ptr<Metric>(new Tndcg(cutoff));
49  else if (metric == Map::NAME_)
50  return std::shared_ptr<Metric>(new Map(cutoff));
51  else
52  return std::shared_ptr<Metric>();
53 }
54 
55 } // namespace ir
56 } // namespace metric
57 } // namespace quickrank
Definition: dataset.cc:28
std::shared_ptr< Metric > ir_metric_factory(std::string metric, size_t cutoff)
Definition: metric_factory.h:39
static const std::string NAME_
Definition: tndcg.h:51
This class implements the average precision AP@k measure.
Definition: map.h:36
This class implements the Normalized Discounted cumulative Gain NDCG@k measure.
Definition: ndcg.h:38
This class implements a Tie-aware version of Normalized Discounted Cumulative Gain TNDCG@k measure...
Definition: tndcg.h:38
static const std::string NAME_
Definition: ndcg.h:51
static const std::string NAME_
Definition: dcg.h:50
static const std::string NAME_
Definition: map.h:49
This class implements the Discounted cumulative Gain DCG@K measure.
Definition: dcg.h:37