Skip to content
Snippets Groups Projects
Commit e31cfc28 authored by Bartosz Walkowiak's avatar Bartosz Walkowiak
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !6
parents 5bcfe6eb f5fc8074
Branches master
1 merge request!6Develop
Pipeline #14787 passed with stages
in 1 minute and 1 second
......@@ -2,19 +2,27 @@ image: 'clarinpl/python:3.6'
cache:
paths:
- .tox
stages:
- check_style
- build
before_script:
- pip install tox==2.9.1
.check_style_template:
before_script:
- pip install tox==2.9.1
pep8:
extends: .check_style_template
stage: check_style
script:
- tox -v -e pep8
docstyle:
extends: .check_style_template
stage: check_style
script:
- tox -v -e docstyle
build_image:
stage: build
image: 'docker:18.09.7'
......@@ -23,9 +31,7 @@ build_image:
- gitlab-registry
services:
- 'docker:18.09.7-dind'
before_script:
- ''
script:
- docker build -t $CI_REGISTRY_IMAGE .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE
\ No newline at end of file
- docker push $CI_REGISTRY_IMAGE
......@@ -8,4 +8,4 @@ COPY ./info.json .
RUN python3.6 -m pip install -r requirements.txt
CMD ["python3.6", "main.py", "service"]
CMD ["python3.6", "main.py"]
"""Implementation of hask service."""
import argparse
import lex_ws
from src.omwn_worker import OMWNWorker
def get_args():
"""Gets command line arguments."""
parser = argparse.ArgumentParser(description="Topic Modeling")
subparsers = parser.add_subparsers(dest="algorithm")
subparsers.required = True
subparsers.add_parser(
"service",
help="Run as a service"
)
return parser.parse_args()
def main():
"""Runs the program."""
args = get_args()
generators = {
"service": lambda: lex_ws.LexService.main(OMWNWorker),
}
gen_fn = generators.get(args.algorithm, lambda: None)
gen_fn()
if __name__ == "__main__":
main()
lex_ws.LexService.main(OMWNWorker)
"""Implementation of omwn_worker."""
import logging
import json
import logging
import lex_ws
import nltk
from nltk.corpus import wordnet as wn
my_logger = logging.getLogger(__name__)
_log = logging.getLogger(__name__)
......@@ -18,7 +18,11 @@ class OMWNWorker(lex_ws.LexWorker):
@classmethod
def static_init(cls, config):
"""Initialize worker."""
"""Initialize worker.
:param config: The service configuration dictionary.
:type config: dict
"""
nltk.download('wordnet')
nltk.download('omw')
my_logger.info("Loading models...")
......@@ -27,25 +31,43 @@ class OMWNWorker(lex_ws.LexWorker):
my_logger.info("Loading finished.")
return
def process(self, input):
"""Running lex process."""
def process(self, input_):
"""Running lex process.
:param input_: The process input.
:type input_: dict
:returns: The required result specified by the value under
"function_type" key in the input_.
:rtype: dict
"""
my_logger.info("Doing work!")
result = {}
if "function" in input:
result = self.evaluate_function(input["function"], input)
if "function" in input_:
result = self.evaluate_function(input_["function"], input_)
my_logger.info("Work done!")
return result
def evaluate_function(self, function_type, input):
"""Performes evaluation and returns appropriate response."""
def evaluate_function(self, function_type, input_):
"""Performs evaluation and returns appropriate response.
:param function_type: Tells the function which action to perform.
Available values are "list", "get" and "getInfo".
:type function_type: str
:param input_: The input dictionary.
:type input_: dict
:returns: The required result specified by function_type parameter.
:rtype: dict
"""
response = {}
if function_type == "list":
element = input["element"]
element = input_["element"]
url = "http://compling.hss.ntu.edu.sg/omw/cgi-bin/wn-gridx.cgi?"
if "lang" not in element or element["lang"] not in languages:
return response
if ("lemma" in element):
if "lemma" in element:
res = wn.lemmas(element["lemma"].encode(
"utf-8").decode("utf-8"), lang=languages[element["lang"]])
if len(res) > 0:
......@@ -57,10 +79,10 @@ class OMWNWorker(lex_ws.LexWorker):
return response
elif function_type == "get":
element = input["element"]
element = input_["element"]
if "lang" not in element or element["lang"] not in languages:
return response
if ("lemma" in element):
if "lemma" in element:
return self._get_data_by_lemma(
element["lemma"], languages[element["lang"]])
......@@ -81,7 +103,7 @@ class OMWNWorker(lex_ws.LexWorker):
wnsynset = wnlem.synset()
trans = dict()
for lang in languages:
if (languages[lang] != language):
if languages[lang] != language:
trans[lang] = wnsynset.lemma_names(languages[lang])
synset = {"name": wnsynset.name(),
"definition": wnsynset.definition(),
......
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