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.
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.
//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.
$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) {