Esempio n. 1
0
        while ($row_meaning = $result_meaning->fetch_object()) {
            $def_arr[] = PWString::escapeQuotes($row_meaning->text);
            $query = "SELECT text FROM relation, wiki_text WHERE relation.wiki_text_id=wiki_text.id AND relation.meaning_id=" . (int) $row_meaning->meaning_id . " AND relation_type_id=" . (int) $relation_type_id;
            //print "<p>$query";
            $result_relation = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
            $synonym = array();
            while ($row_relation = $result_relation->fetch_object()) {
                $synonym[] = $row_relation->text;
                $is_exists_syn = 1;
            }
            if (sizeof($synonym)) {
                $synonyms[] = '"' . join('", "', $synonym) . '"';
            } else {
                $synonyms[] = '';
            }
        }
        if (isset($pos_ids[$row->pos_id])) {
            $pos_name = $pos_ids[$row->pos_id];
        } else {
            $pos_name = '';
        }
        $line = '{"word":["' . PWString::escapeQuotes($row->page_title) . '"], "POS":"' . $pos_ids[$row->pos_id] . '"';
        if ($is_exists_syn) {
            $line .= ', "synonym":[[' . join('],[', $synonyms) . ']]';
        }
        fwrite($fh, $line . ', "definition":["' . join('","', $def_arr) . "\"]}\n");
    }
}
fclose($fh);
?>
<p>done.
Esempio n. 2
0
//use piwidict\widget\WForm;
require '../config_examples.php';
require '../config_password.php';
include LIB_DIR . "header.php";
Piwidict::setDatabaseConnection($config['hostname'], $config['user_login'], $config['user_password'], $config['dbname']);
$link_db = Piwidict::getDatabaseConnection();
$wikt_lang = "ru";
// Russian language is the main language in ruwikt (Russian Wiktionary)
Piwidict::setWiktLang($wikt_lang);
$lang_id = TLang::getIDByLangCode("be");
$fh = fopen('be.wiktionary.with.empty.definition.txt', 'w');
$query = "SELECT page_title FROM lang_pos, page WHERE lang_pos.page_id = page.id AND lang_id={$lang_id} order by page_title";
$result = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
while ($row = $result->fetch_object()) {
    $is_empty = 1;
    $query = "SELECT wiki_text_id FROM lang_pos, page, meaning WHERE lang_pos.page_id = page.id AND lang_id={$lang_id} and page.page_title='" . PWString::escapeQuotes($row->page_title) . "' and lang_pos.id=meaning.lang_pos_id";
    $result_meaning = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
    if ($link_db->query_count($result_meaning)) {
        while ($is_empty && ($row_meaning = $result_meaning->fetch_object())) {
            if ($row_meaning->wiki_text_id != NULL) {
                $is_empty = 0;
            }
        }
    }
    if ($is_empty) {
        fwrite($fh, "#[[" . $row->page_title . "]]\n");
    }
}
fclose($fh);
?>
<p>done.
Esempio n. 3
0
<?php 
$count_exec_time = 1;
include "../../../config.php";
include LIB_DIR . "header.php";
$mask_word = "Пей";
$word = "ПИТЬ";
print "<p>{$word}, {$mask_word}, " . PWString::restoreCase($word, $mask_word);
$mask_word = "пей";
$word = "ПИТЬ";
print "<p>{$word}, {$mask_word}, " . PWString::restoreCase($word, $mask_word);
$mask_word = "Санкт-Петербургом";
$word = "САНКТ-ПЕТЕРБУРГ";
print "<p>{$word}, {$mask_word}, " . PWString::restoreCase($word, $mask_word);
$mask_word = "Saint-Petersburgs";
$word = "SAINT-PETERSBURG";
print "<p>{$word}, {$mask_word}, " . PWString::restoreCase($word, $mask_word);
include LIB_DIR . "footer.php";
Piwidict::setWiktLang($wikt_lang);
//$pos_name = "verb";
//$pos_name = "adverb";
//$pos_name = "adjective";
$pos_name = "noun";
$lang_id = TLang::getIDByLangCode("ru");
$pos_id = TPOS::getIDByName($pos_name);
$fh = fopen('semantic_relations_inlinks_more1meaning_' . $pos_name . '.txt', 'w');
$query = "SELECT wiki_text.text as inlink, relation_type.name as relation, page_title as outlink, meaning_id as outlink_meaning\n          FROM wiki_text, page, relation_type, relation, lang_pos, meaning\n          WHERE page.id = lang_pos.page_id AND lang_id = {$lang_id} AND meaning.lang_pos_id = lang_pos.id AND \n                relation.meaning_id = meaning.id AND relation.wiki_text_id = wiki_text.id AND\n                relation.relation_type_id = relation_type.id order by inlink";
$result = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
while ($row = $result->fetch_object()) {
    if ($pos_name == 'noun') {
        $lword = mb_strtolower($row->inlink);
    }
    if ($pos_name != 'noun' || $lword != 'имя' && $lword == $row->inlink) {
        $query = "SELECT wiki_text.text as inlink_meaning FROM meaning, page, lang_pos, wiki_text WHERE page.id = lang_pos.page_id AND meaning.lang_pos_id = lang_pos.id AND\n                 meaning.wiki_text_id = wiki_text.id AND page_title like '" . PWString::escapeQuotes($row->inlink) . "' AND lang_id = {$lang_id}  AND pos_id={$pos_id}";
        $result_meaning = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
        $num = $link_db->query_count($result_meaning);
        if ($num > 1) {
            $row_meaning = $result_meaning->fetch_object();
            fwrite($fh, $row->inlink . '%%' . $row_meaning->inlink_meaning . '%%' . $row->relation . '%%' . $row->outlink . '%%' . TMeaning::getMeaningByID($row->outlink_meaning) . "\n");
            while ($row_meaning = $result_meaning->fetch_object()) {
                fwrite($fh, '%%' . $row_meaning->inlink_meaning . "\n");
            }
        }
    }
}
fclose($fh);
include LIB_DIR . "footer.php";
?>
<p>done.
Esempio n. 5
0
        }
        if (TLang::isExist($lang)) {
            $query .= " and lang_id=" . (int) $lang;
        }
        $query .= " group by pw_reverse_dict.page_id";
    }
    $query .= " order by reverse_page_title LIMIT 0,{$limit}";
    //    $query = "SELECT id, page_title FROM page order by page_title LIMIT 0,100";
    //print $query;
    $res_page = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
    print "<div style=\"width:50%; text-align:right\">";
    $count = 0;
    while ($row = $res_page->fetch_object()) {
        // meaning.wiki_text_id>0 === words with non-empty definitions
        // relation.meaning_id=meaning.id === words with semantic relations
        /*
            	$query = "SELECT count(*) as count FROM lang_pos, meaning, relation WHERE lang_pos.page_id='".$row->page_id."' and lang_pos.id=meaning.lang_pos_id and meaning.wiki_text_id>0 ".
        		"and relation.meaning_id=meaning.id LIMIT 0,10000";
                $res_meaning = $link_db -> query_e($query,"Query failed in file <b>".__FILE__."</b>, string <b>".__LINE__."</b>");
                $row_meaning = $res_meaning -> fetch_object();
                if ($row_meaning->count >0) {
        */
        $word = PWString::reverseString($row->reverse_page_title);
        //    	    $word = $row->page_title;
        print "<a href=\"http://" . WIKT_LANG . ".wiktionary.org/wiki/{$word}\">|{$word}|</a><br >\n";
        $count++;
        //    	}
    }
    print "</div>\n" . "<p>There are founded {$count} words</p>\n";
}
include LIB_DIR . "footer.php";
Esempio n. 6
0
 $is_exists_syn = 0;
 if (isset($pos_ids[$row_lpos->pos_id])) {
     $pos_name = $pos_ids[$row_lpos->pos_id];
 } else {
     $pos_name = '';
 }
 $line = $line1 . ', "POS":"' . $pos_name . '"';
 $query = "SELECT text, meaning.id as meaning_id FROM meaning, wiki_text WHERE lang_pos_id=" . (int) $row_lpos->id . " and meaning.wiki_text_id=wiki_text.id order by meaning_n";
 $result_meaning = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
 if ($link_db->query_count($result_meaning) == 0) {
     fwrite($fh, $line . ", \"definition\":[]}\n");
     // without meanings
     continue;
 }
 while ($row_meaning = $result_meaning->fetch_object()) {
     $def_arr[] = PWString::escapeQuotes($row_meaning->text);
     $query = "SELECT text FROM relation, wiki_text WHERE relation.wiki_text_id=wiki_text.id AND relation.meaning_id=" . (int) $row_meaning->meaning_id . " AND relation_type_id=" . (int) $relation_type_id;
     //print "<p>$query";
     $result_relation = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     $synonym = array();
     while ($row_relation = $result_relation->fetch_object()) {
         $synonym[] = $row_relation->text;
         $is_exists_syn = 1;
     }
     if (sizeof($synonym)) {
         $synonyms[] = '"' . join('", "', $synonym) . '"';
     } else {
         $synonyms[] = '';
     }
 }
 if ($is_exists_syn) {
Esempio n. 7
0
 /** Counts frequency of occurance of lemmas in meanings and writes to field `pw_lemma_LANG_CODE.frequency`,
  *  if this lemma does not exist in table, that it added there with origin=2 and meaning_id where it has be found.
  */
 public static function count_frequency_lemma_in_meaning()
 {
     global $LINK_DB;
     // set some options
     $opts = array('storage' => PHPMORPHY_STORAGE_FILE, 'predict_by_suffix' => true, 'predict_by_db' => true, 'graminfo_as_text' => true);
     // Path to directory where dictionaries located
     $dir = SITE_ROOT . 'phpmorphy/dicts';
     $lang = 'ru_RU';
     // Create phpMorphy instance
     try {
         $morphy = new phpMorphy($dir, $lang, $opts);
     } catch (phpMorphy_Exception $e) {
         die('Error occured while creating phpMorphy instance: ' . PHP_EOL . $e);
     }
     try {
         $lang_id = (int) TLang::getIDByLangCode(PWLemma::getLangCode());
         $l_table = PWLemma::getTableName();
         $query = "SELECT meaning.id as meaning_id, wiki_text.text as text FROM wiki_text, meaning, lang_pos WHERE  " . "wiki_text.id=meaning.wiki_text_id and meaning.lang_pos_id=lang_pos.id and lang_pos.lang_id={$lang_id}";
         $res_meaning = $LINK_DB->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
         while ($row_meaning = $res_meaning->fetch_object()) {
             //print "<p>".$row_meaning->text;
             $words = preg_split('/((^\\p{P}+)|(\\p{P}*\\s+\\p{P}*)|(\\p{P}+$))/u', $row_meaning->text, -1, PREG_SPLIT_NO_EMPTY);
             //print_r($words);
             $words = array_count_values($words);
             foreach ($words as $word => $count) {
                 $lemma = PWLemma::getPhpMorphyLemma($word, $morphy);
                 if (!$lemma) {
                     continue;
                 }
                 $lemma = PWString::restoreCase($lemma, $word);
                 $lemma = str_replace("'", "\\'", $lemma);
                 $cond = "WHERE lemma like '{$lemma}'";
                 $res_lemma = $LINK_DB->query_e("SELECT id,frequency FROM {$l_table} {$cond}", "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
                 if ($LINK_DB->query_count($res_lemma) == 0) {
                     $query = "INSERT INTO `{$l_table}` (`lemma`,`origin`,`frequency`,`meaning_id`) VALUES ('{$lemma}',2,{$count}," . $row_meaning->meaning_id . ")";
                     //print "<p>$query";
                     $LINK_DB->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
                 } else {
                     $row_lemma = $res_lemma->fetch_object();
                     $query = "UPDATE `{$l_table}` SET `frequency`=" . (int) ($count + $row_lemma->frequency) . " {$cond}";
                     //print "<p>$query";
                     $LINK_DB->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
                 }
             }
         }
     } catch (phpMorphy_Exception $e) {
         die('Error occured while text processing: ' . $e->getMessage());
     }
 }
Esempio n. 8
0
<?php

require "../../config.php";
$str = 'азбука';
//mb_internal_encoding('utf8');
//print mb_substr($str,0,1);
print PWString::reverseString($str);