Skip to content
Snippets Groups Projects
Commit b074855c authored by Radosław Warzocha's avatar Radosław Warzocha
Browse files

Config files reading

parent a5835726
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ add_definitions(-DHAVE_VERSION_H)
# source code files
set(libwcrft_STAT_SRC
config.cpp
corpusio.cpp
classify.cpp
tagger.cpp
......
......@@ -12,10 +12,53 @@
See the LICENCE and COPYING files for more details
*/
#include <fstream>
#include <boost/program_options.hpp>
#include "config.h"
namespace prog_opts = boost::program_options;
namespace Wcrft {
prog_opts::options_description create_config_file_description();
prog_opts::variables_map parse_config_file(const std::string& config_filename, prog_opts::options_description desc);
boost::shared_ptr<const Config> read_config_file(std::string config_filename)
{
prog_opts::options_description desc = create_config_file_description();
prog_opts::variables_map var_map = parse_config_file(config_filename, desc);
return boost::shared_ptr<const Config>(&var_map);
}
prog_opts::options_description create_config_file_description()
{
prog_opts::options_description desc("Config file options");
desc.add_options()
((CONFIG_S_GLOBAL + "." + CONFIG_O_TAGSET).c_str(), prog_opts::value<std::string>())
((CONFIG_S_GLOBAL + "." + CONFIG_O_FEATS).c_str(), prog_opts::value<std::string>())
((CONFIG_S_GLOBAL + "." + CONFIG_O_MACACFG).c_str(), prog_opts::value<std::string>())
((CONFIG_S_GLOBAL + "." + CONFIG_O_ATTRS).c_str(), prog_opts::value<std::string>())
((CONFIG_S_LEXICON + "." + CONFIG_O_CASESENS).c_str(), prog_opts::value<bool>())
((CONFIG_S_LEXICON + "." + CONFIG_O_MINFREQ).c_str(), prog_opts::value<int>())
((CONFIG_S_LEXICON + "." + CONFIG_O_MAXENTRIES).c_str(), prog_opts::value<int>())
((CONFIG_S_UNKNOWN + "." + CONFIG_O_UNKGUESS).c_str(), prog_opts::value<bool>())
((CONFIG_S_UNKNOWN + "." + CONFIG_O_UNKFREQ).c_str(), prog_opts::value<int>())
((CONFIG_S_CLASSIFIER + "." + CONFIG_O_PARAMS).c_str(), prog_opts::value<std::string>())
;
return desc;
}
prog_opts::variables_map parse_config_file(const std::string& config_filename, prog_opts::options_description desc)
{
prog_opts::variables_map var_map;
std::ifstream config_file(config_filename.c_str(), std::ifstream::in);
prog_opts::store(prog_opts::parse_config_file(config_file, desc), var_map);
prog_opts::notify(var_map);
return var_map;
}
}
......@@ -15,14 +15,16 @@
#ifndef WCRFT_CONFIG_H
#define WCRFT_CONFIG_H
#include <map>
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
namespace Wcrft {
typedef std::map<std::string, std::string> Config;
typedef boost::program_options::variables_map Config;
Config read_config_file(std::string config_filename)
{
return std::map<std::string, std::string>();
}
boost::shared_ptr<const Config> read_config_file(const std::string& config_filename);
// global section with tagset-related definitions
const std::string CONFIG_S_GLOBAL = "general";
......
......@@ -58,10 +58,16 @@ namespace Wcrft {
return Corpus2::TokenWriter::create_stream_writer(output_format, std::cout, tagset);
}
inline const Corpus2::Tagset& get_tagset_from_config(const Config& configuration)
boost::shared_ptr<Corpus2::TokenWriter> get_writer(std::ostream& output_stream, const std::string& output_format,
Corpus2::Tagset& tagset)
{
return Corpus2::TokenWriter::create_stream_writer(output_format, output_stream, tagset);
}
inline const Corpus2::Tagset& get_tagset_from_config(Config& configuration)
{
std::string var_name = CONFIG_S_GLOBAL + "." + CONFIG_O_TAGSET;
return Corpus2::get_named_tagset(configuration[var_name]);
return Corpus2::get_named_tagset(configuration[var_name].as<std::string>());
}
inline const std::string filename_from_model_name(const std::string& model_name, const std::string& subdir,
......
......@@ -34,6 +34,8 @@ namespace Wcrft {
Corpus2::Tagset& tagset, const std::string& maca_config);
boost::shared_ptr<Corpus2::TokenWriter> get_writer(const std::string& output_path, const std::string& output_format,
Corpus2::Tagset& tagset);
boost::shared_ptr<Corpus2::TokenWriter> get_writer(const std::ostream& output_stream, const std::string& output_format,
Corpus2::Tagset& tagset);
inline const Corpus2::Tagset& get_tagset_from_config(const Config& configuration);
inline const std::string filename_from_model_name(const std::string& model_name, const std::string& subdir,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment