public static function meaningsToLemmas($word)
 {
     $word_obj_arr = PWLemma::getByLemma($word);
     $words = array();
     foreach ($word_obj_arr as $word_obj) {
         if ($word_obj->getOrigin() > 0) {
             // The page $word does not exist in LANG_CODE.wiktionary.org
             continue;
         }
         $page_id = $word_obj->getID();
         // if origin=0 then word is added from wiktionary, and lemma.id = page.id
         $meaning_arr = TMeaning::getByPageAndLang($page_id, PWLemma::getLangCode());
         foreach ($meaning_arr as $meaning_obj) {
             $meaning_wiki_text = $meaning_obj->getWikiText();
             $meaning_text = $meaning_wiki_text->getText();
             //                $words = array_merge($words,preg_split('/\P{L}+/u', $meaning_text, -1, PREG_SPLIT_NO_EMPTY));
             $words = array_merge($words, preg_split('/((^\\p{P}+)|(\\p{P}*\\s+\\p{P}*)|(\\p{P}+$))/u', $meaning_text, -1, PREG_SPLIT_NO_EMPTY));
         }
     }
     return $words;
 }
Example #2
0
 /** Gets text of meaning by ID
  * @return String or NULL in case of error
  */
 public static function getMeaningByID($_id)
 {
     list($meaning_obj) = TMeaning::getMeaning("id", $_id);
     $wiki_text_obj = $meaning_obj->wiki_text;
     if ($wiki_text_obj !== NULL) {
         return $wiki_text_obj->getText();
     }
     return NULL;
 }
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.
Example #4
0
 /** Gets TLangPOS object by property $property_name with value $property_value.
  * @return TLangPOS or NULL in case of error
  */
 public static function getLangPOS($property_name, $property_value, $page_obj = NULL)
 {
     global $LINK_DB;
     $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 NULL;
     }
     $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;
 }