function normalize_punctuation($str) { global $OP_COMMA, $OP_PERIOD; $ops = lexify_punctuation($str); $ops = simplify_punctuation($ops); if ($ops and $ops[count($ops) - 1] === $OP_COMMA) { $ops[count($ops) - 1] = $OP_PERIOD; } return serialize_sentence_part($ops); }
var_dump(compare_syntax($syntax, "This is Aristos house", ["unescaped" => true])); echo "took " . (microtime(true) - $stime) . " seconds"; /**/ echo "<hr>"; $stime = microtime(true); $syntax = nanomacro('{*Agricola} {_cum$({he|Agricola} {had arrived})} {_imp$(want) to (say|speak)} {_a few (words|things)}.', ['cum' => ', when ${0},', 'a' => '[a[n]|the]', 'imp' => '(was ${0}ing|${0}ed)'], 4); var_dump($syntax); var_dump(compare_syntax($syntax, "Agricola, when he had arrived, wanted to say a few things", ["unescaped" => true])); var_dump(compare_syntax($syntax, "When he had arrived, Agricola was wanting to say a few words", ["unescaped" => true])); echo "took " . (microtime(true) - $stime) . " seconds"; /**/ echo "<hr>"; $stime = microtime(true); $sentence = " , When he said {$OP_LQUOTE}Hello?{$OP_RQUOTE}, they were silent. , {$OP_LQUOTE}Hello{$OP_RQUOTE}, he said. {$OP_LQUOTE}What happened?{$OP_RQUOTE}. He repeated, {$OP_LQUOTE}Hello{$OP_RQUOTE}. {$OP_LQUOTE}What happened?{$OP_RQUOTE}"; var_dump($sentence); var_dump(lexify_punctuation($sentence)); var_dump(normalize_punctuation($sentence)); echo "took " . (microtime(true) - $stime) . " seconds"; /**/ // centuriō, iuvenem cōnspicātus, “hunc agnōscō!” inquit. // kenturioo, iuvenem koonspikaatus, "hunk agnooskoo!" inquit. echo "<hr>"; $stime = microtime(true); $syntax = '{*_a centurion} {_perfactv$(centurion|he)$(caught sight of)$(_a young man)} {said} {_quot$(I recognize (this [man|guy]|him))}.'; $dict = ['a' => '[a[n]|the]', 'perfactv' => ', (having ${1} ${2}|(when|once) ${0} had ${1} ${2}|who had ${1}${2}),', 'quot' => ', “${0}”,']; var_dump(nanomacro($syntax, $dict, 4)); $answer = 'the centurion having caught sight of the young man said I recognize him'; var_dump(compare_syntax3($syntax, $answer, $dict)); $answer = 'the centurion said I recognize him having caught sight of the young man'; var_dump(compare_syntax3($syntax, $answer, $dict)); $answer = 'I recognize him said the centurion having caught sight of the young man';