Exemplo n.º 1
0
 def search(self):
     f = '[WordGuesser] guesser.logic.Guesser.search'
     if self.Success:
         if self.word:
             timer = sh.Timer(func_title=f)
             timer.start()
             lst = [word for word in self.lst \
                    if len(word) == len(self.word)
                   ]
             timer.end()
             words = []
             for item in lst:
                 Match = True
                 items = list(item)
                 for i in range(len(self.word)):
                     if self.word[i] != '?':
                         if self.word[i] != items[i]:
                             Match = False
                             break
                 if Match:
                     words.append(item)
             return words
         else:
             sh.com.rep_empty(f)
     else:
         sh.com.cancel(f)
Exemplo n.º 2
0
 def delete_tags(self):
     f = '[Samurai] samurai.Parse.delete_tags'
     timer = sh.Timer(f) #TODO: del
     timer.start()       #TODO: del
     if self.text:
         try:
             self.soup = bs.BeautifulSoup(self.text,'html.parser')
             for script in self.soup.find_all('script'): #,src=False
                 script.decompose()
             self.text = self.soup.get_text()
             #self.text = lxml.html.fromstring(self.text).text_content()
             """
             '''
             import re
             self.text = re.sub('<.*?>','',self.text)
             #from xml.etree.ElementTree import ElementTree
             #self.text = ''.join(xml.etree.ElementTree.fromstring(self.text).itertext())
             '''
             """
             self.text = html.unescape(self.text)
         except Exception as e:
             mes = _('The operation has failed!\n\nDetails: {}')
             mes = mes.format(e)
             sh.objs.get_mes(f,mes,True).show_error()
     else:
         sh.com.rep_empty(f)
     timer.end() #TODO: del
Exemplo n.º 3
0
 def translate(self, pattern):
     f = '[MClient] plugins.multitrandem.tests.Tests.translate'
     timer = sh.Timer(f)
     timer.start()
     result = gt.Get(pattern).run()
     sh.objs.get_mes(f, result, True).show_debug()
     timer.end()
     return result
Exemplo n.º 4
0
 def suggest(self):
     #pattern = 'acid'
     pattern = 'кислот'
     com.swap_langs()
     timer = sh.Timer()
     timer.start()
     gt.objs.get_files().get_typein1().search(pattern)
     timer.end()
Exemplo n.º 5
0
 def run_stardict(self):
     f = '[MClient] tests.Get.run_stardict'
     import logic as lg
     import plugins.stardict.get as sd
     #search = 'компьютер'
     search = 'computer'
     timer = sh.Timer(f)
     timer.start()
     result = sd.Get(search).run()
     timer.end()
     sh.com.run_fast_txt(result)
Exemplo n.º 6
0
 def run_multitrancom(self):
     f = '[MClient] tests.Get.run_multitrancom'
     import plugins.multitrancom.get as gt
     #url = 'https://www.multitran.com/m.exe?a=3&sc=8&s=%D1%81%D0%B8%D0%BC%D0%BF%D1%82%D0%BE%D0%BC&l1=2&l2=1&SHL=2'
     #search = 'Медицина'
     url = 'https://www.multitran.com/m.exe?s=working%20documentation&l1=1&l2=2&SHL=2'
     search = 'working documentation'
     timer = sh.Timer(f)
     timer.start()
     result = gt.Get(search=search, url=url).run()
     timer.end()
     sh.com.run_fast_txt(result)
Exemplo n.º 7
0
 def run(self):
     f = '[CompressMedia] compress.Converter.run'
     self.itimer = sh.Timer(f)
     self.itimer.start()
     self.check()
     self.get_files()
     self.set_date()
     self.get_useful()
     self.set_target()
     self.skip_existing()
     self.create_folders()
     self.convert()
     self.report()
Exemplo n.º 8
0
 def add_tabs(self):
     f = '[Samurai] samurai.Parse.add_tabs'
     timer = sh.Timer(f) #TODO: del
     timer.start()       #TODO: del
     lst = list(self.text)
     i = len(lst) - 1
     while i >= 0:
         if lst[i] == '\n' and not i in self.breaks:
             if i + 1 < len(lst):
                 # 'isspace' will be 0,16s slower than ' '
                 if lst[i+1] != '\n' and not lst[i+1] == ' ':
                     lst.insert(i+1,self.tab)
         i -= 1
     self.text = ''.join(lst)
     timer.end() #TODO: del
Exemplo n.º 9
0
 def reinsert_same(self):
     f = '[MClient] tests.Plugin.reinsert_same'
     import plugins.multitrancom.run as mc
     search = 'set'
     url = 'https://www.multitran.com/m.exe?l1=1&l2=2&s=set'
     timer = sh.Timer('Getting elems')
     timer.start()
     blocks = mc.Plugin().request(url=url, search=search)
     timer.end()
     same = [block for block in blocks if block.same == 1]
     separate = [block for block in blocks if block.same == 0]
     # takes ~1s for 'set' (EN-RU) on AMD E-300
     timer = sh.Timer(f)
     timer.start()
     cells = []
     for block in separate:
         cell = [block]
         for item in same:
             if item.cellno == block.cellno:
                 cell.append(item)
         cells.append(cell)
     timer.end()
     print('Number of blocks:', len(blocks))
     print('Number of cells:', len(cells))
Exemplo n.º 10
0
 def translate_many(self):
     f = '[MClient] plugins.multitrandem.tests.Tests.translate_many'
     ''' MISSING IN MT DEMO:
         'преобразование случайной величины X, имеющей асимметричное распределение, в нормально распределённую величину Z'
     '''
     timer = sh.Timer()
     timer.start()
     sh.STOP_MES = True
     en_patterns = [
         'A & E', 'a posteriori', 'abasin', 'abatement of purchase price',
         'abatement of tax', 'abbrmate', 'absolute measurements',
         'acceleration measured in G', 'acceleration spectral density',
         'ashlar line', 'baby fish', 'Bachelor of Vocational Education',
         'calcium gallium germanium garnet', 'daily reports notice',
         'deaf as an adder', 'eristic', 'habitable room',
         'he has not a sou', 'Kapteyn transformation', 'law and equity',
         'loadable system', 'palletbox', 'sack duty', 'work',
         'World Union of Catholic Teachers', 'Zebra time'
     ]
     ru_patterns = [
         'абонентское устройство для совместной передачи речи и данных',
         'абсолютный способ измерения',
         'Всемирный союз преподавателей-католиков',
         'курс занятий для студентов последнего курса',
         'с большой точностью', 'уборка', 'у него нет ни гроша',
         'ячейка решётки', 'ящичный поддон'
     ]
     failed = 0
     total = len(en_patterns) + len(ru_patterns)
     for pattern in en_patterns:
         if not self.translate(pattern):
             failed += 1
     com.swap_langs()
     for pattern in ru_patterns:
         if not self.translate(pattern):
             failed += 1
     sh.STOP_MES = False
     timer.end()
     messages = []
     mes = _('Total: {}').format(total)
     messages.append(mes)
     mes = _('Successful: {}').format(total - failed)
     messages.append(mes)
     mes = _('Failed: {}').format(failed)
     messages.append(mes)
     mes = '\n' + '\n'.join(messages)
     sh.objs.get_mes(f, mes, True).show_debug()
Exemplo n.º 11
0
 def load(self):
     f = '[WordGuesser] guesser.logic.Guesser.load'
     if self.Success:
         if not self.lst:
             timer = sh.Timer(f)
             timer.start()
             iread = sh.ReadTextFile(self.file)
             text = iread.get()
             self.Success = iread.Success
             if self.Success:
                 text = text.lower()
                 text = text.strip()
                 self.lst = text.splitlines()
             timer.end()
         return self.lst
     else:
         sh.com.cancel(f)
Exemplo n.º 12
0
 def sort(self):
     f = '[CompressMedia] tests.Compression.sort'
     if self.Success:
         timer = sh.Timer(f)
         timer.start()
         rates = [ifile.compression for ifile in self.ifiles]
         rates.sort(reverse=True)
         ifiles = []
         for rate in rates:
             for ifile in self.ifiles:
                 if ifile.compression == rate:
                     ifiles.append(copy.copy(ifile))
                     self.ifiles.remove(ifile)
                     break
         self.ifiles = ifiles
         timer.end()
     else:
         sh.com.cancel(f)
Exemplo n.º 13
0
 def pretty(self):
     f = '[Samurai] samurai.Parse.pretty'
     timer = sh.Timer(f) #TODO: del
     timer.start()       #TODO: del
     if self.text:
         text = sh.Text(text=self.text)
         text.convert_line_breaks()
         text.strip_lines()
         text.tabs2spaces()
         text.replace_x()
         text.delete_duplicate_spaces()
         self.text = text.text
         # Allow only 2 consequent line breaks
         while '\n\n\n' in self.text:
             self.text = self.text.replace('\n\n\n','\n\n')
     else:
         sh.com.rep_empty(f)
     timer.end() #TODO: del
Exemplo n.º 14
0
    def searchu_stems(self):
        f = '[MClient] plugins.multitrandem.tests.Tests.searchu_stems'
        timer = sh.Timer(f)
        timer.start()
        #pattern = b'wol'
        #pattern = b'zero'
        #pattern = b'wi'
        #pattern = b'wifi'
        #pattern = b'willing'
        #pattern = b'vh'
        #pattern = b'ace'
        #pattern = b'a'
        #pattern = b'algorithm'
        #pattern = b'wol'
        #pattern = b'acf'
        #pattern = b'volume'
        pattern = b'abatement'

        upage = UPage(gt.objs.get_files().iwalker.get_stems1())
        upage.searchu(pattern)
        print('---------------------------------------------------')
        #pattern = 'уборка'
        #pattern = 'эт'
        #pattern = 'аж'
        #pattern = 'ажиотаж'
        #pattern = 'аккордеон'
        #pattern = 'ан'
        #pattern = 'анорексия'
        #pattern = 'ас'
        #pattern = 'асс'
        #pattern = 'язык'
        #pattern = 'этот'
        #pattern = 'железобетонный принцип'
        #pattern = 'з'
        #pattern = 'задеть'
        #pattern = 'зашуганный'
        pattern = 'звезда'
        pattern = bytes(pattern, gt.CODING)
        com.swap_langs()
        # Since we swap languages, the needed stems will always be #1
        upage = UPage(gt.objs.get_files().iwalker.get_stems1())
        upage.searchu(pattern)
        timer.end()
Exemplo n.º 15
0
 def get(self):
     f = '[MClient] plugins.stardict.get.Suggest.get'
     if self.Success:
         items = objs.get_all_dics().get_index()
         if items:
             timer = sh.Timer(f)
             timer.start()
             search = self.pattern.lower()
             result = [item for item in items \
                       if str(item).lower().startswith(search)
                      ]
             timer.end()
             mes = '; '.join(result)
             sh.objs.get_mes(f, mes, True).show_debug()
             return result
         else:
             self.Success = False
             sh.com.rep_empty(f)
     else:
         sh.com.cancel(f)
Exemplo n.º 16
0
 def wrap(self):
     f = '[Samurai] samurai.Parse.wrap'
     timer = sh.Timer(f) #TODO: del
     timer.start()       #TODO: del
     if self.width:
         lst = list(self.text)
         count = 0
         i = 0
         space_i = 0
         while i < len(lst):
             if lst[i] == ' ':
                 space_i = i
             if lst[i] == '\n':
                 count = -1
             if count == self.width:
                 lst[space_i] = '\n'
                 self.breaks.append(space_i)
                 count = i - space_i
             i += 1
             count += 1
         self.text = ''.join(lst)
     else:
         sh.com.rep_empty(f)
     timer.end() #TODO: del
Exemplo n.º 17
0
 def load(self):
     f = '[MClient] plugins.stardict.get.AllDics.load'
     if self.Success:
         if self.locate():
             objs.get_progress().show()
             timer = sh.Timer(f)
             timer.start()
             for i in range(len(self.dics)):
                 text = _('Load Stardict dictionaries ({}/{})')
                 text = text.format(i + 1, len(self.dics))
                 objs.progress.set_text(text)
                 objs.progress.update(i, len(self.dics))
                 self.dics[i].load()
             timer.end()
             total_no = len(self.dics)
             self.dics = [dic for dic in self.dics if dic.Success]
             mes = _('Dictionaries loaded: {}/{}')
             mes = mes.format(len(self.dics), total_no)
             sh.objs.get_mes(f, mes, True).show_info()
             objs.progress.close()
         else:
             sh.com.rep_lazy(f)
     else:
         sh.com.cancel(f)
Exemplo n.º 18
0
        return self.lst

    def get_group(self, subject):
        return []

    def get_group_with_header(self, subject):
        return [subject]


class Objects:
    def __init__(self):
        self.subjects = None

    def get_subjects(self):
        if self.subjects is None:
            self.subjects = Subjects()
        return self.subjects


objs = Objects()

if __name__ == '__main__':
    f = '[MClient] plugins.dsl.subjects.__main__'
    sh.com.start()
    timer = sh.Timer(f)
    timer.start()
    mes = Subjects().get_group('Wood processing')
    sh.objs.get_mes(f, mes, True).show_debug()
    timer.end()
    sh.com.end()
Exemplo n.º 19
0
    
    def __init__(self,text):
        self.text = text
        
    def run(self):
        f = '[Samurai] samurai.Browse.run'
        if self.text:
            print(self.text)
        else:
            sh.com.rep_empty(f)


if __name__ == '__main__':
    f = '[Samurai] samurai.__main__'
    if sys.argv and len(sys.argv) > 1:
        timer = sh.Timer()
        timer.start()
        if sys.argv[1].startswith('http'):
            #url = 'https://youtube.com'
            #url = 'https://en.wikipedia.org/wiki/Bushido'
            if len(sys.argv) > 2:
                get = sh.Get (url = sys.argv[1]
                             ,encoding = sys.argv[2]
                             )
            else:
                get = sh.Get(url=sys.argv[1])
            get.run()
            parse = Parse(text=get.html)
            parse.delete_tags()
        else:
            text = sh.ReadTextFile(file=sys.argv[1]).get()