Example #1
0
    def expression2simptrad(self, expression):
        result = {}
        for charmode, glangcode in [("simp", "zh-CN"), ("trad", "zh-TW")]:
            # Query Google for the conversion, returned in the format: ["社會",[["noun","社會","社會","社會"]]]
            log.info("Doing conversion of %s into %s characters", expression, charmode)
            meanings = dictionaryonline.gTrans(expression, glangcode, False)

            if meanings is None or len(meanings) == 0:
                # No conversion, so give up and return the input expression
                result[charmode] = expression
            else:
                # Conversion is stored in the first 'meaning'
                result[charmode] = model.flatten(meanings[0])
        
        return result
Example #2
0
    def expression2simptrad(self, expression):
        result = {}
        for charmode, glangcode in [("simp", "zh-CN"), ("trad", "zh-TW")]:
            # Query Google for the conversion, returned in the format: ["社會",[["noun","社會","社會","社會"]]]
            log.info("Doing conversion of %s into %s characters", expression, charmode)
            meanings = dictionaryonline.gTrans(expression, glangcode, False)

            if meanings is None or len(meanings) == 0:
                # No conversion, so give up and return the input expression
                result[charmode] = expression
            else:
                # Conversion is stored in the first 'meaning'
                result[charmode] = model.flatten(meanings[0])
        
        return result
Example #3
0
    def generateincharactersystem(self, expression, charmode):
        log.info("Doing conversion of %s into %s characters", expression, charmode)

        # Query Google for the conversion, returned in the format: ["社會",[["noun","社會","社會","社會"]]]
        if charmode=="simp":
            glangcode="zh-CN"
        else:
            glangcode="zh-TW"
        meanings = dictionaryonline.gTrans(expression, glangcode, False)
        
        if meanings == None or len(meanings) == 0:
            # No conversion, so give up and return the input expression
            return expression
        else:
            # Conversion is stored in the first 'meaning'
            return model.flatten(meanings[0])
Example #4
0
    def generateincharactersystem(self, expression, charmode):
        log.info("Doing conversion of %s into %s characters", expression,
                 charmode)

        # Query Google for the conversion, returned in the format: ["社會",[["noun","社會","社會","社會"]]]
        if charmode == "simp":
            glangcode = "zh-CN"
        else:
            glangcode = "zh-TW"
        meanings = dictionaryonline.gTrans(expression, glangcode, False)

        if meanings == None or len(meanings) == 0:
            # No conversion, so give up and return the input expression
            return expression
        else:
            # Conversion is stored in the first 'meaning'
            return model.flatten(meanings[0])
Example #5
0
def preparetokens(config, tokens):
    if config.colorizedpinyingeneration:
        tokens = transformations.colorize(config.tonecolors, tokens)

    return model.flatten(tokens, tonify=config.shouldtonify)
Example #6
0
 def generatecoloredcharacters(self, expression):
     return model.flatten(transformations.colorize(self.config.tonecolors, transformations.tonesandhi(self.dictionary.tonedchars(expression))))
Example #7
0
 def expressiondictreading2color(self, expression, dictreading):
     return model.flatten(transformations.colorize(self.config.tonecolors, model.tonedcharactersfromreading(expression, dictreading)))
Example #8
0
 def generatecoloredcharacters(self, expression):
     return model.flatten(
         transformations.colorize(
             self.config.tonecolors,
             transformations.tonesandhi(
                 self.dictionary.tonedchars(expression))))
Example #9
0
def preparetokens(config, tokens):
    if config.colorizedpinyingeneration:
        tokens = transformations.colorize(config.tonecolors, tokens)

    return model.flatten(tokens, tonify=config.shouldtonify)
Example #10
0
 def expressiondictreading2color(self, expression, dictreading):
     return model.flatten(transformations.colorize(self.config.tonecolors, model.tonedcharactersfromreading(expression, dictreading)))
Example #11
0
y_true_cls = tf.argmax(y_true, dimension=1)

j = model.multi_layer_cnn(
    inp=x,
    no_cnn_layer=10,
    channel=3,
    filter_size=3,
    filter_no_list=[32, 64, 128, 64, 128, 256, 512, 1024, 512, 256],
    stride_size=2,
    pool_size=2,
    pstride_size=2)

for key, value in j.items():
    globals()[key] = value

flat_layer = model.flatten(globals()[key])

y = model.multi_layer_dnn(flat_layer, 4, [128, 256, 512, 256])

for key, value in y.items():
    globals()[key] = value

#final = globals()[key]

final = model.final_layer(
    globals()[key],
    num_inputs=globals()[key].get_shape()[1:4].num_elements(),
    num_outputs=6,
    use_relu=False)

ses = model.predict(final,