-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil_dumpnavisql.pl
139 lines (120 loc) · 5.52 KB
/
util_dumpnavisql.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/perl
#------------------------------------------------------------------------------
# mwForum - Web-based discussion forum
# Copyright (c) 1999-2009 Markus Wichitill
#
# util_dumpnavisql.pl
# Copyright (c) 2010 Tobias Jaeggi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#------------------------------------------------------------------------------
use strict;
use warnings;
no warnings qw(uninitialized once);
# Imports
use MwfMain;
use Data::Dumper;
use utf8;
# Init
my ($m, $cfg, $lng) = MwfMain->newShell();
# We'll save the data in this field.
my @metaWords;
my @localizedWords;
# Get the available types.
my @types = map { $_->[0] } @{$m->fetchAllArray('SELECT DISTINCT(type) FROM dictWordMeta')};
# and blocks
my @blocks = map { $_->[0] } @{$m->fetchAllArray('SELECT DISTINCT(block) FROM dictWordMeta')};
# Now, for each block
# We only dump up to five words per block and type.
for my $block (@blocks) {
# Get one of these words.
for my $type (@types) {
my $results = $m->fetchAllHash('SELECT * FROM dictWordMeta WHERE block = ? && type = ? LIMIT 5', $block, $type);
next if !$results;
for my $result (@$results) {
push @metaWords, $result;
my $localizedResults = $m->fetchAllHash('SELECT * FROM dictWordLoc WHERE id = ?', $result->{id});
push @localizedWords, $_ for (@$localizedResults);
}
}
}
# Full data: Infixes (and other stuff, but we call it 'infixes'.)
#~ "SELECT * FROM dictWordMeta WHERE block = 3 || block = 4 || type = 'pcw' || type = 'pderives'"
my $infixes = $m->fetchAllHash("
SELECT *
FROM dictWordMeta
WHERE (
(`type` = 'infix' || `type` = 'infixcw') && block = 2)
||
(block = 3 || block = 4 || type = 'pcw' || type = 'pderives')
||
(id = 294 || id = 511 || id = 556)
");
for my $infix (@$infixes) {
push @metaWords, $infix;
my $localizedInfixes = $m->fetchAllHash('SELECT * FROM dictWordLoc WHERE id = ?', $infix->{id});
push @localizedWords, $_ for (@$localizedInfixes);
}
# Throw out duplicates
{
my %metafound;
@metaWords = grep { !$metafound{$_->{id}}++ } @metaWords;
my %localizedfound;
@localizedWords = grep { !$localizedfound{$_->{id}.$_->{lc}}++ } @localizedWords;
}
print "Got ", scalar @metaWords, " Metawords and ", scalar @localizedWords, " localized words.\n";
# Now we create SQL out of it. More or less.
open my $FH, '>', 'data.sql';
binmode $FH, ':utf8';
print $FH <<EOD;
-- data.sql, part of Eana Eltu by Tobias Jaeggi (Tuiq, tuiq at clonk2c dot ch), Richard Littauer (Taronyu, richard\@learnnavi.org) and others is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License ( http://creativecommons.org/licenses/by-nc-sa/3.0/ ).
-- The full license text is available at http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode .
-- This SQL does not contain the whole database but is enough to keep coders running. It's about 1/10 of the complete database.
CREATE TABLE IF NOT EXISTS `dictWordLoc`(`id` int(11) NOT NULL,`arg1` text,`arg2` text,`arg3` text,`arg4` text,`arg5` text,`arg6` text,`arg7` text,`arg8` text,`arg9` text,`arg10` text,`odd` text,`lc` char(5) character set latin1 NOT NULL,`editTime` int(11) NOT NULL,UNIQUE KEY `id` (`id`,`lc`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `dictWordMeta` (`id` int(11) NOT NULL auto_increment,`type` char(50) NOT NULL,`arg1` text NOT NULL,`arg2` text NOT NULL,`arg3` text NOT NULL,`arg4` text NOT NULL,`arg5` text NOT NULL,`arg6` text NOT NULL,`arg7` text NOT NULL,`arg8` text NOT NULL,`arg9` text NOT NULL,`arg10` text NOT NULL,`odd` text NOT NULL,`block` tinyint(4) NOT NULL,`editTime` int(11) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `dictLanguages` (`lc` char(5) character set utf8 NOT NULL,`engName` varchar(20) character set utf8 NOT NULL,`nativeName` varchar(20) character set utf8 NOT NULL,`active` tinyint(1) NOT NULL,PRIMARY KEY (`lc`));
CREATE TABLE IF NOT EXISTS `wordLookup` (`text` varchar(250) NOT NULL,`lc` char(100) NOT NULL,`time` int(11) NOT NULL);
TRUNCATE TABLE `dictWordMeta`;
TRUNCATE TABLE `dictWordLoc`;
TRUNCATE TABLE `dictLanguages`;
EOD
for my $word (@metaWords) {
print $FH "INSERT INTO `dictWordMeta` SET ";
# Magic! Voodoo! Call it what you want.
print $FH join(',', map { "`$_`=" . $m->{dbh}->quote($word->{$_}) } keys %$word);
print $FH ";\n";
}
# Ctrl-D
for my $word (@localizedWords) {
print $FH "INSERT INTO `dictWordLoc` SET ";
# Magic! Voodoo! Call it what you want.
print $FH join(',', map { "`$_`=" . $m->{dbh}->quote($word->{$_}) } keys %$word);
print $FH ";\n";
}
print $FH <<EOD;
INSERT INTO `dictLanguages` (`lc`, `engName`, `nativeName`, `active`) VALUES
('de', 'German', 'Deutsch', 1),
('hu', 'Hungarian', 'Magyar', 1),
('est', 'Estonian', 'Eesti', 1),
('ptbr', 'Portuguese', 'Portoguês', 1),
('es', 'Spanish', 'Español', 0),
('fi', 'Finnish', 'Suomi', 0),
('zhcn', 'Simplified Chinese', '简体字', 0),
('nav', 'Na''vi', 'Na''vi', 0),
('nl', 'Dutch', 'Nederlands', 0),
('pl', 'Polish', 'Polski', 0),
('ru', 'Russian', 'Русский', 0),
('sv', 'Swedish', 'Svenska', 1);
EOD
;
close $FH;
$m->finish();
print "Done.\n";