Beispiel #1
0
<?php

require_once '/var/www/config.php';
sro('/Includes/mysql.php');
sro('/Includes/session.php');
sro('/Includes/functions.php');
sro('/PHP5/lib/PHPLang/common.php');
sro('/PHP5/lib/PHPLang/display.php');
sro('/PHP5/lib/PHPLang/string.php');
sro('/PHP5/lib/PHPLang/misc.php');
$input = $_GET["input"];
$syntax = $_GET["syntax"];
$dict = nano_dfdict();
global $DEBUG_STRING_PHP;
$expression = nanomacro($syntax, $dict, 4);
$DEBUG_STRING_PHP = safe_get("debug", $_GET) === "true";
$permutation = permute_syntax($expression);
ob_start();
$result = compare_syntax3($syntax, $input, $dict, !!safe_get("matchall", $_GET), safe_get("dist", $_GET));
$log = ob_get_contents();
ob_end_clean();
echo json_encode(["expression" => $expression, "result" => $result, "log" => $log, "permutation" => $permutation]);
Beispiel #2
0
$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';
var_dump(compare_syntax3($syntax, $answer, $dict));
echo "took " . (microtime(true) - $stime) . " seconds";
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';
var_dump(compare_syntax3($syntax, $answer, $dict));
echo "took " . (microtime(true) - $stime) . " seconds";
echo "<hr>";
$stime = microtime(true);
$dict = [];
$syntax = '{had} {having}';
$answer = 'having had';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'had having';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
Beispiel #3
0
function compare_syntax3($syntax, $target, $dictionary = null, $matchall = false, $distance = 0, $lang = NULL)
{
    if ($dictionary === null) {
        $dictionary = nano_dfdict();
    }
    $syntax = nanomacro($syntax, $dictionary, 4);
    $match = compare_syntax($syntax, $target, ["unescaped" => true, "matchall" => $matchall, "max_distance" => $distance, "lang" => $lang]);
    return $match ? normalize_punctuation($match) : $match;
}
    echo2(compare_syntax($example[0], $example[1], ["unescaped" => true]));
    ?>
<br><?php 
}
?>
</ul>

<p>You can see why we need to normalize the punctuation (make it look pretty) and use macros (simplify our expression-writing needs). Let's see how it all works:
<ul>
<?php 
foreach ([['{*_a centurion} {_perfactv$(caught sight of)$(_a young man)} {said} {_quot$(I recognize (this [man|guy]|him)!)}.', 'thecenturionhavingcaughtsightoftheyoungmansaidirecognizehim'], ['{*{, {himself} {_a young man}, } {_a centurion}} {smiled|was smiling}.', 'the centurion a young man himself was smiling'], ['{*{, {himself} {_a young man}, } {_a centurion}} {smiled|was smiling}.', 'a young man himself the centurion was smiling'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou dost not know me'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou dost know me not'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou not me knowest'], ['_Appos$(_a centurion)$(having seen _a child) {wept} _quot$({*have mercy} {on me} {,O deity,}).', 'the centurion having seen the child wept on me have mercy O deity']] as $example) {
    ?>
<li><?php 
    echo2($example[0]);
    echo "makes this syntax";
    echo2(nanomacro($example[0], $dict, 4));
    echo "and matches";
    echo2($example[1]);
    echo "creating";
    echo2(compare_syntax3($example[0], $example[1], $dict));
    ?>
<br><?php 
}
?>
</ul>

<h2>Try it!</h2>
<p>IT'S ALIVE!!</p>

Damerau-Levenshtein error: <input id="dist" style="width:150px" type="number" placeholder="Max Distance">
<label><input type="checkbox" id="debug">Debug</label>