/** Selects row from the table 'lang_pos' by ID.<br><br> * SELECT page_id,lang_id,pos_id,etymology_n,lemma FROM lang_pos WHERE id=8; * @return null if data is absent. */ public static function getByID($lang_pos_id, $lang_all, $pos_all) { global $LINK_DB; $lang_pos = NULL; $query = "SELECT page_id,lang_id,pos_id,etymology_n,lemma FROM lang_pos WHERE id={$lang_pos_id}"; $result = mysqli_query($LINK_DB, $query) or die("Query failed (line 31) in TLangPOS::getByID: " . mysqli_error() . ". Query: " . $query); while ($row = mysqli_fetch_array($result)) { $page_id = $row['page_id']; $lang_id = $row['lang_id']; $pos_id = $row['pos_id']; $etymology_n = $row['etymology_n']; $lemma = $row['lemma']; $lang_pos['page'] = TPage::getByID($page_id); //print "TLangPOS::getByID lang_id = $lang_id<BR>"; //print "TLangPOS::getByID pos_id = $pos_id<BR>"; $lang_pos['lang'] = TLang::getByID($lang_id, $lang_all); //print "TLangPOS::getByID TLang lang = "; print_r ($lang_pos ['lang']); print "<BR>"; $lang_pos['pos'] = TPOS::getByID($pos_id, $pos_all); //print "TLangPOS::getByID TPOS pos = "; print_r($lang_pos ['pos']); print "<BR>"; $lang_pos['etymology_n'] = $etymology_n; $lang_pos['lemma'] = $lemma; $lang = $lang_pos['lang']; $pos = $lang_pos['pos']; if (null == $lang || null == $pos) { $lang_pos = NULL; } } return (object) $lang_pos; }
/** Counts number of Wiktionary phrases in given language defined by $lang_code. * @return int */ public static function countLangPOS($lang_code, $pos_name) { $link_db = Piwidict::getDatabaseConnection(); $lang_id = TLang::getIDByLangCode($lang_code); if (!$lang_id) { return 0; } $pos_id = TPOS::getIDByName($pos_name); if (!$pos_id) { return 0; } $query = "SELECT DISTINCT page_id FROM lang_pos WHERE pos_id=" . (int) $pos_id . " and lang_id=" . (int) $lang_id; $result_page = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>"); return $link_db->query_count($result_page); }
foreach ($wikt_words as $w_word =>$s_word) { print "<br># [[$w_word]]"; } */ /* print "<pre>"; print_r($proper_noun_word); */ print "<p><b>POS distribution:</b>"; $lang_pos_count = array(); foreach ($lang_pos_word as $lp => $words_arr) { $lang_pos_count[$lp] = sizeof($words_arr); } asort($lang_pos_count); foreach ($lang_pos_count as $lp => $total) { print "<hr><p><i>==" . TPOS::getNameByID($lp) . ": {$total}==</i></p>\n"; $words_arr = $lang_pos_word[$lp]; ksort($words_arr); print "<table border=1 cellspacing=0 cellpadding=5>\n"; $null_words = array(); foreach ($words_arr as $word => $lword) { if (!$RNC_num[$lword] && !$GBN_num[$lword]) { $null_words[] = $word; } else { print "<tr><td># [[{$word}]]</td><td>" . $RNC_num[$lword] . "</td><td>" . $GBN_num[$lword] . "</td></tr>\n"; } } print "</table>\n"; foreach ($null_words as $word) { print "<br>#[[{$word}]]"; }
<?php require '../../../vendor/autoload.php'; use piwidict\Piwidict; use piwidict\sql\{TLang, TPage, TPOS, TRelationType}; use piwidict\widget\WForm; require '../config_examples.php'; require '../config_password.php'; // $pw = new Piwidict(); 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("ru"); $pos_ids = array(TPOS::getIDbyName('noun') => "сущ", TPOS::getIDbyName('adjective') => "прил", TPOS::getIDbyName('verb') => "глаг", TPOS::getIDbyName('adverb') => "нареч"); $relation_type_id = (int) TRelationType::getIDByName("synonyms"); $fh = fopen('ru.wiktionary.with.synonyms.json', 'w'); $query = "SELECT page_title, lang_pos.id as id, pos_id FROM lang_pos,page WHERE lang_pos.page_id = page.id AND lang_id={$lang_id} order by page_title"; print "<p>{$query}"; $result = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>"); while ($row = $result->fetch_object()) { $def_arr = $synonyms = array(); $is_exists_syn = 0; $query = "SELECT text, meaning.id as meaning_id FROM meaning, wiki_text WHERE lang_pos_id=" . (int) $row->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)) { 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";
require '../../../vendor/autoload.php'; use piwidict\Piwidict; //use piwidict\sql\{TLang, TPage, TPOS, TRelationType}; //use piwidict\widget\WForm; require '../config_examples.php'; require '../config_password.php'; include LIB_DIR . "header.php"; // $pw = new Piwidict(); 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); $pos_name = "adjective"; $lang_id = TLang::getIDByLangCode("ru"); $pos_id = TPOS::getIDByName($pos_name); $syn_id = TRelationType::getIDByName("synonyms"); $fh1 = fopen('synset_synonyms_only_' . $pos_name . '.txt', 'w'); $fh2 = fopen('synset_all_relations_' . $pos_name . '.txt', 'w'); $query = "SELECT page_title as first_word, meaning.id as meaning_id\n FROM lang_pos, meaning, page \n WHERE lang_pos.id = meaning.lang_pos_id \n AND page.id = lang_pos.page_id\n AND page_title NOT LIKE '% %'\n AND lang_id = {$lang_id}\n AND pos_id={$pos_id}\n ORDER BY page_title"; $result_meaning = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>"); while ($row = $result_meaning->fetch_object()) { $query = "SELECT wiki_text.text as relation_word, relation_type_id\n FROM wiki_text, relation \n WHERE relation.wiki_text_id=wiki_text.id \n AND wiki_text.text NOT LIKE '% %'\n AND relation.meaning_id = " . $row->meaning_id . " ORDER BY wiki_text.text"; $result_relation = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>"); $num = $link_db->query_count($result_relation); if ($num > 1) { $synonyms = array(); fwrite($fh2, $row->first_word); while ($row_relation = $result_relation->fetch_object()) { fwrite($fh2, ' ' . $row_relation->relation_word); if ($row_relation->relation_type_id == $syn_id) {
?> )</h2> Database version: <?php echo NAME_DB; ?> <form action="<?php echo $php_self; ?> " method="GET"> <p>Language: <?php echo TLang::getDropDownList($lang_id, "lang_id", ''); ?> </p> <p>Part of speech: <?php echo TPOS::getDropDownList($pos_id, "pos_id", ''); ?> </p> <p>Relation type: <?php echo TRelationType::getDropDownList($relation_type_id, "relation_type_id", ''); ?> </p> <p>Word: <input type="text" name="page_title" value="<?php echo $page_title; ?> "></p> <p><input type="submit" name="view_list" value="search"></p> </form> <?php if (isset($view_list) && $view_list) { $query_lang_pos = "SELECT lang_pos.id as id, page_title FROM lang_pos, page WHERE lang_pos.page_id=page.id";
<p>Language: <?php echo TLang::getDropDownList($lang, "lang", ''); ?> </p> <p>Part of speech: <?php echo TPOS::getDropDownList($pos, "pos", ''); ?> </p> <p><input type="submit" name="view_dict" value="view"></p> </form> <?php if (isset($view_dict) && $view_dict) { $query = "SELECT pw_reverse_dict.page_id, reverse_page_title FROM pw_reverse_dict"; if ($pos > 0 || $lang > 0) { $query .= ", lang_pos WHERE lang_pos.page_id=pw_reverse_dict.page_id"; if (TPOS::isExist($pos)) { $query .= " and pos_id=" . (int) $pos; } 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
require '../../../vendor/autoload.php'; use piwidict\Piwidict; //use piwidict\sql\{TLang, TPage, TPOS, TRelationType}; //use piwidict\widget\WForm; require '../config_examples.php'; require '../config_password.php'; include LIB_DIR . "header.php"; // $pw = new Piwidict(); 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("ru"); $pos_id = TPOS::getIDByName("noun"); $proper_noun_word = array(); //$counter = 0; $query = "SELECT page_title,id as page_id FROM page WHERE id in (SELECT page_id FROM lang_pos where lang_id={$lang_id} and pos_id={$pos_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()) { $word = $row->page_title; $l_word = mb_strtolower($word); if ($word != $l_word) { $proper_noun_word[] = $word; } } print "<hr><p><b>There are " . sizeof($proper_noun_word) . " proper nouns </b><br> (вычислено по существительным, это <i>предположительно</i> <b>имена собственные</b>, а точнее те слова, для которых:<br> нижний_регистр (слово) != слово)\n"; $fh = fopen('pos_proper_noun.txt', 'w'); ksort($proper_noun_word); foreach ($proper_noun_word as $word) {
$this_script_URL = "list_hypo.php"; include "../lib/header.php"; ?> <h3>Generation of list of hyponyms and hypernyms</h3> <?php print "Database version: {$NAME_DB}<BR>"; //$labels_all = TLabel::getAllLabels(); $lang_all = TLang::getAllLang(); $relation_type_all = TRelationType::getAllRelations(); $pos_all = TPOS::getAllPOS(); $lang_id_ru = TLang::getIDByLangCode($lang_all, "ru"); print "lang_id_ru = {$lang_id_ru}<BR>"; $pos_id_noun = TPOS::getIDByName($pos_all, "noun"); $pos_id_noun_class = TPOS::getIDByName($pos_all, "noun class"); print "ID of part of speech \"noun\" = {$pos_id_noun}<BR>"; print "ID of part of speech \"noun class\" = {$pos_id_noun_class}<BR>"; $relation_type_id_hyponyms = TRelationType::getIDByName($relation_type_all, "hyponyms"); $relation_type_id_hypernyms = TRelationType::getIDByName($relation_type_all, "hypernyms"); print "ID of relation type \"hyponyms\" = {$relation_type_id_hyponyms}<BR>"; print "ID of relation type \"hypernyms\" = {$relation_type_id_hypernyms}<BR>"; print "<BR>"; $query_lang_pos = "SELECT id FROM lang_pos"; $result_lang_pos = mysqli_query($LINK_DB, $query_lang_pos) or die("Query failed (line 39) in list_hypo.php: " . mysqli_error() . ". Query: " . $query); $counter = 0; while ($row = mysqli_fetch_array($result_lang_pos)) { $lang_pos_id = $row['id']; $lang_pos = TLangPOS::getByID($lang_pos_id, $lang_all, $pos_all); // 1. filter by part of speech $pos_id = $lang_pos->pos->id;
/** Gets TLangPOS object by property $property_name with value $property_value. * @return TLangPOS or NULL in case of error */ public static function getLangPOS($property_name, $property_value, $page_obj = NULL) { global $LINK_DB; $query = "SELECT * FROM lang_pos WHERE lang_id is not NULL and pos_id is not NULL and `{$property_name}`='{$property_value}' order by id"; $result = $LINK_DB->query_e($query, "Query failed in " . __METHOD__ . " in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>"); if ($LINK_DB->query_count($result) == 0) { return NULL; } $lang_pos_arr = array(); while ($row = $result->fetch_object()) { $lang = TLang::getByID($row->lang_id); $pos = TPOS::getByID($row->pos_id); if (NULL == $lang || NULL == $pos) { return NULL; } if ($page_obj == NULL) { $page_obj = TPage::getByID($row->page_id); } $lang_pos = new TLangPOS($row->id, $page_obj, $lang, $pos, $row->etymology_n, $row->lemma); $lang_pos->meaning = TMeaning::getByLangPOS($row->id, $lang_pos); $lang_pos_arr[] = $lang_pos; } return $lang_pos_arr; }