예제 #1
0
 /** Gets number of common words in two meanings (definitions) identified by meaning_id1 and meaning_id2, 
  * it will be counted only for meaninful POS [without stop-words].
  * @return int number of common words in two definitions
  */
 public static function countIntersectionTwoMeanings($meaning_id1, $meaning_id2)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $rk = array();
     //TODO
     return $rk;
 }
예제 #2
0
 /** 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);
 }
예제 #3
0
 public static function getPathLenBetweenPoints($start, $finish)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT path_len FROM " . self::$table_name . " where lemma_id_1='{$start}' and lemma_id_n='{$finish}'";
     $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;
     }
     $row = $result->fetch_object();
     return $row->path_len;
 }
예제 #4
0
 /** Gets TWikiText object (text, ID and wiki_text) by ID.
  * @return object or NULL if it is unknown ID.
  */
 public static function getByID($_id)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM wiki_text where id=" . (int) $_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;
     }
     $row = $result->fetch_object();
     return new TWikiText($row->id, $row->text, $row->wikified_text);
 }
예제 #5
0
 /** Gets TLabel object by property $property_name with value $property_value.
  * @return TLabel or NULL in case of error
  */
 private static function getLabel($property_name, $property_value)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM label WHERE `{$property_name}`='{$property_value}' order by id";
     $result = $link_db->query_err($query, __FILE__, __LINE__, __METHOD__);
     if ($link_db->query_count($result) == 0) {
         return NULL;
     }
     $label_arr = array();
     while ($row = $result->fetch_object()) {
         $label_arr[] = new TLabel($row->id, $row->short_name, $row->name, TLabelCategory::getByID($row->category_id));
     }
     return $label_arr;
 }
예제 #6
0
 /** Gets TRelation object by property $property_name with value $property_value.
  * @return TRelationType or NULL in case of error
  */
 public static function getRelationType($property_name, $property_value)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM relation_type WHERE `{$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;
     }
     $relation_type_arr = array();
     while ($row = $result->fetch_object()) {
         $relation_type_arr[] = new TRelationType($row->id, $row->name);
     }
     return $relation_type_arr;
 }
예제 #7
0
 /** Gets TTranslationEntry object by property $property_name with value $property_value.
  * @return TTranslationEntry or NULL in case of error
  */
 public static function getTranslationEntry($property_name, $property_value, $translation_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM translation_entry WHERE `{$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;
     }
     $translationEntry_arr = array();
     while ($row = $result->fetch_object()) {
         if ($translation_obj == NULL) {
             $translation_obj = TTranslation::getByID($row->translation_id);
         }
         $translationEntry_arr[] = new TTranslationEntry($row->id, $translation_obj, TLang::getByID($row->lang_id), TWikiText::getByID($row->wiki_text_id));
     }
     return $translationEntry_arr;
 }
예제 #8
0
 /** Gets TRelation object by property $property_name with value $property_value.
  * @return TLabelCategory or NULL in case of error
  */
 public static function getLabelCategory($property_name, $property_value, $parent_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM label_category WHERE `{$property_name}`='{$property_value}' order by id";
     $result = $link_db->query_err($query, __FILE__, __LINE__, __METHOD__);
     if ($link_db->query_count($result) == 0) {
         return NULL;
     }
     $category_arr = array();
     while ($row = $result->fetch_object()) {
         /*
         	    if ($parent_obj == NULL)
         	  	$parent_obj = TLabelCategory::getByID($row->parent_category_id); 
         */
         $category_arr[] = new TLabelCategory($row->id, $row->name, $parent_obj);
     }
     return $category_arr;
 }
예제 #9
0
 /** Gets TRelation object by property $property_name with value $property_value.
  * @return TRelation or NULL in case of error
  */
 public static function getRelation($property_name, $property_value, $meaning_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM relation WHERE `{$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;
     }
     $relation_arr = array();
     while ($row = $result->fetch_object()) {
         /*
         	    if ($meaning_obj == NULL)
         	  	$meaning_obj = TMeaning::getByID($row->meaning_id);
         */
         $relation_arr[] = new TRelation($row->id, $meaning_obj, TWikiText::getByID($row->wiki_text_id), TRelationType::getByID($row->relation_type_id), $row->meaning_summary);
     }
     return $relation_arr;
 }
예제 #10
0
 /** Gets TLabelMeaning object by property $property_name with value $property_value.
  * @return TLabelMeaning or NULL in case of error
  */
 public static function getLabelMeaning($property_name, $property_value, $meaning_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM label_meaning WHERE `{$property_name}`='{$property_value}'";
     $result = $link_db->query_err($query, __FILE__, __LINE__, __METHOD__);
     if ($link_db->query_count($result) == 0) {
         return NULL;
     }
     $labelMeaning_arr = array();
     while ($row = $result->fetch_object()) {
         /*
         	    if ($meaning_obj == NULL)
         	  	$meaning_obj = TMeaning::getByID($row->meaning_id);
         */
         $labelMeaning_arr[] = new TLabelMeaning(TLabel::getByID($row->label_id), $meaning_obj);
     }
     return $labelMeaning_arr;
 }
예제 #11
0
 public static function getDropDownList($selected_id, $select_name, $first_option = '', $table_name, $table_field = 'name', $order_by = 'id')
 {
     $link_db = Piwidict::getDatabaseConnection();
     $s = "<SELECT name=\"{$select_name}\">\n";
     if ($first_option !== NULL) {
         $s .= "<OPTION value='{$first_option}'></OPTION>\n";
     }
     $query = "SELECT id, `{$table_field}` as name FROM `{$table_name}` order by `{$order_by}`";
     $result = $link_db->query_e($query, "Query failed in " . __METHOD__ . " in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     while ($row = $result->fetch_object()) {
         $s .= "<OPTION value=\"" . $row->id . "\"";
         if ($selected_id == $row->id) {
             $s .= " selected";
             // selected option
         }
         $s .= ">" . $row->name . "</OPTION>\n";
     }
     $s .= "</SELECT>";
     return $s;
 }
예제 #12
0
 /** Gets TTranslation object by property $property_name with value $property_value.
  * @return TTranslation or NULL in case of error
  */
 public static function getTranslation($property_name, $property_value, $meaning_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM translation WHERE `{$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;
     }
     $translation_arr = array();
     while ($row = $result->fetch_object()) {
         /*
                 if ($meaning_obj == NULL)
                 $meaning_obj = TMeaning::getByID($row->meaning_id);
                
                 if ($meaning_obj != NULL)
                 $lang_pos_obj = $meaning_obj->getLangPOS();
                 else $lang_pos_obj = NULL;
         */
         $translation = new TTranslation($row->id, NULL, $row->meaning_summary, $meaning_obj);
         $translation->entry = TTranslationEntry::getByTranslation($row->id, $translation);
         $translation_arr[] = $translation;
     }
     return $translation_arr;
 }
예제 #13
0
 public static function getRelatedWords()
 {
     $link_db = Piwidict::getDatabaseConnection();
     $node_table = PWLemma::getTableName();
     $edge_table = PWRelatedWords::getTableName();
     // Construct DOM elements
     $xml = new DomDocument('1.0', 'UTF-8');
     $xml->formatOutput = true;
     // Nicely formats output with indentation and extra space
     $gexf = $xml->createElementNS(null, 'gexf');
     // Create new element node with an associated namespace
     $gexf = $xml->appendChild($gexf);
     // Assign namespaces for GexF with VIZ
     $gexf->setAttribute('xmlns:viz', 'http://www.gexf.net/1.1draft/viz');
     // Skip if you don't need viz!
     $gexf->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $gexf->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation', 'http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd');
     $gexf->setAttribute('version', '1.2');
     // Add Meta data
     $meta = $gexf->appendChild($xml->createElement('meta'));
     $meta->setAttribute('lastmodifieddate', date('Y-m-d'));
     $meta->appendChild($xml->createElement('creator', 'PHP GEXF Generator v0.1'));
     $meta->appendChild($xml->createElement('description', 'Related words'));
     // Add Graph data!
     $graph = $gexf->appendChild($xml->createElement('graph'));
     $nodes = $graph->appendChild($xml->createElement('nodes'));
     $edges = $graph->appendChild($xml->createElement('edges'));
     // Add Nodes!
     $res_node = $link_db->query_e("SELECT * FROM {$node_table} WHERE id in (select lemma_id1 from {$edge_table}) or id in (select lemma_id2 from {$edge_table}) order by id", "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     while ($row_node = $res_node->fetch_object()) {
         $node = $xml->createElement('node');
         $node->setAttribute('id', $row_node->id);
         $node->setAttribute('label', $row_node->lemma);
         /*
                 // Set color for node
                 $color = $xml->createElement('viz:color');
                 $color->setAttribute('r', '1');
                 $color->setAttribute('g', '1');
                 $color->setAttribute('b', '1');
                 $node->appendChild($color);
         
                 // Set position for node
                 $position = $xml->createElement('viz:position');
                 $position->setAttribute('x', '1');
                 $position->setAttribute('y', '1');
                 $position->setAttribute('z', '1');
                 $node->appendChild($position);
         
                 // Set size for node
                 $size = $xml->createElement('viz:size');
                 $size->setAttribute('value', '1');
                 $node->appendChild($size);
         
                 // Set shape for node
                 $shape = $xml->createElement('viz:shape');
                 $shape->setAttribute('value', 'disc');
                 $node->appendChild($shape);
         */
         $nodes->appendChild($node);
     }
     // Add Edges
     $res_relw = $link_db->query_e("SELECT * FROM " . PWRelatedWords::getTableName() . " order by lemma_id1", "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     while ($row_relw = $res_relw->fetch_object()) {
         $edge = $xml->createElement('edge');
         $edge->setAttribute('source', $row_relw->lemma_id1);
         $edge->setAttribute('target', $row_relw->lemma_id2);
         $edge->setAttribute('weight', $row_relw->weight);
         $edges->appendChild($edge);
     }
     return $xml->saveXML();
 }
예제 #14
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()
 {
     $link_db = Piwidict::getDatabaseConnection();
     // 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());
     }
 }
예제 #15
0
 public static function DijkstraAlgorithmByDB($first, $finish)
 {
     $link_db = Piwidict::getDatabaseConnection();
     if ($first == $finish) {
         return array(0, array($first));
     }
     $edge_table = PWRelatedWords::getTableName();
     // table of related words (words and distance between them)
     $path_table = PWShortPath::getTableName();
     // table of shortest paths (first, last, next-to-last vertexes, length of path)
     //print "$first, $finish";
     $query = "SELECT lemma_id1 FROM {$edge_table} WHERE lemma_id1='{$first}' or lemma_id2='{$first}' LIMIT 1";
     // check if any edge with $first exists
     $res_exist = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     if ($link_db->query_count($res_exist) == 0) {
         return array(0, NULL);
     }
     $query = "SELECT lemma_id1 FROM {$edge_table} WHERE lemma_id1='{$finish}' or lemma_id2='{$finish}' LIMIT 1";
     // check if any edge with $finish exists
     $res_exist = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     if ($link_db->query_count($res_exist) == 0) {
         return array(0, NULL);
     }
     $success = 0;
     // the condition of finding the shortest path in the given vertex ($finish)
     $count_row = 1;
     $query = "UPDATE {$path_table} SET mark=0 where lemma_id_1=" . $first;
     // mark all vertexes as unvisited (if already any paths in DB exists)
     //        $query = "DELETE FROM $path_table where lemma_id_1=".$first; // mark all vertexes as unvisited (if already any paths in DB exists)
     $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     $prev = $first;
     $path_len = 0;
     //print "<PRE>";
     $count = 0;
     //print $first;
     //return;
     while (!$success && $count_row) {
         // until all vertixes will not be visited
         $count++;
         //  && $count<3
         print "<p>" . $count . ": " . $count_row . ".-----------------------------</p>";
         //print_r($finish_arr);
         //print_r($len_arr);
         $query = "SELECT * FROM {$edge_table} WHERE lemma_id1='{$prev}' or lemma_id2='{$prev}'";
         // search nearest vertexes to $prev (НЕТ необходимости сортировать, так как неважно в какой последовательности ставятся метки)
         $res_neib = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
         while ($row_neib = $res_neib->fetch_object()) {
             if ($row_neib->lemma_id1 == $prev) {
                 $last = $row_neib->lemma_id2;
             } else {
                 $last = $row_neib->lemma_id1;
             }
             $new_path_len = $path_len + $row_neib->weight;
             // path length from $prev to $last (neighbour of $prev via semantic relations)
             $query = "SELECT path_len,mark FROM {$path_table} WHERE lemma_id_1='{$first}' and lemma_id_n='{$last}'";
             // recounted only unvisited vertexes
             //print "<P>$query";
             $res_path = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
             if ($link_db->query_count($res_path) == 0) {
                 // 1. this is new path from $start to $finish which is absent in table pw_short_path_LANG_CODE
                 $query = "INSERT INTO {$path_table} (`lemma_id_1`, `lemma_id_n`, `path_len`, `lemma_id_prev_n`, mark) VALUES ({$first}, {$last}, {$new_path_len}, {$prev}, 0)";
                 //print "<P>$query";
                 $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
             } else {
                 // 2. already (one) path from $start to $finish does exist, then update (length and previous word) only if length of new path is shorter
                 $row_path = $res_path->fetch_object();
                 if ($row_path->mark == 0 && $new_path_len < $row_path->path_len) {
                     $query = "UPDATE {$path_table} SET path_len={$new_path_len}, lemma_id_prev_n={$prev} WHERE lemma_id_1={$first} and lemma_id_n={$last}";
                     //print "<P>$query";
                     $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
                 }
             }
         }
         $query = "SELECT path_len, lemma_id_n FROM {$path_table} WHERE lemma_id_1='{$first}' and mark=0 order by path_len";
         // choose minimal distance of path from first to any unvisited vertex
         $res_min = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
         $count_row = $link_db->query_count($res_min);
         if (!$count_row) {
             // all paths from start are marked as visited
             $path_len = 0;
         } else {
             // choose vertex with minimal distance
             $row_min = $res_min->fetch_object();
             // get only one row - minimal path length
             $path_len = $row_min->path_len;
             // choose minimal distance of path from first to any unvisited vertex
             $prev = $row_min->lemma_id_n;
             // choose unvisited vertex with minimal distance
         }
         //print "<p>prev:$prev, path_len:".$path_len;
         $query = "UPDATE {$path_table} SET mark=1 where lemma_id_1={$first} and lemma_id_n={$prev}";
         // mark vertex $prev as unvisited
         //print "<P>$query";
         $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
         if ($prev == $finish) {
             // the shortest path in $finish are found!!
             $success = 1;
         }
     }
     print "<p>{$count} iterations";
     if ($success) {
         //
         $path = array($finish);
         $prev = $finish;
         while ($prev != start) {
             $query = "SELECT lemma_id_prev_n FROM {$path_table} WHERE lemma_id_1='{$first}' and lemma_id_n='{$prev}' order by path_len LIMIT 1";
             // choose minimal distance of path from first to any unvisited vertex
             $res = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
             $row = $res->fetch_object();
             $prev = $row->lemma_id_prev_n;
             array_unshift($path, $prev);
         }
         return array($path_len, $path);
     } else {
         return array(NULL, NULL);
     }
     // any path from $first to $finish are not found
 }
예제 #16
0
<?php

use piwidict\Piwidict;
printf("<p>Page generated in %f seconds!</p>", Piwidict::getExecutionTime());
/*
if (isset($count_exec_time) && $count_exec_time) {
    $mtime = explode(" ",microtime());
    $mtime = $mtime[1] + $mtime[0];
    printf ("<p>Page generated in %f seconds!</p>", ($mtime - $tstart));
}*/
예제 #17
0
?>
>exact search</option>
	<option value='sub'<?php 
echo isset($search_type) && $search_type == 'sub' ? " selected" : '';
?>
>substring search</option>
    </select>
    <input type="submit" value="view page">
</form>
<?php 
if (isset($page_title)) {
    if (isset($search_type) && $search_type == 'sub') {
        $page_title = "%{$page_title}%";
    }
    $limit_request = 100;
    Piwidict::setLimitRequest($limit_request);
    $tpage = new TPage();
    $total_num = $tpage->countPageByTitle($page_title);
    $pageObj_arr = $tpage->getByTitle($page_title);
    if ($pageObj_arr == NULL) {
        print "<p>The word has not founded.</p>\n";
    } else {
        if ($total_num > 1) {
            print "<p>There are founded {$total_num} words.</p>\n";
            if ($limit_request > 0 && $limit_request < $total_num) {
                print "Restriction on the search for a maximum of {$limit_request} records";
            }
            //ограничение на поиск не более 100 записей
        }
        if (is_array($pageObj_arr)) {
            foreach ($pageObj_arr as $pageObj) {
예제 #18
0
 /** Gets TMeaning object by property $property_name with value $property_value.
  * @return TMeaning or NULL in case of error
  */
 public static function getMeaning($property_name, $property_value, $lang_pos_obj = NULL)
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT * FROM meaning WHERE `{$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;
     }
     $meaning_arr = array();
     while ($row = $result->fetch_object()) {
         /*
                 if ($lang_pos_obj == NULL)
                 $lang_pos_obj = TLangPOS::getByID($row->lang_pos_id);
         */
         $meaning = new TMeaning($row->id, $lang_pos_obj, $row->lang_pos_id, $row->meaning_n, TWikiText::getByID($row->wiki_text_id), $row->wiki_text_id);
         $meaning->relation = TRelation::getByMeaning($row->id, $meaning);
         $meaning->translation = TTranslation::getByMeaning($row->id, $meaning);
         $meaning->label_meaning = TLabelMeaning::getByMeaning($row->id, $meaning);
         $meaning_arr[] = $meaning;
     }
     return $meaning_arr;
 }
예제 #19
0
 /** Gets the total amount of words in LANG_CODE vocabulary
  * @return int
  */
 public static function getTotalNum()
 {
     $link_db = Piwidict::getDatabaseConnection();
     $query = "SELECT count(*) as count FROM " . self::$table_name;
     $result = $link_db->query_e($query, "Query failed in " . __METHOD__ . " in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     $row = $result->fetch_object();
     return $row->count;
 }
예제 #20
0
 /** Gets URL to Wiktionary page, where link text is explicitly given.
  * 
  * @param String $page_title Title of the Wiktionary entry
  * @param String $link_text Link text (visible text)
  * @return String HTML hyperlink
  */
 public function getURLWithLinkText(string $page_title, string $link_text = '') : string
 {
     $wikt_lang = Piwidict::getWiktLang();
     if (!$link_text) {
         $link_text = $wikt_lang . ".wiktionary.org";
     }
     // $link_text = $page_title;
     return "<a href=\"http://" . $wikt_lang . ".wiktionary.org/wiki/{$page_title}\">{$link_text}</a>";
 }
예제 #21
0
 public static function isExist($id)
 {
     $link_db = Piwidict::getDatabaseConnection();
     if ($id == '' || (int) $id != $id) {
         return false;
     }
     $query = "SELECT id FROM lang where id=" . (int) $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 false;
     }
     return true;
 }
예제 #22
0
 public static function getAllRelatedWords()
 {
     $link_db = Piwidict::getDatabaseConnection();
     $table_name = self::getTableName();
     $words = array();
     $query = "SELECT DISTINCT lemma_id1 FROM {$table_name} ORDER BY lemma_id1";
     $res_relw = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     while ($row_relw = $res_relw->fetch_object()) {
         $words[] = $row_relw->lemma_id1;
     }
     $query = "SELECT DISTINCT lemma_id2 FROM {$table_name} WHERE lemma_id2 not in (SELECT lemma_id1 FROM {$table_name}) ORDER BY lemma_id2";
     $res_relw = $link_db->query_e($query, "Query failed in file <b>" . __FILE__ . "</b>, string <b>" . __LINE__ . "</b>");
     while ($row_relw = $res_relw->fetch_object()) {
         $words[] = $row_relw->lemma_id2;
     }
     return $words;
 }
예제 #23
0
*/
// input file structure:
// word | RNC (Russian National Corpus) number of occurences| GBN (Google Books Ngram) the same
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");
$search_words = file('ru.Wikt_uniq-lemas_with-freq.txt');
$RNC_num = $GBN_num = array();
for ($i = 0; $i < sizeof($search_words); $i++) {
    $word = trim($search_words[$i]);
    $word_stats = preg_split("/\\|/", $word);
    $search_words[$i] = $word_stats[0];
    $RNC_num[$word_stats[0]] = $word_stats[1];
    $GBN_num[$word_stats[0]] = $word_stats[2];
}
$unfound_words = $search_words = array_flip($search_words);
/*
ksort($search_words);
print "<PRE>";
print_r($search_words);
예제 #24
0
 /** Gets array of TLangPOS objects by property $property_name with value $property_value.
  * @return array[TLangPOS] or empty array in case of error
  */
 public static function getLangPOS(string $property_name, string $property_value, TPage $page_obj = NULL) : array
 {
     $link_db = Piwidict::getDatabaseConnection();
     $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 array();
     }
     $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;
 }