Exemplo n.º 1
0
function import()
{
    try {
        $page = isset($_GET['page']) ? $_GET['page'] : null;
        if ($page == 0) {
            del_feature();
        }
        $results = get_writing($page);
        $size = sizeof($results);
        foreach ($results as $r) {
            $f = new Feature();
            $w = json_decode($r->writing);
            $char_id = $r->char_id;
            $features = $f->make_feature($w);
            //获取特征
            $dic = new Dictionary();
            $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);
            $c = new Character();
            $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);
        }
        if ($size > 0) {
            echo "<meta HTTP-EQUIV=REFRESH CONTENT='5;URL=import.php?page=" . ($page + 1) . "'>";
        } else {
            echo "导入完成";
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
Exemplo n.º 2
0
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();
    }
}
Exemplo n.º 3
0
function debug_train(&$writing, $ret)
{
    $t = new Trainer();
    //训练(需要大量资源,非常慢)
    $t->train();
}