-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
60 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from arekit.common.entities.base import Entity | ||
|
||
|
||
class IndexedEntity(Entity): | ||
""" Same as the base Entity but supports indexing. | ||
""" | ||
|
||
def __init__(self, value, e_type, entity_id): | ||
super(IndexedEntity, self).__init__(value=value, e_type=e_type) | ||
self.__id = entity_id | ||
|
||
@property | ||
def ID(self): | ||
return self.__id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This implementation has been tested for | ||
# googletrans==3.1.0a0 | ||
|
||
|
||
import time | ||
|
||
from googletrans import Translator | ||
|
||
|
||
class GoogleTranslateModel(object): | ||
|
||
def __init__(self, **kwargs): | ||
self._instance = Translator() | ||
|
||
@staticmethod | ||
def translate_value(translator, value, src, dest, sec_delay=1, attempts=10): | ||
|
||
import logging | ||
logger = logging.getLogger() # get the default logger | ||
logger.setLevel(50) | ||
|
||
for i in range(attempts): | ||
try: | ||
translated = translator.translate(value, dest=dest, src=src) | ||
return translated.text | ||
except: | ||
logger.info("Unable to perform translation. Try {} out of {}.".format(i, attempts)) | ||
time.sleep(sec_delay) | ||
|
||
raise Exception("Can't translate") | ||
|
||
def get_func(self, src, dest, **kwargs): | ||
# We do auto-import so we not depend on the actually installed library. | ||
# Translation of the list of data. | ||
# Returns the list of strings. | ||
return lambda str_list: [ | ||
GoogleTranslateModel.translate_value(translator=self._instance, value=s, dest=dest, src=src) | ||
for s in str_list] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.