Esempio n. 1
0
function get_word_row_try_stemming($word)
{
    $word_row = get_word_row($word);
    if ($word_row) {
        return $word_row;
    }
    # didnt find the exact word, so try a few heuristics
    # if word ends with "s", try to find word without it e.g. "strings" => "string"
    if ("s" == substr($word, strlen($word) - 1)) {
        $word = substr($word, 0, strlen($word) - 1);
        $word_row = get_word_row($word);
        if ($word_row) {
            return $word_row;
        }
    }
    # if word ends with "ed", try to find word without it e.g. "glued" => "glue"
    if ("ed" == substr($word, strlen($word) - 2)) {
        $word = substr($word, 0, strlen($word) - 2);
        $word_row = get_word_row($word);
        if ($word_row) {
            return $word_row;
        }
    }
    # if word ends with "ing", try to find word without it e.g. "working" => "work"
    if ("ing" == substr($word, strlen($word) - 3)) {
        $word = substr($word, 0, strlen($word) - 3);
        $word_row = get_word_row($word);
        if ($word_row) {
            return $word_row;
        }
    }
    return 0;
}
Esempio n. 2
0
function serve_get_word($cookie, $word)
{
    /*
        if ( $word=='wl' )
        {
            write_WORDLIST( "word one\nand another\nand even more\nword three\ntest\nsample\n" );
            exit;
        }
    
        if ( $word=='tm' )
        {
            write_MSG( "This is a test message. Do you hear me now?" );
            exit;
        }
    */
    $orig_word = $word;
    log_get_word_request($cookie, $word);
    $word_row = get_word_row($word);
    if ($word_row) {
        write_DEF($word, $word_row->pron, $word_row->def);
        exit;
    }
    # didnt find the exact word, so try a few heuristics
    # if word ends with "s", try to find word without it e.g. "strings" => "string"
    if ("s" == substr($word, strlen($word) - 1)) {
        $word = substr($word, 0, strlen($word) - 1);
        $word_row = get_word_row($word);
        if ($word_row) {
            write_DEF($word, $word_row->pron, $word_row->def);
            exit;
        }
    }
    # if word ends with "ed", try to find word without it e.g. "glued" => "glue"
    if ("ed" == substr($word, strlen($word) - 2)) {
        $word = substr($word, 0, strlen($word) - 2);
        $word_row = get_word_row($word);
        if ($word_row) {
            write_DEF($word, $word_row->pron, $word_row->def);
            exit;
        }
    }
    # if word ends with "ing", try to find word without it e.g. "working" => "work"
    if ("ing" == substr($word, strlen($word) - 3)) {
        $word = substr($word, 0, strlen($word) - 3);
        $word_row = get_word_row($word);
        if ($word_row) {
            write_DEF($word, $word_row->pron, $word_row->def);
            exit;
        }
    }
    # didnt find the word
    write_MSG("Definition of word '{$orig_word}' has not been found");
    exit;
}