function recognize(&$ret, &$writing, $rank) { try { $debug_start = microtime(true); $c = new Character(); $w = $c->create_sparse_writing($writing); //骨架化笔画 $first_stroke_type = $c->get_first_stroke_type($w); //首笔的笔画类型(横竖撇点折) $int_strokes = sizeof($w->s); //笔画数 $f = new Feature(); $features = $f->make_feature($w); //获取特征 $debug_end = microtime(true); $ret->debug .= "计算特征所需的时间:" . debug_time($debug_start, $debug_end) . "<br>"; $debug_start = microtime(true); $dic = new Dictionary(); $cands = $dic->get_candidates_by_strokes($int_strokes, $first_stroke_type, $rank); //初步获取候选字 $debug_end = microtime(true); $ret->debug .= "获取候选字所需的时间:" . debug_time($debug_start, $debug_end) . "<br>"; $debug_start = microtime(true); $rec = new Recognizer(); $res = $rec->get_results($cands, $features, $debug_msg); //获取结果 $debug_end = microtime(true); $ret->debug .= "匹配候选字所需的时间:" . debug_time($debug_start, $debug_end) . "<br>"; if ($res != null) { $ret->msgno = MSG_OK; $ret->msg = MSG_OK_TXT; $ret->res = $res; } else { $ret->msgno = MSG_ERR; $ret->msg = MSG_ERR_NOCAND; } } catch (Exception $e) { $ret->msgno = MSG_ERR; $ret->msg = $e->getMessage(); } }