tomaseo2022 commited on
Commit
06c6bcc
·
1 Parent(s): 8c8eae5

Upload models.py

Browse files
Files changed (1) hide show
  1. models.py +47 -0
models.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class Translated:
2
+ """Translate result object
3
+
4
+ :param src: source langauge (default: auto)
5
+ :param dest: destination language (default: en)
6
+ :param origin: original text
7
+ :param text: translated text
8
+ :param pronunciation: pronunciation
9
+ """
10
+ def __init__(self, src, dest, origin, text, pronunciation, extra_data=None):
11
+ self.src = src
12
+ self.dest = dest
13
+ self.origin = origin
14
+ self.text = text
15
+ self.pronunciation = pronunciation
16
+ self.extra_data = extra_data
17
+
18
+ def __str__(self): # pragma: nocover
19
+ return self.__unicode__()
20
+
21
+ def __unicode__(self): # pragma: nocover
22
+ return (
23
+ u'Translated(src={src}, dest={dest}, text={text}, pronunciation={pronunciation}, '
24
+ u'extra_data={extra_data})'.format(
25
+ src=self.src, dest=self.dest, text=self.text,
26
+ pronunciation=self.pronunciation,
27
+ extra_data='"' + repr(self.extra_data)[:10] + '..."'
28
+ )
29
+ )
30
+
31
+
32
+ class Detected:
33
+ """Language detection result object
34
+
35
+ :param lang: detected language
36
+ :param confidence: the confidence of detection result (0.00 to 1.00)
37
+ """
38
+ def __init__(self, lang, confidence):
39
+ self.lang = lang
40
+ self.confidence = confidence
41
+
42
+ def __str__(self): # pragma: nocover
43
+ return self.__unicode__()
44
+
45
+ def __unicode__(self): # pragma: nocover
46
+ return u'Detected(lang={lang}, confidence={confidence})'.format(
47
+ lang=self.lang, confidence=self.confidence)