Skip to content

Commit

Permalink
Renamed Applicator to PluginSocket.
Browse files Browse the repository at this point in the history
- the new name hopefully better describes its current function (see #3).
  • Loading branch information
fpetran committed Feb 23, 2017
1 parent a5ecf8c commit 0bd5e41
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_sources(applicator.cpp cycle.cpp string_impl.cpp training_data.cpp)
install_headers(applicator.h cycle.h gfsmlibs.h interface.h norma.h
add_sources(pluginsocket.cpp cycle.cpp string_impl.cpp training_data.cpp)
install_headers(pluginsocket.h cycle.h gfsmlibs.h interface.h norma.h
regex_impl.h string_impl.h training_data.h
training_data-inl.h)
16 changes: 8 additions & 8 deletions src/cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include<cctype>
#include"normalizer/result.h"
#include"interface.h"
#include"applicator.h"
#include"pluginsocket.h"
#include"training_data.h"
#include"results_queue.h"

Expand All @@ -36,8 +36,8 @@ namespace Norma {
Cycle::~Cycle() {
if (_data != nullptr)
delete _data;
if (_applicator != nullptr)
delete _applicator;
if (_plugins != nullptr)
delete _plugins;
}

void Cycle::init(Input *input, Output* output,
Expand All @@ -55,7 +55,7 @@ void Cycle::init_chain(const std::string& chain_definition,
const std::string& plugin_base) {
if (_in == nullptr || _out == nullptr)
throw std::runtime_error("Cycle was not intialized!");
_applicator = new Applicator(chain_definition, plugin_base, _params);
_plugins = new PluginSocket(chain_definition, plugin_base, _params);
}

void Cycle::start() {
Expand All @@ -67,7 +67,7 @@ void Cycle::start() {
o->put_line(&r, print_prob, ll);
};
auto producer = [this](string_impl line) {
auto my_result = _applicator->normalize(line);
auto my_result = _plugins->normalize(line);
return my_result;
};
res.set_consumer(outputter);
Expand All @@ -83,7 +83,7 @@ void Cycle::start() {
if (settings["normalize"])
res.add_producer(producer, line);
if (settings["train"] && _out->request_train())
_applicator->train(_data);
_plugins->train(_data);
}
res.finish();
_in->end();
Expand All @@ -103,14 +103,14 @@ bool Cycle::training_pair(const string_impl& line) {
extract(line, divpos + 1, line.length(), &modern);
_data->add_source(word);
_data->add_target(modern);
_applicator->train(_data);
_plugins->train(_data);
return true;
}
return false;
}

void Cycle::save_params() {
_applicator->save_params();
_plugins->save_params();
}
} // namespace Norma

9 changes: 3 additions & 6 deletions src/cycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@
namespace Norma {
class Input;
class Output;
class Applicator;
class PluginSocket;

/// the main application cycle
/** This class contains the main loop for input and output.
* It connects Input, Output, and Applicator classes.
* At some point it should support multiple Applicator instances
* and supply a way of choosing between their input, but right
* now, it's just the one.
* It connects Input, Output, and PluginSocket classes.
*
* Usually, an application should need just one Cycle object,
* but it's conceivable to have multiple ones, e.g. when
Expand Down Expand Up @@ -72,7 +69,7 @@ class Cycle {
{ "normalize", true },
{ "prob", true } };
TrainingData* _data = nullptr;
Applicator* _applicator = nullptr;
PluginSocket* _plugins = nullptr;
Input* _in = nullptr;
Output* _out = nullptr;

Expand Down
25 changes: 13 additions & 12 deletions src/applicator.cpp → src/pluginsocket.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2013-2015 Marcel Bollmann, Florian Petran
/* Copyright 2013-2017 Marcel Bollmann, Florian Petran
*
* This file is part of Norma.
*
Expand All @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public License along
* with Norma. If not, see <http://www.gnu.org/licenses/>.
*/
#include"applicator.h"
#include"pluginsocket.h"
#include<dlfcn.h> // linux specific XXX
#include<string>
#include<stdexcept>
Expand All @@ -40,7 +40,7 @@ using std::string;

namespace Norma {

Applicator::Applicator(const string& chain_definition,
PluginSocket::PluginSocket(const string& chain_definition,
const string& plugin_base_param,
const map<string, string>& params)
: config_vars(params), chain_def(chain_definition),
Expand All @@ -60,19 +60,19 @@ Applicator::Applicator(const string& chain_definition,
}
}

Applicator::~Applicator() {
PluginSocket::~PluginSocket() {
delete _lex;
for (auto normalizer : created_normalizers)
normalizer.first(normalizer.second);
for (auto plugin : loaded_plugins)
dlclose(plugin);
}

void Applicator::push_chain(Normalizer::Base* n) {
void PluginSocket::push_chain(Normalizer::Base* n) {
push_back(n);
}

void Applicator::init_chain() {
void PluginSocket::init_chain() {
std::set<std::string> aliases;
std::istringstream chain_stream(chain_def);
string element;
Expand Down Expand Up @@ -116,7 +116,7 @@ void Applicator::init_chain() {
}
}

Normalizer::Result Applicator::normalize(const string_impl& word) const {
Normalizer::Result PluginSocket::normalize(const string_impl& word) const {
// starting all normalizers async seems to make everything slower
// presumably this is because the cascade_lookup blocks
unsigned int priority = 1;
Expand All @@ -132,7 +132,7 @@ Normalizer::Result Applicator::normalize(const string_impl& word) const {
return bestresult;
}

void Applicator::train(TrainingData *data) {
void PluginSocket::train(TrainingData *data) {
if (data->empty())
return;

Expand Down Expand Up @@ -172,13 +172,13 @@ void Applicator::train(TrainingData *data) {
}

const Normalizer::Result&
Applicator::best_score(Normalizer::Result* one,
PluginSocket::best_score(Normalizer::Result* one,
Normalizer::Result* two) {
return (one->score > two->score) ? *one : *two;
}

const Normalizer::Result&
Applicator::best_priority(Normalizer::Result* one,
PluginSocket::best_priority(Normalizer::Result* one,
Normalizer::Result* two) {
if ((two->priority < one->priority) && two->score > 0.0) {
two->is_final = true;
Expand All @@ -187,7 +187,7 @@ const Normalizer::Result&
return *one;
}

void Applicator::save_params() {
void PluginSocket::save_params() {
for (auto n : *this) {
try {
n->save_params();
Expand All @@ -205,7 +205,7 @@ void Applicator::save_params() {
}
}

Normalizer::Base* Applicator::create_plugin(const std::string& lib_name,
Normalizer::Base* PluginSocket::create_plugin(const std::string& lib_name,
const std::string& alias) {
// this is linux specific now
std::string plugin_name = plugin_base + "/lib" + lib_name + ".so";
Expand Down Expand Up @@ -234,3 +234,4 @@ Normalizer::Base* Applicator::create_plugin(const std::string& lib_name,
}

} // namespace Norma

20 changes: 10 additions & 10 deletions src/applicator.h → src/pluginsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* You should have received a copy of the GNU Lesser General Public License along
* with Norma. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef APPLICATOR_H_
#define APPLICATOR_H_
#ifndef PLUGINSOCKET_H_
#define PLUGINSOCKET_H_
#include<list>
#include<string>
#include<map>
Expand Down Expand Up @@ -49,15 +49,15 @@ class Base;
* concurrency related issues as possible from the authors of
* the Normalizer.
**/
class Applicator : private std::list<Normalizer::Base*> {
class PluginSocket : private std::list<Normalizer::Base*> {
public:
explicit Applicator(const std::string& chain_definition,
explicit PluginSocket(const std::string& chain_definition,
const std::string& plugin_base_param,
const std::map<std::string, std::string>& params);
Applicator() = delete;
Applicator(const Applicator& a) = delete;
const Applicator& operator=(const Applicator& a) = delete;
~Applicator();
PluginSocket() = delete;
PluginSocket(const PluginSocket& a) = delete;
const PluginSocket& operator=(const PluginSocket& a) = delete;
~PluginSocket();

/// add a normalizer to the back of the chain
inline void push_chain(Normalizer::Base* n);
Expand All @@ -83,7 +83,7 @@ class Applicator : private std::list<Normalizer::Base*> {
Normalizer::Result*)>
Chooser;
/// choose between two results
Chooser chooser = Applicator::best_priority;
Chooser chooser = PluginSocket::best_priority;

private:
Normalizer::Base* create_plugin(const std::string& lib_name,
Expand All @@ -96,5 +96,5 @@ class Applicator : private std::list<Normalizer::Base*> {
};
} // namespace Norma

#endif // APPLICATOR_H_
#endif // PLUGINSOCKET_H_

0 comments on commit 0bd5e41

Please sign in to comment.