QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
svml.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 <string>
25 
26 #include "data/dataset.h"
27 
28 namespace quickrank {
29 namespace io {
30 
31 /**
32  * This class implements IO on Svml files.
33  *
34  * SVML format is as follows:
35  * \verbatim
36  <line> .=. <target> qid:<qid> <feature>:<value> <feature>:<value> ... <feature>:<value> # <info>
37  <target> .=. <float>
38  <qid> .=. <positive integer>
39  <feature> .=. <positive integer>
40  <value> .=. <float>
41  <info> .=. <string>
42  \endverbatim
43 
44  \todo TODO: handle feature filtering
45  */
46 class Svml {
47  public:
48  /// Creates a new Svml IO reader/writer.
49  ///
50  /// \param k The cut-off threshold.
51  Svml() {
52  }
53 
54  virtual ~Svml() {
55  }
56 
57  /// Reads the input dataset and returns in horizontal format.
58  /// \param file the input filename.
59  /// \return The svml dataset in horizontal format.
60  virtual std::unique_ptr<data::Dataset> read_horizontal(
61  const std::string &file);
62 
63  /// Write the dataset to an output file.
64  /// \param file the output filename.
65  /// \return The svml dataset in horizontal format.
66  virtual void write(
67  std::shared_ptr<data::Dataset>,
68  const std::string &file);
69 
70  private:
71  double reading_time_ = 0.0;
72  double processing_time_ = 0.0;
73  long file_size_ = 0;
74 
75  /// The output stream operator.
76  /// Prints the data reading time stats.
77  friend std::ostream &operator<<(std::ostream &os, const Svml &me) {
78  return me.put(os);
79  }
80 
81  /// Prints the data reading time stats
82  virtual std::ostream &put(std::ostream &os) const;
83 
84 };
85 
86 } // namespace io
87 } // namespace quickrank
Definition: dataset.cc:28
double reading_time_
Definition: svml.h:71
virtual void write(std::shared_ptr< data::Dataset >, const std::string &file)
Write the dataset to an output file.
Definition: svml.cc:163
virtual std::ostream & put(std::ostream &os) const
Prints the data reading time stats.
Definition: svml.cc:187
double processing_time_
Definition: svml.h:72
Svml()
Creates a new Svml IO reader/writer.
Definition: svml.h:51
virtual std::unique_ptr< data::Dataset > read_horizontal(const std::string &file)
Reads the input dataset and returns in horizontal format.
Definition: svml.cc:38
virtual ~Svml()
Definition: svml.h:54
This class implements IO on Svml files.
Definition: svml.h:46
long file_size_
Definition: svml.h:73
friend std::ostream & operator<<(std::ostream &os, const Svml &me)
The output stream operator.
Definition: svml.h:77