Skip to content

Commit 84341e4

Browse files
committed
strange antonym generator
1 parent 9863df7 commit 84341e4

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?
2+
/*
3+
This script generates
4+
the list of antonyms for nouns, verbs, adjectives, adverbs
5+
Only for Russian entries.
6+
* Restrictions:
7+
* - synset size >= 3
8+
* - skip multiword expressions
9+
10+
For example,
11+
in the article "tree" there are
12+
* "sapling, seedling" in Synonyms section;
13+
* "plant" in Hyperonyms section;
14+
* "oak, birch, maple, fir, pine" in Hyponyms section
15+
16+
then the following line will be generated:
17+
18+
1) first file with only synonyms
19+
tree sapling seedling
20+
21+
2) second file with all relations
22+
tree sapling seedling plant oak birch maple fir pine
23+
24+
*/
25+
$count_exec_time = 1;
26+
include("../../../config.php");
27+
include(LIB_DIR."header.php");
28+
29+
$pos_name = "adjective";
30+
$lang_id = TLang::getIDByLangCode("ru");
31+
$pos_id = TPOS::getIDByName($pos_name);
32+
$syn_id = TRelationType::getIDByName("synonyms");
33+
34+
$fh1 = fopen('synset_synonyms_only_'.$pos_name.'.txt','w');
35+
$fh2 = fopen('synset_all_relations_'.$pos_name.'.txt','w');
36+
37+
$query = "SELECT page_title as first_word, meaning.id as meaning_id
38+
FROM lang_pos, meaning, page
39+
WHERE lang_pos.id = meaning.lang_pos_id
40+
AND page.id = lang_pos.page_id
41+
AND page_title NOT LIKE '% %'
42+
AND lang_id = $lang_id
43+
AND pos_id=$pos_id
44+
ORDER BY page_title";
45+
46+
$result_meaning = $LINK_DB -> query_e($query,"Query failed in file <b>".__FILE__."</b>, string <b>".__LINE__."</b>");
47+
48+
while ($row = $result_meaning -> fetch_object()) {
49+
50+
$query = "SELECT wiki_text.text as relation_word, relation_type_id
51+
FROM wiki_text, relation
52+
WHERE relation.wiki_text_id=wiki_text.id
53+
AND wiki_text.text NOT LIKE '% %'
54+
AND relation.meaning_id = ".$row->meaning_id.
55+
" ORDER BY wiki_text.text";
56+
57+
$result_relation = $LINK_DB -> query_e($query,"Query failed in file <b>".__FILE__."</b>, string <b>".__LINE__."</b>");
58+
59+
$num = $LINK_DB -> query_count($result_relation);
60+
61+
if ($num > 1) {
62+
$synonyms = array();
63+
fwrite($fh2, $row->first_word);
64+
65+
while ($row_relation = $result_relation -> fetch_object()) {
66+
fwrite($fh2, ' '. $row_relation->relation_word);
67+
if ($row_relation->relation_type_id == $syn_id)
68+
$synonyms[] = $row_relation->relation_word;
69+
}
70+
fwrite($fh2, "\n");
71+
if (sizeof($synonyms)>1)
72+
fwrite($fh1, $row->first_word. ' '. join(' ', $synonyms)."\n");
73+
}
74+
}
75+
76+
fclose($fh1);
77+
fclose($fh2);
78+
include(LIB_DIR."footer.php");
79+
?>
80+
<p>done.

0 commit comments

Comments
 (0)