1 #include <stdio.h>
2 #include "../vowpalwabbit/parser.h"
3 #include "../vowpalwabbit/vw.h"
4 #include "../vowpalwabbit/ezexample.h"
5 
6 using namespace std;
7 
main(int argc,char * argv[])8 int main(int argc, char *argv[])
9 {
10   string init_string = "-t -q st --hash all --noconstant --ldf_override s -i ";
11   if (argc > 1)
12     init_string += argv[1];
13   else
14     init_string += "train.w";
15 
16   cerr << "initializing with: '" << init_string << "'" << endl;
17 
18   // INITIALIZE WITH WHATEVER YOU WOULD PUT ON THE VW COMMAND LINE -- THIS READS IN A MODEL FROM train.w
19   vw* vw = VW::initialize(init_string); // "-t -q st --hash all --noconstant --ldf_override s -i train.w");
20 
21   {
22     // HAL'S SPIFFY INTERFACE USING C++ CRAZINESS
23     ezexample ex(vw, false);  // don't need multiline
24     ex(vw_namespace('s'))
25       ("p^the_man")
26       ("w^the")
27       ("w^man")
28       (vw_namespace('t'))
29       ("p^le_homme")
30       ("w^le")
31       ("w^homme");
32     ex.set_label("1");
33     cerr << ex.predict_partial() << endl;
34 
35     //    ex.clear_features();
36 
37     --ex;   // remove the most recent namespace
38     ex(vw_namespace('t'))
39       ("p^un_homme")
40       ("w^un")
41       ("w^homme");
42     ex.set_label("2");
43     cerr << ex.predict_partial() << endl;
44 
45     --ex;   // remove the most recent namespace, and add features with explicit ns
46     ex('t', "p^un_homme")
47       ('t', "w^un")
48       ('t', "w^homme");
49     ex.set_label("2");
50     cerr << ex.predict_partial() << endl;
51   }
52 
53   // AND FINISH UP
54   VW::finish(*vw);
55 }
56