-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeproApi.py
72 lines (50 loc) · 2 KB
/
TeproApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from TeproAlgo import TeproAlgo
from TeproDTO import TeproDTO
class TeproApi(object):
"""This is the Python class that each NLP app
has to implement so that it can be plugged into
the TEPROLIN platform."""
def __init__(self):
"""The constructor gets the name of the NLP application/algorithm
that is used by 'TeproAlgo' to construct allowed operation
chains."""
self._algoName = ""
def getAlgoName(self):
return self._algoName
def loadResources(self):
"""Call this method after createApp so that
the NLP app can load all resources it needs."""
pass
def createApp(self):
"""Call this method so that the process is spawned
and the app is waiting for input."""
pass
def destroyApp(self):
"""This method will 'gracefully' destroy the NLP app."""
pass
def _checkProgress(self, dto: TeproDTO) -> list:
"""Checks what operations have been perforemed already
and what needs to be done futher."""
opNotDone = []
for op in TeproAlgo.getOperationsForAlgo(self._algoName):
if not dto.isOpPerformed(op) or \
self._algoName == dto.getConfiguredAlgoForOper(op):
opNotDone.append(op)
return opNotDone
def _runApp(self, dto: TeproDTO, opNotDone: list) -> TeproDTO:
"""This is the method that does the actual work
of this NLP app. Takes the list of currently not done
operations."""
return dto
def doWork(self, dto: TeproDTO) -> TeproDTO:
"""The main method that has to be called so that the app
can perform its work on 'dto' of type TeproDTO. The result
is written in 'dto' which is an object reference."""
notdone = self._checkProgress(dto)
# Return if everything is done.
if not notdone:
return
dto = self._runApp(dto, notdone)
for op in notdone:
dto.addPerformedOp(op)
return dto