Exemplo n.º 1
0
 def toTranslateBox(self):
     if self.ui.toTranslateBox.currentIndex() == 0:
         self.destLanguage = 'en'  #default destination language is English
         self.ui.toTranslateBox.setCurrentText("English")
         return
     else:
         lang = self.ui.toTranslateBox.currentText().lower()
         # print('to', lang)
         self.destLanguage = LANGCODES.get(lang, None)
 def _changSettings():
     lang = event.message.text[4:]
     dest = LANGCODES.get(lang)
     user_lang_modified = _changeUserTranslationDest(user_profile,
                                                     dest=dest)
     print(
         "Translated destination language is successfully changed to: %s" %
         user_lang_modified.get("dest"))
     return user_lang_modified
Exemplo n.º 3
0
def specify(s):
    return LANGCODES.get(redirs.get(s, s), redirs.get(s, s))
Exemplo n.º 4
0
 def fromTranslateBox(self):
     if self.ui.fromTranslateBox.currentIndex() == 0:
         self.srcLanguage = 'auto'  #let google(translation service) determine the source language
     else:
         lang = self.ui.fromTranslateBox.currentText().lower()
         self.srcLanguage = LANGCODES.get(lang, None)
Exemplo n.º 5
0
def main():
    st.sidebar.write('StanzaGraphs ')
    mes = '''
  a Multilingual STANZA-based Summary and Keyword Extractor and Question-Answering System using TextGraphs and Neural Networks
  '''

    st.sidebar.write(mes)
    langList = ['', 'Auto detect']
    langList += list(LANGCODES.keys())
    langFull = st.sidebar.selectbox('Translate to?', langList)
    if langFull != "Auto detect":
        lang = LANGCODES.get(langFull)
    else:
        lang = langFull
    st.write('Selected language: ', langFull)

    uploaded_file = st.sidebar.file_uploader('Select a File',
                                             type=['txt', 'pdf'])
    title = None
    action = None

    if uploaded_file is not None:
        fpath = save_uploaded_file(uploaded_file)
        if fpath[-4:] == '.pdf':
            pdf2txt(fpath[:-4])
        text = file2text(fpath[:-4] + '.txt')

        data_lang = langid.classify(text)[0]
        if data_lang == 'zh':
            data_lang = 'zh-cn'
        elif data_lang == 'jv':
            data_lang = 'jw'
        data_fulllang = LANGUAGES.get(data_lang)
        st.sidebar.write('Language:', data_fulllang)

        fname = fpath[:-4]
        print("fname: ")
        print(fname)

        if not title or title != uploaded_file.name:
            title = uploaded_file.name
            action = st.sidebar.selectbox("Choose an action",
                                          ["Summarize", "Ask a question"])
            if action == "Summarize":
                proceed = st.sidebar.button('Run with selected option!')
                if proceed:
                    if langFull == "Auto detect":
                        st.write('Translate summary from ', fname, 'to ',
                                 data_fulllang)
                    else:
                        st.write('Translate summary from ', fname, 'to ',
                                 langFull)
                    summary(fname=fname, lang=lang)
                    pass
            elif action == "Ask a question":
                st.write('Query Answering')
                question = st.text_input('Input your question here:')
                if question:
                    st.write('Answers:')
                    answer(fname, question, lang)
        else:
            st.info("Please select a text file to upload")
Exemplo n.º 6
0
from googletrans import Translator as BaseTranslator
from googletrans.client import Translated
from utils.formatters import BetterEmbed

if TYPE_CHECKING:
    from asyncio import AbstractEventLoop

    from aiohttp import ClientSession


# outside of the class to use it as a converter
def to_language(arg: str) -> Union[str, None]:
    """Converts a string into a valid google trans language"""
    if (low := arg.lower()) in LANGUAGES:
        return low
    elif res := LANGCODES.get(low):
        return res
    raise BadArgument(message=f"Couldn't find the language {arg}")


def check_length(arg: str) -> str:
    """Checks the initial text and returns it"""
    if len(arg) > 200:
        raise BadArgument(message="Cannot translate texts longer than 200 characters")
    return arg


class AioTranslator(BaseTranslator):
    """Translates stuff using google translate's api"""

    def __init__(self, *args, **kwargs):