/** 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); }
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) {
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"; 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); $php_self = "reverse_dict.php"; if (!isset($pos)) { $pos = TPOS::getIDByName("noun"); } if (!isset($lang)) { $lang = TLang::getIDByLangCode("ru"); } $limit = 200000; ?> <h1>Reverse dictionary (LIMIT <?php echo $limit; ?> )</h1> <form action="<?php echo $php_self; ?> " method="GET">
//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); $php_self = "list_hypo.obj.php"; if (!isset($lang_id)) { $lang_id = TLang::getIDByLangCode("ru"); } if (!isset($pos_id)) { $pos_id = TPOS::getIDByName("noun"); } if (!isset($relation_type_id)) { $relation_type_id = TRelationType::getIDByName("hyponyms"); } if (!isset($page_title)) { $page_title = ''; } $limit = 100; ?> <h2>Generation of list of relations (LIMIT <?php echo $limit; ?> )</h2> Database version: <?php echo NAME_DB;
$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;