Debian Codegraph @

apertium_apy/handlers/translate_chain.py

raw symbols SCIP
1 from tornadoscip-python python tornado 6.5.5 tornado/__init__: import gen
2
3 from apertium_apy.handlers.translatescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/__init__: import TranslateHandlerscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#
4 from apertium_apy.utilsscip-python python apertium-apy 0.13.0 `apertium_apy.utils`/__init__: import to_alpha3_codescip-python python apertium-apy 0.13.0 `apertium_apy.utils`/to_alpha3_code().
5 from apertium_apy.utils.translationscip-python python apertium-apy 0.13.0 `apertium_apy.utils.translation`/__init__: import coreducescip-python python apertium-apy 0.13.0 `apertium_apy.utils.translation`/coreduce().
6
7
8 class TranslateChainHandlerscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#(TranslateHandlerscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#):
9 def pair_listscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(self), langsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(langs)):
10 return [(langsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(langs)[i], langsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(langs)[i + 1]) for i in rangescip-python python python-stdlib 3.11 builtins/range#(0, len(langsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(langs)) - 1)]
11
12 def get_pairs_or_errorscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self), langpairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(langpairs), text_lengthscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(text_length)):
13 langs = [to_alpha3_codescip-python python apertium-apy 0.13.0 `apertium_apy.utils`/to_alpha3_code().(lang) for lang in langpairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(langpairs).split('|')]
14 if len(langs) < 2:
15 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).send_error(400, explanation='Need at least two languages, use e.g. eng|spa')
16 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_after_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_after_translation().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_before_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_before_translation().(), text_lengthscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(text_length))
17 return None
18 if len(langs) == 2:
19 if langs[0] == langs[1]:
20 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).send_error(400, explanation='Need at least two languages, use e.g. eng|spa')
21 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_after_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_after_translation().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_before_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_before_translation().(), text_lengthscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(text_length))
22 return None
23 return selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).pathsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#paths..getscip-python python python-stdlib 3.11 builtins/dict#get().(langs[0], {}).getscip-python python python-stdlib 3.11 builtins/dict#get().(langs[1])
24 for lang1, lang2 in selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).pair_listscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(langs):
25 if '{:s}-{:s}'.format(lang1, lang2) not in selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#pairs.:
26 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).send_error(400, explanation='Pair {:s}-{:s} is not installed'.format(lang1, lang2))
27 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_after_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_after_translation().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(self).log_before_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_before_translation().(), text_lengthscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(text_length))
28 return None
29 return langs
30
31 @gen.coroutine
32 def translate_and_respondscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self), pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs), pipelinesscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pipelines), to_translatescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(to_translate), mark_unknownscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(mark_unknown), nosplitscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(nosplit)=False, deformatscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(deformat)=True, reformatscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(reformat)=True):
33 mark_unknownscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(mark_unknown) = mark_unknownscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(mark_unknown) in ['yes', 'true', '1']
34 chain, pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs) = pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs), selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).pair_listscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs))
35 for pair in pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs):
36 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).note_pair_usagescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#note_pair_usage().(pair)
37 before = selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).log_before_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_before_translation().()
38 translated = yield coreducescip-python python apertium-apy 0.13.0 `apertium_apy.utils.translation`/coreduce().(to_translatescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(to_translate), [p.translate for p in pipelinesscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pipelines)], nosplitscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(nosplit), deformatscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(deformat), reformatscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(reformat))
39 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).log_after_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_after_translation().(before, len(to_translatescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(to_translate)))
40 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).send_responsescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#send_response().({
41 'responseData': {
42 'translatedText': selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).maybe_strip_marksscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#maybe_strip_marks().(mark_unknownscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(mark_unknown), (pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs)[0][0], pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs)[-1][1]), translated),
43 'translationChain': chain,
44 },
45 'responseDetails': None,
46 'responseStatus': 200,
47 })
48 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(self).clean_pairsscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#clean_pairs().()
49
50 def preparescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#prepare().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#prepare().(self)):
51 if not selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#prepare().(self).pairs_graphscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#pairs_graph.:
52 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#prepare().(self).init_pairs_graphscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#init_pairs_graph().()
53
54 @gen.coroutine
55 def getscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self)):
56 q = selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_argument('q', default=None)
57 langpairs = selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_argument('langpairs')
58 pairs = selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_pairs_or_errorscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(langpairs, len(q or []))
59 if pairs:
60 if not q:
61 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).send_responsescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.base`/BaseHandler#send_response().({
62 'responseData': {
63 'translationChain': selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_pairs_or_errorscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get_pairs_or_error().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_argument('langpairs'), 0),
64 },
65 'responseDetails': None,
66 'responseStatus': 200,
67 })
68 else:
69 pipelines = [selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_pipelinescip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#get_pipeline().(pair) for pair in selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).pair_listscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#pair_list().(pairs)]
70 deformat, reformat = selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_formatscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#get_format().()
71 yield selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).translate_and_respondscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#translate_and_respond().(pairs, pipelines, q,
72 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).get_argument('markUnknown', default='yes'),
73 nosplit=False, deformat=deformat, reformat=reformat)
74 else:
75 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).send_error(400, explanation='No path found for {:s}-{:s}'.format(*langpairs.splitscip-python python python-stdlib 3.11 builtins/str#split().('|')))
76 selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).log_after_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_after_translation().(selfscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate_chain`/TranslateChainHandler#get().(self).log_before_translationscip-python python apertium-apy 0.13.0 `apertium_apy.handlers.translate`/TranslateHandler#log_before_translation().(), 0)