Skip to content

Commit

Permalink
updated the constructor to make it even simpler
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Staar <[email protected]>
  • Loading branch information
PeterStaar-IBM committed Dec 5, 2024
1 parent 729ff71 commit 7346d94
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/pybind/base_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace andromeda_py

base_log();

base_log(std::string level);

bool set_loglevel(std::string level);
};

Expand All @@ -33,23 +35,32 @@ namespace andromeda_py
*/
}

base_log::base_log(std::string level)
{
set_loglevel(level);
}

bool base_log::set_loglevel(std::string level)
{
if(level=="INFO")
if(level=="INFO" or level=="info")
{
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
}
else if(level=="WARNING")
else if(level=="WARNING" or level=="warning")
{
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
}
else if(level=="ERROR")
else if(level=="ERROR" or level=="error")
{
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
}
else if(level=="FATAL" or level=="fatal")
{
loguru::g_stderr_verbosity = loguru::Verbosity_FATAL;
}
else
{
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
return false;
}

Expand Down
17 changes: 17 additions & 0 deletions src/pybind/nlp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace andromeda_py
public:

nlp_model();
nlp_model(std::string loglevel, bool text_ordering, bool normalise_chars, bool normalise_text);

~nlp_model();

bool initialise(const nlohmann::json config_);
Expand Down Expand Up @@ -66,6 +68,21 @@ namespace andromeda_py
char_normaliser(andromeda::text_element::create_char_normaliser(false)),
text_normaliser(andromeda::text_element::create_text_normaliser(false))
{}

nlp_model::nlp_model(std::string loglevel, bool text_ordering, bool normalise_chars, bool normalise_text):
base_log::base_log(loglevel),
base_resources::base_resources(),

config(nlohmann::json::object({})),

order_text(text_ordering),
models({}),

char_normaliser(andromeda::text_element::create_char_normaliser(normalise_chars)),
text_normaliser(andromeda::text_element::create_text_normaliser(normalise_text))
{
config["order-text"] = order_text;
}

nlp_model::~nlp_model()
{}
Expand Down
10 changes: 9 additions & 1 deletion src/pybind/nlp_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ PYBIND11_MODULE(andromeda_nlp, m) {

pybind11::class_<andromeda_py::nlp_model>(m, "nlp_model")
.def(pybind11::init())

.def(pybind11::init<std::string, bool, bool, bool>(),
pybind11::arg("loglevel"),
pybind11::arg("text_ordering") = true,
pybind11::arg("normalise_chars") = true,
pybind11::arg("normalise_text") = true,
R"(
Initialise the NLP models with standard parameters.)"
)

.def("set_loglevel", &andromeda_py::nlp_model::set_loglevel)
.def("get_resources_path", &andromeda_py::nlp_model::get_resources_path)

Expand Down
9 changes: 8 additions & 1 deletion tests/test_simple_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from deepsearch_glm.andromeda_nlp import nlp_model


def test_simple_interface():
def test_simple_interface_v1():
model = nlp_model()
model.set_loglevel("WARNING")

Expand All @@ -15,3 +15,10 @@ def test_simple_interface():

doc = json.load(open("tests/data/docs/1806.02284.json"))
output = model.apply_on_doc(doc)

def test_simple_interface_v2():
model = nlp_model(loglevel="warning", text_ordering=True)

doc = json.load(open("tests/data/docs/1806.02284.json"))
output = model.apply_on_doc(doc)

0 comments on commit 7346d94

Please sign in to comment.