コード例 #1
0
ファイル: PWStats.php プロジェクト: componavt/piwidict
 /** Counts number of semantic relations filtered by language code and type of semantic relation.  
  * @return int */
 public static function countRelations($lang_code, $relation_type_name)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $lang_id = TLang::getIDByLangCode($lang_code);
     $relation_type_id = TRelationType::getIDByName($relation_type_name);
     $query = "SELECT meaning_id from relation, lang_pos, meaning where lang_pos.id=meaning.lang_pos_id and meaning.id=relation.meaning_id " . "and relation_type_id=" . (int) $relation_type_id . " and lang_pos.lang_id=" . (int) $lang_id;
     $result = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     return $link_db->query_count($result);
 }
コード例 #2
0
ファイル: json.ru.php プロジェクト: componavt/piwidict
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";
            $result_relation = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
コード例 #3
0
ファイル: synset_3_more.php プロジェクト: componavt/piwidict
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) {
                $synonyms[] = $row_relation->relation_word;
コード例 #4
0
ファイル: list_hypo.obj.php プロジェクト: componavt/piwidict
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;
?>

<form action="<?php 
コード例 #5
0
ファイル: list_hypo.php プロジェクト: katerysh/wikokit
<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;
    // [39] => Array ( [id] => 39 [name] => noun )
    if ($pos_id != $pos_id_noun && $pos_id != $pos_id_noun_class) {
        continue;
    }
コード例 #6
0
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);
$php_self = "antonym_synsets.php";
$lang_name = "ru";
$lang_id = TLang::getIDByLangCode($lang_name);
$ant_id = TRelationType::getIDByName("antonyms");
$out_file_name = SITE_ROOT . preg_replace("/^\\/src(\\/.+)\\.php\$/", "data\$1", $php_self);
$pos_name = "noun";
//$pos_name = "verb";
//$pos_name = "adjective";
//$pos_name = "adverb";
$pos_id = TPOS::getIDByName($pos_name);
//$fh = gzopen($out_file_name.'.txt.gz','wb9');
$fh = gzopen($out_file_name . '_' . $lang_name . '_' . $pos_name . '.txt.gz', 'wb9');
gzwrite($fh, '## Database version: ' . NAME_DB . "\n\n");
$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} " . "  AND pos_id={$pos_id} " . "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\n              FROM wiki_text, relation\n              WHERE relation.wiki_text_id=wiki_text.id \n                AND wiki_text.text NOT LIKE '% %'\n                AND relation_type_id = {$ant_id}\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);