コード例 #1
0
    }
    $def->internalRep = $s;
    $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId);
    $def->abbrevReview = ABBREV_REVIEW_COMPLETE;
    $def->save();
}
$MARKER = 'DEADBEEF';
// any string that won't occur naturally in a definition
$def = null;
$ids = db_getArray(sprintf('select id from Definition where status != %d and abbrevReview = %d', ST_DELETED, ABBREV_AMBIGUOUS));
if (count($ids)) {
    $defId = $ids[array_rand($ids, 1)];
    $def = Definition::get_by_id($defId);
    // Collect the positions of ambiguous abbreviations
    $matches = array();
    AdminStringUtil::markAbbreviations($def->internalRep, $def->sourceId, $matches);
    usort($matches, 'positionCmp');
    // Inject our marker around each ambiguity and htmlize the definition
    $s = $def->internalRep;
    foreach ($matches as $m) {
        $s = substr($s, 0, $m['position']) . " {$MARKER} " . substr($s, $m['position'], $m['length']) . " {$MARKER} " . substr($s, $m['position'] + $m['length']);
    }
    $s = AdminStringUtil::htmlize($s, $def->sourceId);
    // Split the definition into n ambiguities and n+1 bits of text between the ambiguities
    $text = array();
    $ambiguities = array();
    while (($p = strpos($s, $MARKER)) !== false) {
        $chunk = trim(substr($s, 0, $p));
        $s = trim(substr($s, $p + strlen($MARKER)));
        if (count($text) == count($ambiguities)) {
            $text[] = $chunk;
コード例 #2
0
ファイル: test.php プロジェクト: nastasie-octavian/DEXonline
function assertAbbreviations($typed, $internal, $html, $sourceId)
{
    assertEquals($internal, AdminStringUtil::markAbbreviations($typed, $sourceId));
    assertEquals($html, AdminStringUtil::htmlize($internal, $sourceId));
}