ModErn Text Analysis
META Enumerates Textual Applications
instance.h
Go to the documentation of this file.
1 
9 #ifndef META_LEARN_INSTANCE_H_
10 #define META_LEARN_INSTANCE_H_
11 
12 #include "meta/config.h"
13 #include "meta/util/identifiers.h"
15 
16 namespace meta
17 {
18 namespace learn
19 {
20 using feature_id = term_id;
21 using feature_vector = util::sparse_vector<feature_id, double>;
22 
23 MAKE_NUMERIC_IDENTIFIER_UDL(instance_id, uint64_t, _inst_id)
24 
25 inline void print_liblinear(std::ostream& os, const feature_vector& weights)
26 {
27  for (const auto& count : weights)
28  os << ' ' << (count.first + 1) << ':' << count.second;
29 }
30 
35 struct instance
36 {
37  template <class ForwardIterator>
38  instance(instance_id inst_id, ForwardIterator begin, ForwardIterator end)
39  : id{inst_id}, weights{begin, end}
40  {
41  // nothing
42  }
43 
44  instance(instance_id inst_id, feature_vector wv)
45  : id{inst_id}, weights{std::move(wv)}
46  {
47  // nothing
48  }
49 
50  instance(instance_id inst_id) : id{inst_id}, weights{}
51  {
52  // nothing
53  }
54 
55  void print_liblinear(std::ostream& os) const
56  {
57  learn::print_liblinear(os, weights);
58  }
59 
61  instance_id id;
64 };
65 }
66 }
67 #endif
instance_id id
the id within the dataset that contains this instance
Definition: instance.h:61
STL namespace.
feature_vector weights
the weights of the features in this instance
Definition: instance.h:63
Represents an instance in the dataset, consisting of its id and feature_vector.
Definition: instance.h:35
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25