Exemplo n.º 1
0
 def test_mix_english_with_greek(self):
     sentence = u"English is the main language but let me show my GREEK: Καλημέρα σας! 59310"
     # English is the main language
     output = brl.translate(sentence, main_language="english")
     actual_output = [[
         '000001', '100010', '101110', '110110', '111000', '010100',
         '100101'
     ], ['010100', '011100'], ['011101'], ['101100', '100000', '001010'],
                      [
                          '111000', '100000', '101110', '110110', '101001',
                          '100000', '110110', '100010'
                      ], ['110000'], ['111000', '100010', '011110'],
                      ['101100', '100010'], ['100101', '010101'],
                      ['101100', '101111'],
                      [
                          '000001', '000001', '110110', '111010', '100010',
                          '100010', '101000'
                      ],
                      [
                          '000010', '000001', '101000', '100000', '111000',
                          '001110', '101100', '000010', '000101', '111010',
                          '100000'
                      ], ['000010', '011100', '100000'],
                      [
                          '001111', '010001', '001010', '010010', '010000',
                          '001011'
                      ]]
     # ⠠⠑⠝⠛⠇⠊⠩ ⠊⠎ ⠮ ⠍⠁⠔ ⠇⠁⠝⠛⠥⠁⠛⠑ ⠃ ⠇⠑⠞ ⠍⠑ ⠩⠪ ⠍⠽ ⠠⠠⠛⠗⠑⠑⠅ ⠐⠠⠅⠁⠇⠜⠍⠐⠨⠗⠁ ⠐⠎⠁ ⠼⠢⠔⠒⠂⠴
     self.assertEqual(output, actual_output)
Exemplo n.º 2
0
 def test_greek_main_translation(self):
     sentence = u"Τεστ 3,5 σουβλακι"
     # Greek is the main language
     output = brl.translate(sentence, main_language="greek")
     actual_output = [['000101', '011110', '100010', '011100', '011110'],
                      ['001111', '010010', '010001'],
                      [
                          '011100', '101001', '110000', '111000', '100000',
                          '101000', '010100'
                      ]]
     # ⠨⠞⠑⠎⠞ ⠼⠒⠢ ⠎⠥⠃⠇⠁⠅⠊
     self.assertEqual(output, actual_output)
Exemplo n.º 3
0
 def test_english_translation(self):
     sentence = "Hello WORLD 123"
     output = brl.translate(sentence, main_language="english")
     actual_output = [[
         '000001', '110010', '100010', '111000', '111000', '101010'
     ],
                      [
                          '000001', '000001', '010111', '101010', '111010',
                          '111000', '100110'
                      ], ['001111', '010000', '011000', '010010']]
     # ⠠⠓⠑⠇⠇⠕ ⠠⠠⠺⠕⠗⠇⠙ ⠼⠂⠆⠒
     self.assertEqual(output, actual_output)
Exemplo n.º 4
0
 def test_greek_foreign_translation(self):
     sentence = u"Τεστ 3,5 σουβλακι"
     # English is the main language
     output = brl.translate(sentence, main_language="english")
     actual_output = [[
         '000010', '000001', '011110', '100010', '011100', '011110'
     ], ['001111', '010010', '010001'],
                      [
                          '000010', '011100', '101001', '110000', '111000',
                          '100000', '101000', '010100'
                      ]]
     # ⠐⠠⠞⠑⠎⠞ ⠼⠒⠢ ⠐⠎⠥⠃⠇⠁⠅⠊
     self.assertEqual(output, actual_output)
Exemplo n.º 5
0
 def test_mix_english_with_greek(self):
     sentence = u"Η κύρια γλώσσα είναι τα Ελληνικά. ΑΓΓΛΙΚΆ: Foo bar 59310"
     # Greek is the main language
     output = brl.translate(sentence, main_language="greek")
     actual_output = [
         ['000101', '001110'],
         ['101000', '000010', '000101', '111010', '010100', '100000'],
         [
             '110110', '111000', '000010', '000100', '011100', '011100',
             '100000'
         ], ['000010', '000101', '101110', '110001'], ['011110', '100000'],
         [
             '000101', '100010', '111000', '111000', '001110', '101110',
             '010100', '101000', '000010', '000101'
         ],
         [
             '000101', '000101', '100000', '110110', '110110', '111000',
             '010100', '101000', '000010', '000101'
         ], ['000011', '000001', '110100', '101010', '101010'],
         ['000011', '110000', '001110'],
         ['001111', '010001', '001010', '010010', '010000', '001011']
     ]
     # ⠨⠜ ⠅⠐⠨⠗⠊⠁ ⠛⠇⠐⠈⠎⠎⠁ ⠐⠨⠝⠣ ⠞⠁ ⠨⠑⠇⠇⠜⠝⠊⠅⠐⠨ ⠨⠨⠁⠛⠛⠇⠊⠅⠐⠨ ⠰⠠⠋⠕⠕ ⠰⠃⠜ ⠼⠢⠔⠒⠂⠴
     self.assertEqual(output, actual_output)
Exemplo n.º 6
0
 def mytext(self):
     cursor = self.textEdit.textCursor()
     textSelected = cursor.selectedText()
     example=brl.translate(textSelected)
     s = brl.toUnicodeSymbols(example, flatten=True)
     cursor.insertText(s)
Exemplo n.º 7
0
def convert(argv):
    def usage():
        print(
            'usage: %s [-d] [-p pagenos] [-m maxpages] [-P password] [-o output]'
            ' [-C] [-n] [-A] [-V] [-M char_margin] [-L line_margin] [-W word_margin]'
            ' [-F boxes_flow] [-Y layout_mode] [-O output_dir] [-R rotation]'
            ' [-t text|html|xml|tag] [-c codec] [-s scale]'
            ' file ...' % argv[0])
        return 100

    try:
        (opts, args) = getopt.getopt(argv[1:],
                                     'dp:m:P:o:CnAVM:L:W:F:Y:O:R:t:c:s:')
    except getopt.GetoptError:
        return usage()
    if not args: return usage()
    # debug option
    debug = 0
    # input option
    password = ''
    pagenos = set()
    maxpages = 0
    # output option
    outfile = 'inputs/' + sys.argv[1].replace(' ', '')[:-4] + '.txt'
    outtype = None
    imagewriter = None
    rotation = 0
    layoutmode = 'normal'
    codec = 'utf-8'
    pageno = 1
    scale = 1
    caching = True
    showpageno = True
    laparams = LAParams()
    for (k, v) in opts:
        if k == '-d': debug += 1
        elif k == '-p': pagenos.update(int(x) - 1 for x in v.split(','))
        elif k == '-m': maxpages = int(v)
        elif k == '-P': password = v
        elif k == '-o': outfile = v
        elif k == '-C': caching = False
        elif k == '-n': laparams = None
        elif k == '-A': laparams.all_texts = True
        elif k == '-V': laparams.detect_vertical = True
        elif k == '-M': laparams.char_margin = float(v)
        elif k == '-L': laparams.line_margin = float(v)
        elif k == '-W': laparams.word_margin = float(v)
        elif k == '-F': laparams.boxes_flow = float(v)
        elif k == '-Y': layoutmode = v
        elif k == '-O': imagewriter = ImageWriter(v)
        elif k == '-R': rotation = int(v)
        elif k == '-t': outtype = v
        elif k == '-c': codec = v
        elif k == '-s': scale = float(v)
    #
    PDFDocument.debug = debug
    PDFParser.debug = debug
    CMapDB.debug = debug
    PDFResourceManager.debug = debug
    PDFPageInterpreter.debug = debug
    PDFDevice.debug = debug
    #
    rsrcmgr = PDFResourceManager(caching=caching)
    if not outtype:
        outtype = 'text'
        if outfile:
            if outfile.endswith('.htm') or outfile.endswith('.html'):
                outtype = 'html'
            elif outfile.endswith('.xml'):
                outtype = 'xml'
            elif outfile.endswith('.tag'):
                outtype = 'tag'
    if outfile:
        outfp = file(outfile, 'w')
    else:
        outfp = sys.stdout
    if outtype == 'text':
        device = TextConverter(rsrcmgr,
                               outfp,
                               codec=codec,
                               laparams=laparams,
                               imagewriter=imagewriter)
    elif outtype == 'xml':
        device = XMLConverter(rsrcmgr,
                              outfp,
                              codec=codec,
                              laparams=laparams,
                              imagewriter=imagewriter)
    elif outtype == 'html':
        device = HTMLConverter(rsrcmgr,
                               outfp,
                               codec=codec,
                               scale=scale,
                               layoutmode=layoutmode,
                               laparams=laparams,
                               imagewriter=imagewriter)
    elif outtype == 'tag':
        device = TagExtractor(rsrcmgr, outfp, codec=codec)
    else:
        return usage()
    for fname in args:
        fp = file('pdfs/' + fname, 'rb')
        interpreter = PDFPageInterpreter(rsrcmgr, device)
        for page in PDFPage.get_pages(fp,
                                      pagenos,
                                      maxpages=maxpages,
                                      password=password,
                                      caching=caching,
                                      check_extractable=True):
            page.rotate = (page.rotate + rotation) % 360
            interpreter.process_page(page)
        fp.close()
    device.close()
    outfp.close()

    #read converted file
    y = open("inputs/" + sys.argv[1].replace(' ', '')[:-4] + '.txt', "r")
    output = brl.translate(y.read())
    #convert into Grade 2 Braille unicode
    x = brl.toUnicodeSymbols(output, flatten=True)
    #save to results folder in .txt format
    text_file = open(
        "results/" + sys.argv[1].replace(' ', '')[:-4] + "-Braille.txt", "w")
    text_file.write(x.encode(codec))
    text_file.close()