diff options
author | Hal Daume III <me@hal3.name> | 2014-09-22 06:02:38 +0400 |
---|---|---|
committer | Hal Daume III <me@hal3.name> | 2014-09-22 06:02:38 +0400 |
commit | 2cffcd53b6ecc28e03994f09d4492753065fc0f6 (patch) | |
tree | 5d62779691834225977be3cb33eaf77bb2112262 /vowpalwabbit/search_hooktask.cc | |
parent | 6568385d7945a176a3370c719eda8c52804f7ff1 (diff) |
added missing files
Diffstat (limited to 'vowpalwabbit/search_hooktask.cc')
-rw-r--r-- | vowpalwabbit/search_hooktask.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vowpalwabbit/search_hooktask.cc b/vowpalwabbit/search_hooktask.cc new file mode 100644 index 00000000..7a8435dd --- /dev/null +++ b/vowpalwabbit/search_hooktask.cc @@ -0,0 +1,38 @@ +/* +Copyright (c) by respective owners including Yahoo!, Microsoft, and +individual contributors. All rights reserved. Released under a BSD (revised) +license as described in the file LICENSE. + */ +#include "search_hooktask.h" + +// this is used for the C++ library and python library hook; hopefully +// it can be used for any foreign library too! +namespace HookTask { + Search::search_task task = { "hook", run, initialize, finish, NULL, NULL }; + + void initialize(Search::search& sch, size_t& num_actions, po::variables_map& vm) { + task_data *td = new task_data; + td->run_f = NULL; + td->run_object = NULL; + td->delete_run_object = NULL; + td->var_map = new po::variables_map(vm); + td->num_actions = num_actions; + sch.set_task_data<task_data>(td); + } + + void finish(Search::search& sch) { + task_data *td = sch.get_task_data<task_data>(); + if (td->run_object && td->delete_run_object) td->delete_run_object(td->run_object); + delete td->var_map; + delete td; + } + + void run(Search::search& sch, vector<example*>& ec) { + task_data *td = sch.get_task_data<task_data>(); + if (td->run_f) + td->run_f(sch); + else + cerr << "warning: HookTask::structured_predict called before hook is set" << endl; + } +} + |