当前位置: 首页>>代码示例>>Python>>正文


Python Translator.translate方法代码示例

本文整理汇总了Python中Translator.Translator.translate方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.translate方法的具体用法?Python Translator.translate怎么用?Python Translator.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Translator.Translator的用法示例。


在下文中一共展示了Translator.translate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
 def run(self):
     '''
     invokes the config parser, generates the sql statements and runs optimizer 
     '''
     Parser=ConfigParser(self.filename)
     config=Parser.configContent
     translator=Translator(config)
     translator.translate()
     self.blocks=translator.getBlocks()
开发者ID:UWQuickstep,项目名称:Grail,代码行数:11,代码来源:Grail.py

示例2: translate

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
 def translate(self):
     glPushMatrix()
     Translator.translate(self)
     glTranslate(*-self._center)
     rs = self._rs = self.scale * self._modelScale
     glScale(rs, rs, rs)
     glRotate(self.rotX, 1, 0, 0)
     glRotate(self.rotY, 0, 1, 0)
     glRotate(self.rotZ, 0, 0, 1)
开发者ID:nbudin,项目名称:solidfuel,代码行数:11,代码来源:Model.py

示例3: run

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
 def run(self):
     '''
     invokes the config parser, generates the sql statements and runs optimizer 
     '''
     Parser=ConfigParser(self.filename)
     config=Parser.configContent
     translator=Translator(config)
     translator.translate()
     self.blocks=translator.getBlocks()
     op=Optimizer(translator.getConvertedOptions(),self.blocks,translator.getSenders())
     op.run()
开发者ID:njayaram2,项目名称:Grail,代码行数:13,代码来源:Grail.py

示例4: execute

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
    def execute(self):
        print('compile: ' + self.inName + ' to ' + self.outName)

        source = open(self.inName).read()
        t = Translator()
        t.translate(source)

        # for debug
        print t.getFuncList()
        print t.getAddrList()

        e = MakeElf(t)
        e.execute()

        f = open(self.outName, 'wb')
        #f.write(elf)
        f.write(text)
开发者ID:warabanshi,项目名称:binstudy,代码行数:19,代码来源:Compiler.py

示例5: Translator_test

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
class Translator_test(unittest.TestCase):

    def setUp(self):
        pattern_replacement = PatternReplacement('show switch (\d+)',
                                                 r'show slot \1')
        pattern_replacements = [pattern_replacement]
        self.tlr = Translator(pattern_replacements=pattern_replacements)

    def test_translate_shouldReturnNoHintOnEmptyConfigLine(self):
        configline = ''

        transl = self.tlr.translate(configline)

        self.assertEqual('', transl.get_hint())

    def test_translate_shouldReturnNoHintOnCommentedConfigLine(self):
        configline = '#'

        transl = self.tlr.translate(configline)

        self.assertEqual('', transl.get_hint())

    def test_translate_shouldReturnNoHintOnCommentedConfigLine2(self):
        configline = '!'

        transl = self.tlr.translate(configline)

        self.assertEqual('', transl.get_hint())

    def test_translate_shouldReturnXosConfigOnValidInput(self):
        configline = 'show switch 12'
        expected = 'show slot 12'

        transl = self.tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())

    def test_translate_shouldReturnEmptyHintOnValidInput(self):
        configline = 'show switch 1'
        expected = ''

        transl = self.tlr.translate(configline)

        self.assertEqual(expected, transl.get_hint())

    def test_translate_shouldIgnoreMultipleSpacesBetweenKeywords(self):
        configline = 'show    switch   1'
        expected = 'show slot 1'

        transl = self.tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())

    def test_translate_shouldAllowNewlineInReplacement(self):
        pattern_replacement = PatternReplacement('set timeout (\d+)',
                                                 r'configure timeout \1\n'
                                                 'enable timeout')
        tlr = Translator(pattern_replacements=[pattern_replacement])
        configline = 'set timeout 10'
        expected = 'configure timeout 10\nenable timeout'

        transl = tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())

    def test_translate_shouldAllowConstantsInPatternString(self):
        PATTERN_IPV4 = Translator.PATTERN_IPV4
        pattern = 'ip address (' + PATTERN_IPV4 + ') ' \
                                                  'mask (' + PATTERN_IPV4 + ')'
        pattern_replacement = PatternReplacement(pattern,
                                                 r'\1 \2')
        pattern_replacements = [pattern_replacement]
        tlr = Translator(pattern_replacements)
        configline = 'ip address 1.2.3.4 mask 255.255.255.0'
        expected = '1.2.3.4 255.255.255.0'

        transl = tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())

    def test_translate_shouldEmitEmptyStringIfNoHintInPatternReplacement(self):
        pattern = 'show (\d+)'
        configline = 'show 11'
        pattern_replacement = \
            PatternReplacement(pattern, r'show \1')
        tlr = Translator([pattern_replacement])

        transl = tlr.translate(configline)

        self.assertEqual(configline, transl.get_xos())
        self.assertEqual('', transl.get_hint())

    def test_translate_shouldEmitHintInPatternReplacement(self):
        pattern = 'show (\d+)'
        hint = 'silly hint'
        configline = 'show 11'
        pattern_replacement_and_hint = \
            PatternReplacement(pattern, r'show \1', 'silly hint')
        tlr = Translator([pattern_replacement_and_hint])

#.........这里部分代码省略.........
开发者ID:extremenetworks,项目名称:E2X,代码行数:103,代码来源:Translator_test.py

示例6: btn_clicked

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
 def btn_clicked(self, text, cbox, outBox):
     outBox.clear()
     lang = ''
     if cbox.currentIndex() is 0:
         lang = 'eng'
     elif cbox.currentIndex() is 1:
         lang = 'fr'
     trans = Translator(text, lang, self.dict)
     t_text = trans.translate()
     outBox.append(t_text)
开发者ID:kbroten14,项目名称:Picard,代码行数:12,代码来源:View.py

示例7: test_translate_shouldAllowNewlineInReplacement

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
    def test_translate_shouldAllowNewlineInReplacement(self):
        pattern_replacement = PatternReplacement('set timeout (\d+)',
                                                 r'configure timeout \1\n'
                                                 'enable timeout')
        tlr = Translator(pattern_replacements=[pattern_replacement])
        configline = 'set timeout 10'
        expected = 'configure timeout 10\nenable timeout'

        transl = tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())
开发者ID:extremenetworks,项目名称:E2X,代码行数:13,代码来源:Translator_test.py

示例8: test_translate_shouldEmitEmptyStringIfNoHintInPatternReplacement

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
    def test_translate_shouldEmitEmptyStringIfNoHintInPatternReplacement(self):
        pattern = 'show (\d+)'
        configline = 'show 11'
        pattern_replacement = \
            PatternReplacement(pattern, r'show \1')
        tlr = Translator([pattern_replacement])

        transl = tlr.translate(configline)

        self.assertEqual(configline, transl.get_xos())
        self.assertEqual('', transl.get_hint())
开发者ID:extremenetworks,项目名称:E2X,代码行数:13,代码来源:Translator_test.py

示例9: test_translate_shouldEmitHintInPatternReplacement

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
    def test_translate_shouldEmitHintInPatternReplacement(self):
        pattern = 'show (\d+)'
        hint = 'silly hint'
        configline = 'show 11'
        pattern_replacement_and_hint = \
            PatternReplacement(pattern, r'show \1', 'silly hint')
        tlr = Translator([pattern_replacement_and_hint])

        transl = tlr.translate(configline)

        self.assertEqual(configline, transl.get_xos())
        self.assertEqual(hint, transl.get_hint())
开发者ID:extremenetworks,项目名称:E2X,代码行数:14,代码来源:Translator_test.py

示例10: GlobalCloneBot

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
class GlobalCloneBot(CloneBot):
    def __init__(self, crawl_user, mecab=None, log_file='crawl.tsv', db_file='bigram.db'):
        super(GlobalCloneBot, self).__init__(crawl_user, mecab, log_file, db_file)
        self.translator = Translator(config.BING_APP_KEY, 'ja', 'en')

    def reply_hook(self, bot, status):
        """適当にリプライを返してあげる"""
        text = self.get_text()
        if status:
            bot.reply_to(text, status)
        else:
            bot.update_status(text)
            #時々英訳
            if random.random()<0.2:
                text = self.translator.translate(text)
                bot.update_status(u'[Translated] '+text)
                #時々再翻訳
                if random.random()<0.5:
                    text = self.translator.translate(text, 'en', 'ja')
                    bot.update_status(u'[再翻訳] ' + text)
        return True
开发者ID:jun-oya,项目名称:JO_RI_bot,代码行数:23,代码来源:JO_RI_bot.py

示例11: __init__

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
class VoiceRSSTTS:
	def __init__(self, desiredLanguage = "en-us"):
		self.desiredLanguage = desiredLanguage

		self.translator = Translator(VoiceRSSTTS.convertLangCodeForGoog(desiredLanguage))
		self.baseAPIURL = "http://api.voicerss.org/"

	def getAudioFileLink(self, stringToRead):
		stringToRead = self.translator.translate(stringToRead)

		#encode to utf-8
		stringToRead = stringToRead.encode(ENCODING)
		params = {"key" : VoiceRSSTTS.VOICE_RSS_TTS_API_KEY, "src" : stringToRead, "hl" : self.desiredLanguage}
		fullAPIURL = self.baseAPIURL + "?" + urllib.urlencode(params)

		return fullAPIURL

	@staticmethod
	def convertLangCodeForGoog(langCode):
		langCodeDict = {
		"en-us" : "en",
		"en-ca" : "en",
		"en-au" : "en",
		"en-gb" : "en",
		"en-in" : "en",
		"ca-es" : "ca",
		"zh-cn" : "zh-CN",
		"zh-hk" : "zh-TW",
		"zh-tw" : "zh-TW",
		"da-dk" : "da",
		"nl-nl" : "nl",
		"fi-fi" : "fi",
		"fr-ca" : "fr",
		"fr-fr" : "fr",
		"de-de" : "de",
		"it-it" : "it",
		"ja-jp" : "ja",
		"ko-kr" : "ko",
		"nb-no" : "no",
		"pl-pl" : "pl",
		"pt-br" : "pt",
		"pt-pt" : "pt",
		"ru-ru" : "ru",
		"es-mx" : "es",
		"es-es" : "es",
		"sv-se" : "sv"

		}

		return langCodeDict[langCode]
开发者ID:jjrob13,项目名称:ArticleReader,代码行数:52,代码来源:TextToSpeechClasses.py

示例12: test_translate_shouldAllowConstantsInPatternString

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
    def test_translate_shouldAllowConstantsInPatternString(self):
        PATTERN_IPV4 = Translator.PATTERN_IPV4
        pattern = 'ip address (' + PATTERN_IPV4 + ') ' \
                                                  'mask (' + PATTERN_IPV4 + ')'
        pattern_replacement = PatternReplacement(pattern,
                                                 r'\1 \2')
        pattern_replacements = [pattern_replacement]
        tlr = Translator(pattern_replacements)
        configline = 'ip address 1.2.3.4 mask 255.255.255.0'
        expected = '1.2.3.4 255.255.255.0'

        transl = tlr.translate(configline)

        self.assertEqual(expected, transl.get_xos())
开发者ID:extremenetworks,项目名称:E2X,代码行数:16,代码来源:Translator_test.py

示例13: translate

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
	def translate(self):
	    glPushMatrix()
		Translator.translate(self)
		glScale(self.zoom, self.zoom, self.zoom)
		glRotate(self.rot, 0, 0, 1)
开发者ID:nbudin,项目名称:solidfuel,代码行数:7,代码来源:RotoZoomer.py

示例14: print

# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import translate [as 别名]
        for name, R in relations.items():
            print('{}{}: {}'.format(indent, 'Name', name))
            print('{}{}: {}'.format(indent*2, 'Attributes', ', '.join(a for a in R.attributes)))
            print('{}{}: {}'.format(indent*2, 'Keys', repr_keys(R.keys)))
            print('{}{}: {}'.format(indent*2, 'Primary key', '(' + ', '.join(a for a in R.pkey) + ')'))
            if R.fkeys is not None:
                print('{}{}: {}'.format(indent*2, 'Fkeys', repr_keys(R.fkeys)))
            if R.refed_by is not None:
                print('{}{}: {}'.format(indent*2, 'Referenced by', ', '.join(str(r) for r in R.refed_by)))

    print 'done\n'

    # TRANSLATING part
    print 'Translating ... ',
    translator = Translator(relations.values())
    translator.translate()
    print 'done\n</h3>'

    if args.verbosity:
        print 'Intemediate output: '
        # find core relations
        core_relations = translator.core_relations
        print('Core relations: {}'.format(', '.join(c for c in core_relations)))
        print

        # find component relations
        comp_relations = translator.comp_relations
        print('Component relations: ')
        for cname, comps in comp_relations.items():
            print('{}{}: {}'.format(indent, cname, ', '.join(comp[0]+"({})".format(comp[1]) for comp in comps)))
        print
开发者ID:Lincolnnus,项目名称:RD-to-ERD,代码行数:33,代码来源:translate.py


注:本文中的Translator.Translator.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。