function learn(&$ret, &$writing, $char_id, $user_id) { try { $c = new Character(); $w = $c->create_sparse_writing($writing); //骨架化笔画 $f = new Feature(); $features = $f->make_feature($w); //获取特征 $dic = new Dictionary(); $dic->add_writing($char_id, $w, $user_id); //添加笔迹 $dict_feature = $dic->get_feature($char_id); //获取数据库中已存的特征值 $dict_feature = isset($dict_feature) ? json_decode($dict_feature) : null; $t = new Trainer(); $t->train($features, $dict_feature); $first_stroke_type = $c->get_first_stroke_type($w); //首笔的笔画类型(横竖撇点折) $int_strokes = sizeof($w->s); //笔画数 $dic->update_character($char_id, json_encode($t->train_features), $int_strokes, $first_stroke_type); $ret->msgno = MSG_OK; $ret->msg = MSG_OK_LEARN; } catch (Exception $e) { $ret->msgno = MSG_ERR; $ret->msg = $e->getMessage(); } }