Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
omwn
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lexworkers
omwn
Commits
e31cfc28
Commit
e31cfc28
authored
1 year ago
by
Bartosz Walkowiak
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' into 'master'
Develop See merge request
!6
parents
5bcfe6eb
f5fc8074
Branches
master
1 merge request
!6
Develop
Pipeline
#14787
passed with stages
in 1 minute and 1 second
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+11
-5
11 additions, 5 deletions
.gitlab-ci.yml
Dockerfile
+1
-1
1 addition, 1 deletion
Dockerfile
main.py
+1
-30
1 addition, 30 deletions
main.py
src/omwn_worker.py
+36
-14
36 additions, 14 deletions
src/omwn_worker.py
with
49 additions
and
50 deletions
.gitlab-ci.yml
+
11
−
5
View file @
e31cfc28
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Dockerfile
+
1
−
1
View file @
e31cfc28
...
...
@@ -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"]
This diff is collapsed.
Click to expand it.
main.py
+
1
−
30
View file @
e31cfc28
"""
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
)
This diff is collapsed.
Click to expand it.
src/omwn_worker.py
+
36
−
14
View file @
e31cfc28
"""
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
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment