コード例 #1
0
ファイル: TRelation.php プロジェクト: componavt/piwidict
 /** Gets list of semantically related words.
  * If page title is not exist, then return empty array.
  * @return array, where keys are related words, values are arrays of their relation type names
  */
 public static function getPageRelations($page_title)
 {
     $relations = array();
     // return array, if exact search then returns only one word
     list($page_obj) = TPage::getByTitle($page_title);
     $lang_pos_arr = $page_obj->getLangPOS();
     if (is_array($lang_pos_arr)) {
         foreach ($lang_pos_arr as $lang_pos_obj) {
             $meaning_arr = $lang_pos_obj->getMeaning();
             if (is_array($meaning_arr)) {
                 foreach ($meaning_arr as $meaning_obj) {
                     $relation_arr = $meaning_obj->getRelation();
                     if (is_array($relation_arr)) {
                         foreach ($relation_arr as $relation_obj) {
                             $relations[$relation_obj->getWikiText()->getText()][] = $relation_obj->getRelationType()->getName();
                         }
                     }
                 }
             }
         }
     }
     ksort($relations);
     return $relations;
 }
コード例 #2
0
ファイル: TLangPOS.php プロジェクト: componavt/piwidict
 /** 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;
 }