nlparrot

natural language processing server
Log | Files | Refs | README | LICENSE

commit 9b85e20d877c0b1c35b2b39ef5d86bb2a22fd702
parent 70cb172f11e6ac4c3c9700573a3e8be7f23cf45b
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Sun, 27 Aug 2023 13:57:24 +0200

accept multiple possible languages to choose from

Diffstat:
Mpyproject.toml | 2+-
Msrc/nlparrot/server.py | 13+++++--------
2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nlparrot" -version = "0.0.1" +version = "0.0.2" dependencies = [ 'classla', 'pyphen', diff --git a/src/nlparrot/server.py b/src/nlparrot/server.py @@ -23,9 +23,6 @@ if __name__ == "__main__": current_language = None tokenizers = None - # TODO: Receive supported languages from client program - supported_languages = ["hr", "ja"] - with Listener(**get_listen_address()) as listener: print("Listening for connection ...") @@ -33,12 +30,12 @@ if __name__ == "__main__": with listener.accept() as conn: task: dict = conn.recv() - if task["language"] is None: - language = detect_language(task["text"], supported_languages=supported_languages) - print(f'Auto-detected language "{language}"') - else: - language = task["language"] + if len(task["languages"]) == 1: + language = task["languages"][0] print(f'Received language "{language}"') + else: + language = detect_language(task["text"], supported_languages=task["languages"]) + print(f'Auto-detected language "{language}"') if tokenizers is None or current_language != language: tokenizers = get_tokenizers(language)