示例#1
0
 function is_acceptable($input)
 {
     return compare_syntax3($this->expr, $input, nano_dfdict(), true) !== NULL;
 }
示例#2
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]);
示例#3
0
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'hhad having';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'having hhad';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'had hhaving';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$syntax = '{having} {had}';
$answer = 'having had';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'had having';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'hhaving had';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'hhad having';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'having hhad';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
$answer = 'had hhaving';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
echo "took " . (microtime(true) - $stime) . " seconds";
echo "<hr>";
$stime = microtime(true);
$dict = [];
$syntax = '{this} {is} {a} {sentence} {{which} {is} {this}}';
$answer = 'sentence which this is this is a';
var_dump(compare_syntax3($syntax, $answer, $dict, true, 2));
var_dump(compare_syntax3($syntax, $answer, $dict, true, 5));
echo "took " . (microtime(true) - $stime) . " seconds";
echo "<hr>";
echo "took " . (microtime(true) - $START) . " seconds total";
示例#4
0
}
if ($cquiz->mode() != "question") {
    exit("Checking answers is not allowed for this quiz (mode: " . $cquiz->mode() . ")");
}
$flags = ["unescaped" => TRUE, "matchall" => TRUE];
$name = safe_get("name", $_POST);
if (!$name) {
    exit("no key name supplied");
}
$values = $cquiz->answers()[$name];
$answer = safe_get("answer", $_POST);
if (!$answer) {
    exit("no answer supplied");
}
if (array_key_exists("correct", $values) and is_array($values["correct"]) and array_key_exists("expr", $values) and is_string($values["expr"])) {
    $value = compare_syntax3($values["expr"], $answer, nano_dfdict(), true);
    if ($value === null) {
        echo "false";
    } else {
        echo "true";
    }
} else {
    if (array_key_exists("correct", $values) and array_key_exists("acceptable", $values) and is_array($values["correct"]) and is_array($values["acceptable"])) {
        $also = $values["correct"];
        $correct = $values["correct"];
        $values = $values["acceptable"];
    } else {
        $correct = $also = $values;
    }
    $score = FALSE;
    foreach ($values as $value) {
?>
</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>
<label><input type="checkbox" checked id="matchall">Only match whole string</label>
<br>
<input style="width: 100%" id="syntax" placeholder="Expression">
<br>