Beispiel #1
0
    def test_sanity_case(self):
        """transliterate() should give consistent results for round-trip transliterations"""

        for source in self.sanity_values:
            intermediate = xltrtr.transliterate(source)
            result = xltrtr.transliterate(xltrtr.format_text(intermediate))

            #print '%s = %s = %s' % (source, intermediate, result)
            self.assertEqual(source, xltrtr.format_text(result))
Beispiel #2
0
    def test_basic_case(self):
        """transliterate() should give known result with known input"""

        for source, to in self.basic_values:
            #print '%s = %s' % (source, to)
            result = xltrtr.transliterate(source)
            self.assertEqual(to, xltrtr.format_text(result))
Beispiel #3
0
    def tr(self, irc, msg, args, strings):
        """ <text>
        Transliterates strings. Supports Latin transcriptions to 
        Russian Cyrillic, Latin transcriptions to Inuktitut syllabics,
        and back into Latin. Intelligently chooses which language 
        to transliterate into (please report any bugs).
        Note that only one language will be detected best matching 
        the entire <text>. """

        import xltrtr

        query = strings.decode('utf-8')
        result = xltrtr.transliterate(query)
        irc.reply(result, prefixNick = False)
Beispiel #4
0
        # something is printed, at least in python 2.6.6 on my webhost.
        # So print the Content-Type header.
        # Do not print newline, so that the content-type can be changed
        # by printing a second header later. This is used to send HTML
        # from this same file.
        print 'Content-Type: application/json'

        args = cgi.FieldStorage()

        if 'query' in args and 'ajax' in args:
            print '\n' # newline to signal end of header field

            # print JSON output with all data
            # (scores for all combinations, sorted descending)
            query = args['query'].value.decode('utf-8')
            xl = xltrtr.transliterate(query)
            result = {'input': query, 'output': xl}
            print json.dumps(result)
        else:
            print 'Content-Type: text/html\n' # we'll be sending HTML instead

            f = open('web/frontend.html', 'r')
            html = f.read().decode('utf8')

            f = open('web/xltrtr.js', 'r')
            js = f.read()

            f = open('web/style.css', 'r')
            css = f.read()

            html = html.format(js = js, css = css)