blob: ef80bf014811c158c4428a9ab0e16dddbdf8e584 [file] [log] [blame]
Marc Kupietzdc22b982015-10-09 09:19:34 +02001#!/usr/local/bin/perl
Marc Kupietzf11d20c2019-08-02 15:42:04 +02002use Inline C => "./w2v-server.c" => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1, ccflags => $Config{ccflags}." -I/vol/work/kupietz/Work2/kl/trunk/CollocatorDB -I, -L. -Wall -O4", libs => "-shared -lpthread -lcollocatordb -lrt -lsnappy -lz -lbz2 -llz4 -lzstd -lrocksdb -lgomp";
Marc Kupietza5f60042017-05-04 10:38:12 +02003#use Inline C => Config => BUILD_NOISY => 1, CFLAGS => $Config{cflags}." -O4 -mtune k9";
4#use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -Ofast -march k8 -mtune k8 ";
Marc Kupietzdc22b982015-10-09 09:19:34 +02005use Mojolicious::Lite;
Marc Kupietzc4893362016-02-25 08:04:46 +01006use Mojo::JSON qw(decode_json encode_json to_json);
Marc Kupietz30ca4342017-11-22 21:21:20 +01007use base 'Mojolicious::Plugin';
8
Marc Kupietz247500f2015-10-09 11:29:01 +02009use Encode qw(decode encode);
Marc Kupietza5b90152016-03-15 17:39:19 +010010use Getopt::Std;
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010011use Mojo::Server::Daemon;
Marc Kupietzffef9302017-11-07 15:58:01 +010012use Cwd;
Marc Kupietz66bfd952017-12-11 09:59:45 +010013
Marc Kupietzffef9302017-11-07 15:58:01 +010014app->static->paths->[0] = getcwd;
15
Marc Kupietz1b856fa2019-12-07 23:01:43 +010016plugin Config => {file => 'w2v-server.conf'};
17plugin 'Piwik';
18plugin 'Util::RandomString' => {
19 piwik_rand_id => {
20 alphabet => '0123456789abcdef',
21 length => 16
22 }
23};
24
Marc Kupietzd4227392016-03-01 16:45:12 +010025plugin 'Log::Access';
Marc Kupietzb3422c12017-07-04 14:12:11 +020026plugin "RequestBase";
Marc Kupietz95104512019-12-05 10:13:05 +010027#plugin 'AutoReload';
28plugin Localize => {
29 dict => {
30 _ => sub { $_->locale },
31 },
32 resources => ['w2v-server.dict']
33};
Marc Kupietza5b90152016-03-15 17:39:19 +010034our $opt_i = 0; # latin1-input?
35our $opt_l = undef;
36our $opt_p = 5676;
Marc Kupietza2e64502016-04-27 09:53:51 +020037our $opt_m;
Marc Kupietz6ed81872016-04-27 14:04:04 +020038our $opt_M;
Marc Kupietz43ee87e2016-04-25 10:50:08 +020039our $opt_n = '';
40our $opt_d;
Marc Kupietzfa194262018-06-05 09:39:32 +020041our $opt_D;
Marc Kupietz5c3887d2016-04-28 08:53:35 +020042our $opt_G;
Marc Kupietza5b90152016-03-15 17:39:19 +010043
Marc Kupietz6ed81872016-04-27 14:04:04 +020044my %marked;
Marc Kupietzc053d972019-01-10 10:41:51 +010045my $title="";
Marc Kupietz793413b2016-04-02 21:48:57 +020046my $training_args="";
Marc Kupietza2e64502016-04-27 09:53:51 +020047my $mergedEnd=0;
Marc Kupietz15987412017-11-07 15:56:58 +010048my %cache;
Marc Kupietz19c68242018-03-12 09:42:21 +010049my %cccache; # classic collocator cache
Marc Kupietza51dcfa2018-03-19 16:22:05 +010050my %spcache; # similar profile cache
Marc Kupietz793413b2016-04-02 21:48:57 +020051
Marc Kupietzfa194262018-06-05 09:39:32 +020052getopts('d:D:Gil:p:m:n:M:');
Marc Kupietz6ed81872016-04-27 14:04:04 +020053
54if($opt_M) {
Marc Kupietzed930212016-04-27 15:42:38 +020055 open my $handle, '<:encoding(UTF-8)', $opt_M
56 or die "Can't open '$opt_M' for reading: $!";
57 while(<$handle>) {
Marc Kupietz6ed81872016-04-27 14:04:04 +020058 foreach my $mw (split /\s+/) {
59 $marked{$mw}=1
60 }
61 }
Marc Kupietzed930212016-04-27 15:42:38 +020062 close($handle);
Marc Kupietz6ed81872016-04-27 14:04:04 +020063}
Marc Kupietza5b90152016-03-15 17:39:19 +010064
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010065# -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
Marc Kupietza5b90152016-03-15 17:39:19 +010066if(!$ARGV[0]) {
Marc Kupietz6b2975c2016-03-18 21:59:33 +010067 init_net("vectors15.bin", $opt_n, ($opt_i? 1 : 0));
Marc Kupietz2cb667e2016-03-10 09:44:12 +010068} else {
Marc Kupietz6b2975c2016-03-18 21:59:33 +010069 init_net($ARGV[0], $opt_n, ($opt_i? 1 : 0));
Marc Kupietz793413b2016-04-02 21:48:57 +020070 if(open(FILE, "$ARGV[0].args")) {
71 $training_args = <FILE>;
72 }
73 close(FILE);
Marc Kupietzc053d972019-01-10 10:41:51 +010074 $title = fname2corpusname($ARGV[0]);
Marc Kupietz2cb667e2016-03-10 09:44:12 +010075}
Marc Kupietzdc22b982015-10-09 09:19:34 +020076
Marc Kupietza51dcfa2018-03-19 16:22:05 +010077my $have_sprofiles = load_sprofiles($ARGV[0]);
78
Marc Kupietza2e64502016-04-27 09:53:51 +020079if($opt_m) {
80 $mergedEnd = mergeVectors($opt_m);
Marc Kupietzc053d972019-01-10 10:41:51 +010081 $title = "<span class=\"merged\">" . $title . "</span> vs. " . fname2corpusname($opt_m);
Marc Kupietza2e64502016-04-27 09:53:51 +020082}
83
Marc Kupietze5568a02018-12-20 11:42:02 +010084
Marc Kupietz43ee87e2016-04-25 10:50:08 +020085if($opt_d) { # -d: dump vecs and exit
86 dump_vecs($opt_d);
87 exit;
88}
89
Marc Kupietzfa194262018-06-05 09:39:32 +020090if($opt_D) { # -D: dump vecs for numpy and exit
91 dump_for_numpy($opt_D);
92 exit;
93}
94
Marc Kupietza5b90152016-03-15 17:39:19 +010095my $daemon = Mojo::Server::Daemon->new(
96 app => app,
97 listen => ['http://'.($opt_l ? $opt_l : '*').":$opt_p"]
98);
99
Marc Kupietz5c3887d2016-04-28 08:53:35 +0200100if($opt_G) {
101 print "Filtering garbage\n";
102 filter_garbage();
103}
104
Marc Kupietz554aff52017-11-09 14:42:09 +0100105get '*/js/*' => sub {
Marc Kupietzffef9302017-11-07 15:58:01 +0100106 my $c = shift;
107 my $url = $c->req->url;
108 $url =~ s@/derekovecs@@g;
109 $c->app->log->info("GET: " . $url);
110 $c->reply->static($url);
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100111} => 'js';
Marc Kupietzffef9302017-11-07 15:58:01 +0100112
Marc Kupietza9270572018-03-17 15:17:07 +0100113get '*/css/*' => sub {
114 my $c = shift;
115 my $url = $c->req->url;
116 $url =~ s@/derekovecs/@/@g;
117 $c->app->log->info("GET: " . $url);
118 $c->reply->static($url);
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100119} => 'css';
Marc Kupietza9270572018-03-17 15:17:07 +0100120
Marc Kupietzc053d972019-01-10 10:41:51 +0100121sub fname2corpusname {
122 ($_) = @_;
123 s@.*/@@;
Marc Kupietz86b50292019-02-17 21:03:59 +0100124 s@\.en@-en@;
Marc Kupietzc053d972019-01-10 10:41:51 +0100125 s@\..*@@;
126 return $_;
127}
128
Marc Kupietzcb43e492019-12-03 10:07:53 +0100129sub getWord {
130 ($_) = @_;
131 if ($_ =~ /^\d+/) {
132 return $_;
133 } else {
134 return getWordNumber($_);
135 }
136}
137
Marc Kupietz19c68242018-03-12 09:42:21 +0100138sub getClassicCollocatorsCached {
139 my ($c, $word) = @_;
Marc Kupietz81aeed22019-02-17 21:22:45 +0100140 my $s2 = "";
Marc Kupietz9ff3c992019-02-04 12:32:54 +0100141 if($word > $mergedEnd) {
142 $word-=$mergedEnd;
143 }
Marc Kupietz81aeed22019-02-17 21:22:45 +0100144
Marc Kupietz999ab8c2019-02-17 21:42:21 +0100145 if($opt_p >= 5000 && $opt_p < 5600) { # German non-reference
Marc Kupietz9ee3f412019-08-02 14:58:19 +0200146 open PIPE, "GET http://compute:5673/getClassicCollocators?w=$word |" or
147 open PIPE, "GET http://klinux10:5673/getClassicCollocators?w=$word |";
Marc Kupietz999ab8c2019-02-17 21:42:21 +0100148 }
Marc Kupietz19c68242018-03-12 09:42:21 +0100149 if(!$cccache{$word}) {
Marc Kupietz06d61292019-02-04 12:33:22 +0100150 $c->app->log->info("Getting classic collocates of $word.");
Marc Kupietz19c68242018-03-12 09:42:21 +0100151 $cccache{$word} = getClassicCollocators($word);
Marc Kupietz1d96a082019-02-18 09:29:06 +0100152 $cccache{$word} =~ s/:(-?)(nan|inf)/:"${1}${2}"/g;
Marc Kupietz19c68242018-03-12 09:42:21 +0100153 } else {
Marc Kupietz06d61292019-02-04 12:33:22 +0100154 $c->app->log->info("Getting classic collocates for $word from cache.");
Marc Kupietz19c68242018-03-12 09:42:21 +0100155 }
Marc Kupietz81aeed22019-02-17 21:22:45 +0100156 if($opt_p >= 5000 && $opt_p < 5600) { # German non-reference
Marc Kupietz999ab8c2019-02-17 21:42:21 +0100157 while(<PIPE>) {
158 $s2 .= $_;
159 }
160 close(PIPE);
Marc Kupietz81aeed22019-02-17 21:22:45 +0100161 }
Marc Kupietz999ab8c2019-02-17 21:42:21 +0100162
Marc Kupietz81aeed22019-02-17 21:22:45 +0100163 if(length($s2) > 2000) {
164 my $d1 = decode_json($cccache{$word});
165 my $d2 = decode_json($s2);
166 my %d2ld;
Marc Kupietz001bffd2019-02-21 08:52:41 +0100167 my $minLd = 14;
Marc Kupietz81aeed22019-02-17 21:22:45 +0100168 foreach my $i (@{$d2->{collocates}}) {
169 $d2ld{$i->{word}}=$i->{ld};
Marc Kupietz001bffd2019-02-21 08:52:41 +0100170 $minLd=$i->{ld} if($i->{ld} < $minLd);
Marc Kupietz81aeed22019-02-17 21:22:45 +0100171 }
172 foreach my $i (@{$d1->{collocates}}) {
173 my $w = $i->{word};
Marc Kupietz001bffd2019-02-21 08:52:41 +0100174 $i->{delta} = $i->{ld} - (defined $d2ld{$w} ? $d2ld{$w} : $minLd-0.1);
Marc Kupietz81aeed22019-02-17 21:22:45 +0100175 }
176 return(encode_json($d1));
177 } else {
178 my $d1 = decode_json($cccache{$word});
179 foreach my $i (@{$d1->{collocates}}) {
180 $i->{delta} = 0;
181 }
182 return(encode_json($d1));
183 }
Marc Kupietz19c68242018-03-12 09:42:21 +0100184}
185
Marc Kupietza51dcfa2018-03-19 16:22:05 +0100186sub getSimilarProfilesCached {
187 my ($c, $word) = @_;
188 if(!$spcache{$word}) {
189 $spcache{$word} = getSimilarProfiles($word);
190 } else {
191 $c->app->log->info("Getting similar profiles for $word from cache:");
Marc Kupietza51dcfa2018-03-19 16:22:05 +0100192 }
193 return $spcache{$word};
194}
195
Marc Kupietz66bfd952017-12-11 09:59:45 +0100196post '/derekovecs/getVecsByRanks' => sub {
197 my $self = shift;
198 my $vec = getVecs($self->req->json);
199 $self->render(json => $vec);
200};
201
Marc Kupietze13a3552018-01-25 08:48:34 +0100202any '*/getClassicCollocators' => sub {
Marc Kupietze243efd2018-01-11 22:19:24 +0100203 my $self = shift;
Marc Kupietzcb43e492019-12-03 10:07:53 +0100204 $self->render(data => getClassicCollocatorsCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100205} => 'getClassicCollocators1';
Marc Kupietze243efd2018-01-11 22:19:24 +0100206
Marc Kupietze13a3552018-01-25 08:48:34 +0100207any '/getClassicCollocators' => sub {
Marc Kupietze243efd2018-01-11 22:19:24 +0100208 my $self = shift;
Marc Kupietzcb43e492019-12-03 10:07:53 +0100209 $self->render(data => getClassicCollocatorsCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100210} => 'getClassicCollocators';
Marc Kupietze243efd2018-01-11 22:19:24 +0100211
Marc Kupietzd7760b42019-02-21 09:01:44 +0100212any '/getBiggestVocabDistances' => sub {
213 my $self = shift;
214 $self->render(data => getBiggestMergedDifferences(), format=>'json');
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100215} => 'getBiggestVocabDistances1';
Marc Kupietzd7760b42019-02-21 09:01:44 +0100216
217any '*/getBiggestVocabDistances' => sub {
218 my $self = shift;
219 $self->render(data => getBiggestMergedDifferences(), format=>'json');
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100220} => 'getBiggestVocabDistances';
Marc Kupietzd7760b42019-02-21 09:01:44 +0100221
Marc Kupietz33c79d32019-08-02 15:11:23 +0200222any '*/getPosWiseW2VCollocators' => sub {
223 my $self = shift;
224 $self->render(data => getPosWiseW2VCollocatorsAsTsv($self->param("w"),
225 ($self->param("max")? $self->param("max") : 200),
226 ($self->param("cutoff")? $self->param("cutoff") :750000),
227 ($self->param("threshold")? $self->param("threshold") : 0.2)),
228 format=>'tsv');
229};
230
231any '/getPosWiseW2VCollocators' => sub {
232 my $self = shift;
233 $self->render(data => getPosWiseW2VCollocatorsAsTsv($self->param("w"),
234 ($self->param("max")? $self->param("max") : 200),
235 ($self->param("cutoff")? $self->param("cutoff") : 750000),
236 ($self->param("threshold")? $self->param("threshold") : 0.2)),
237 format=>'tsv');
238};
239
Marc Kupietza51dcfa2018-03-19 16:22:05 +0100240any '*/getSimilarProfiles' => sub {
241 my $self = shift;
Marc Kupietzcb43e492019-12-03 10:07:53 +0100242 $self->render(data => getSimilarProfilesCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
Marc Kupietza51dcfa2018-03-19 16:22:05 +0100243};
244
Marc Kupietzc987fa82018-03-21 12:14:25 +0100245any '/getSimilarProfiles' => sub {
246 my $self = shift;
Marc Kupietzcb43e492019-12-03 10:07:53 +0100247 $self->render(data => getSimilarProfilesCached($self, getWord($self->param("w") ? $self->param("w") : $self->req->json)), format=>'json');
Marc Kupietzc987fa82018-03-21 12:14:25 +0100248};
249
Marc Kupietz98ed1c02019-08-02 15:05:37 +0200250any '/getSimilarity' => sub {
251 my $self = shift;
252 my $w1 = $self->param("w1");
253 my $w2 = $self->param("w2");
254 $self->render(data => cos_similarity_as_json($w1, $w2), format=>'json');
255};
256
257any '*/getSimilarity' => sub {
258 my $self = shift;
259 my $w1 = $self->param("w1");
260 my $w2 = $self->param("w2");
261 $self->render(data => cos_similarity_as_json($w1, $w2), format=>'json');
262};
263
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100264get '*/img/*' => sub {
265 my $c = shift;
266 my $url = $c->req->url;
267 $url =~ s@/derekovecs@@g;
268 $c->app->log->info("GET: " . $url);
269 $c->reply->static($url);
270};
271
Marc Kupietzdc22b982015-10-09 09:19:34 +0200272get '/' => sub {
273 my $c = shift;
Marc Kupietza5f60042017-05-04 10:38:12 +0200274 $c->app->log->info("get: ".$c->req->url->to_abs);
Marc Kupietzdc22b982015-10-09 09:19:34 +0200275 my $word=$c->param('word');
Marc Kupietz2da2a812019-02-21 14:17:35 +0100276 my $no_nbs=$c->param('n') || ($opt_m? 50 : 100);
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100277 my $no_iterations=$c->param('N') || 2000;
Marc Kupietzd4227392016-03-01 16:45:12 +0100278 my $perplexity=$c->param('perplexity') || 20;
Marc Kupietzc4d62f82016-03-01 11:04:24 +0100279 my $epsilon=$c->param('epsilon') || 5;
Marc Kupietzd7aea722016-03-02 11:59:12 +0100280 my $som=$c->param('som') || 0;
Marc Kupietza2e64502016-04-27 09:53:51 +0200281 my $searchBaseVocabFirst=$c->param('sbf') || 0;
Marc Kupietz6d9a6782016-03-23 17:25:25 +0100282 my $sort=$c->param('sort') || 0;
Marc Kupietzc469f3b2017-11-13 14:07:36 +0100283 my $csv=$c->param('csv') || 0;
Marc Kupietzb613b052016-04-28 14:11:59 +0200284 my $json=$c->param('json') || 0;
Marc Kupietzdb2dc7e2017-12-02 12:04:03 +0100285 my $cutoff=$c->param('cutoff') || 500000;
Marc Kupietzd91212f2017-11-13 10:05:09 +0100286 my $dedupe=$c->param('dedupe') || 0;
Marc Kupietzac707b32018-12-20 11:36:38 +0100287 my $nosp=$c->param('nosp') || 0;
Marc Kupietz6b2975c2016-03-18 21:59:33 +0100288 my $res;
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100289 my @lists;
Marc Kupietz6b2975c2016-03-18 21:59:33 +0100290 my @collocations;
Marc Kupietzcddc8482019-12-04 08:57:33 +0100291 if(defined($word) && $word !~ /^\s*$/) {
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100292 $c->inactivity_timeout(300);
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100293 $word =~ s/\s+/ /g;
Marc Kupietz3082fd02019-01-09 14:54:06 +0100294 if($opt_m && $word !~ /\|/) {
295 $word .= "|$word";
296 }
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100297 for my $w (split(' *\| *', $word)) {
Marc Kupietz3082fd02019-01-09 14:54:06 +0100298 if($opt_m) {
299 if($searchBaseVocabFirst) {
300 $searchBaseVocabFirst=0;
301 } else {
302 $searchBaseVocabFirst=1;
303 }
304 }
305 if ($cache{$w.$cutoff.$no_nbs.$sort.$dedupe,$searchBaseVocabFirst}) {
Marc Kupietz15987412017-11-07 15:56:58 +0100306 $c->app->log->info("Getting $w results from cache");
Marc Kupietz3082fd02019-01-09 14:54:06 +0100307 $res = $cache{$w.$cutoff.$no_nbs.$sort.$dedupe.$searchBaseVocabFirst}
Marc Kupietza5b90152016-03-15 17:39:19 +0100308 } else {
Marc Kupietz15987412017-11-07 15:56:58 +0100309 $c->app->log->info('Looking for neighbours of '.$w);
310 if($opt_i) {
Marc Kupietzac707b32018-12-20 11:36:38 +0100311 $res = get_neighbours(encode("iso-8859-1", $w), $no_nbs, $sort, $searchBaseVocabFirst, $cutoff, $dedupe, $nosp);
Marc Kupietz15987412017-11-07 15:56:58 +0100312 } else {
Marc Kupietzac707b32018-12-20 11:36:38 +0100313 $res = get_neighbours($w, $no_nbs, $sort, $searchBaseVocabFirst, $cutoff, $dedupe, $nosp);
Marc Kupietz15987412017-11-07 15:56:58 +0100314 }
Marc Kupietz2dd2dd72017-12-01 22:08:14 +0100315 $cache{$w.$cutoff.$no_nbs.$sort.$dedupe} = $res;
Marc Kupietza5b90152016-03-15 17:39:19 +0100316 }
Marc Kupietz6b2975c2016-03-18 21:59:33 +0100317 push(@lists, $res->{paradigmatic});
Marc Kupietz15987412017-11-07 15:56:58 +0100318 }
319 }
Marc Kupietz56844a22019-08-02 15:12:19 +0200320
Marc Kupietz000ad862016-02-26 14:59:12 +0100321 $word =~ s/ *\| */ | /g;
Marc Kupietzb613b052016-04-28 14:11:59 +0200322 if($json) {
323 return $c->render(json => {word => $word, list => \@lists, collocators=>$res->{syntagmatic}});
Marc Kupietzc469f3b2017-11-13 14:07:36 +0100324 } elsif($csv) {
325 my $csv_data="";
326 for (my $i=0; $i <= $no_nbs; $i++) {
327 $csv_data .= $res->{paradigmatic}->[$i]->{word} . ", ";
328 }
329 for (my $i=0; $i < $no_nbs; $i++) {
330 $csv_data .= $res->{syntagmatic}->[$i]->{word} . ", ";
331 }
332 chop $csv_data;
333 chop $csv_data;
334 $csv_data .= "\n";
335 return $c->render(text=>$csv_data);
Marc Kupietzb613b052016-04-28 14:11:59 +0200336 } else {
Marc Kupietzd7760b42019-02-21 09:01:44 +0100337 my $distantWords="";
338 if(!defined($word) || $word !~ /^\s*$/) {
339 $distantWords = getBiggestMergedDifferences();
340 }
341 $c->render(template=>"index", title=>$title, word=>$word, distantWords=>$distantWords, cutoff=>$cutoff, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, searchBaseVocabFirst=>$searchBaseVocabFirst, sort=>$sort, training_args=>$training_args, mergedEnd=> $mergedEnd, haveSProfiles=> $have_sprofiles, dedupe=> $dedupe, marked=>\%marked, lists=> \@lists, collocators=> $res->{syntagmatic});
Marc Kupietzb613b052016-04-28 14:11:59 +0200342 }
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100343} => "paradigmaticAndSyntagmaticNbs";
Marc Kupietzdc22b982015-10-09 09:19:34 +0200344
Marc Kupietz30ca4342017-11-22 21:21:20 +0100345helper(bitvec2window => sub {
346 my ($self, $n) = @_;
347 my $str = unpack("B32", pack("N", $n));
348 $str =~ s/^\d{22}//;
349 $str =~ s/^(\d{5})/$1x/;
350 $str =~ s/0/ยท/g;
351 $str =~ s/1/+/g;
352 return $str;
353 });
354
Marc Kupietz1b856fa2019-12-07 23:01:43 +0100355hook(
356 after_render => sub {
357 my $c = shift;
358
359 # Only track valid routes
360 my $route = $c->current_route or return;
361
362 # This won't forward personalized information
363 my $hash = {
364 action_url => $c->url_for->to_abs,
365 action_name => $route,
366 ua => '',
367 urlref => '',
368 send_image => 0,
369 dnt => 0,
370 uid => $c->random_string('piwik_rand_id')
371 };
372 $c->app->log->info("PIWIK: counting " . $hash->{action_url});
373 $c->app->log->info("PIWIK: tag " . $c->piwik_tag);
374
375 # Send track
376 $c->piwik->api_p(Track => $hash)->wait;
377 }
378);
379
Marc Kupietz95104512019-12-05 10:13:05 +0100380$daemon->run;
381# app->start;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200382
Marc Kupietz95104512019-12-05 10:13:05 +0100383# exit;