Ejemplo n.º 1
0
def translate(config_path, input_path, output_path):
    print('Loading config ... ', end='', flush=True)
    with open(config_path, 'r') as f:
        config = json.load(f)
    print('done !')

    dic = Dic()
    dic.read_dict(config['dic'], config['word'], True)

    translater = Translater(dic, config['model'])
    if input_path == '':
        translater.shell()
    else:
        translater.translate_file(input_path, output_path)
    return
Ejemplo n.º 2
0
def train(config_path):
    jieba.initialize()  # init jieba
    print('Loading training config ... ', end='', flush=True)
    with open(config_path, 'r') as f:
        config = json.load(f)
    print('done !')

    dic = Dic()
    dic.read_dict(config['dic'], config['word'])

    trainer = Trainer(dic)
    # trainer.feed(config['word'], True)
    for data in config['data']:
        trainer.feed(data)
    trainer.build()
    trainer.write_into_file(config['model'])
Ejemplo n.º 3
0
    def run(self, window):
        self.window = window
        frame = self.view(window, back_button=True)

        vbox = gui.Box(frame, axis=1, expand=True)
        self.question_text = tichy.Text("Question")
        self.question_text.view(vbox, expand=True, font_size=58)

        self.choices = tichy.List()
        self.choices.view(vbox, expand=True)

        frame.connect('back', self.on_quit)

        dic = codecs.open(Learn.path('characters.dic'), encoding='utf-8')

        logger.info("opening the dict")
        # dic = open(Learn.path('characters.dic'), 'r')
        dic = Dic.read(dic)
        self.full_dic = dic[:]
        brain = Brain()

        logger.info("start game")
        self.task = None
        while True:
            self.task = brain.ask(self.ask, dic)
            try:
                yield self.task
            except GeneratorExit:
                break
Ejemplo n.º 4
0
def main(args):
    stats = Stats()
    transactions = TransactionsList(args.infile)
    if args.algorithm == 'apriori':
        algorithm = Apriori(transactions, args.minsup)
    else:
        algorithm = Dic(transactions, args.minsup, args.m)
    large_sets, counter = algorithm.get_large_sets_and_counter()
    stats.record_post_large_sets()
    rules = RulesGenerator.generate_rules(large_sets, args.minconf, counter, transactions)
    stats.record_post_rules()

    writer = Writer(args.outfile)
    writer.add_args(args)
    writer.add_stats(stats)
    writer.add_rules(rules)
    writer.write()
Ejemplo n.º 5
0
 def __init__(self):
     Dic.__init__(self)
     self.space = 10
     self.peradd = 5
     self.datas = np.array([], dtype=np.uint16)
     self.datas = np.resize(self.datas, self.space)
Ejemplo n.º 6
0
    def size(self):
        return self.list.size()

    def getDatas(self):
        return self.list.datas

    def show(self):
        self.list.show()

    def __getitem__(self, i):
        return self.list.datas[i]

    def __str__(self):
        return str(self.list)

if __name__ == '__main__':
    from dic import Dic
    dic = Dic()
    li = range(1, 20)
    for i in li:
        dic.add(i)
    dic.done()
    dic.show()
    datas = Datas()
    datas.setDic(dic)
    f = [1, 1, 5, 3]
    print 'f:', f
    datas.addFeatures(f)
    datas.show()