Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
Marc Kupietz | 043db15 | 2023-11-05 17:47:53 +0100 | [diff] [blame^] | 3 | use Test::More tests=>8; |
Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame] | 4 | use Mojo::JSON qw(decode_json encode_json to_json); |
| 5 | use REST::Client; |
| 6 | use Data::Dump qw(dump); |
| 7 | |
| 8 | my $pid = fork(); |
| 9 | my $res; |
| 10 | unless ($pid) { |
| 11 | unless (fork) { |
| 12 | exec "MOJO_CONFIG=../example.conf morbo script/derekovecs-server"; |
| 13 | die "exec failed!"; |
| 14 | } |
| 15 | exit(0); |
| 16 | } |
| 17 | sleep(20); |
| 18 | |
| 19 | my $client = REST::Client->new(); |
| 20 | $client->GET('http://localhost:3000/?word=Grund&json=1'); |
| 21 | $res = decode_json($client->responseContent()); |
| 22 | is( $res->{list}->[0]->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" ); |
| 23 | is( $res->{collocators}->[0]->{word}, "Hitchcock", "primary syntagmatic neighbour of Grund" ); |
| 24 | |
| 25 | $client->GET('http://localhost:3000/getClassicCollocators?w=Grund'); |
| 26 | #print STDERR dump($res); |
| 27 | $res = decode_json($client->responseContent()); |
| 28 | is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" ); |
| 29 | |
| 30 | $client->GET('http://localhost:3000/getClassicCollocators?w=Grund'); |
| 31 | $res = decode_json($client->responseContent()); |
| 32 | is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund (cached)" ); |
| 33 | |
| 34 | $client->GET('http://localhost:3000/getCollocationAssociation?w=Grund&c=diesem'); |
| 35 | $res = decode_json($client->responseContent()); |
| 36 | is($res->{f1}, 29, "collocation association"); |
| 37 | |
Marc Kupietz | af708c2 | 2023-11-05 11:20:20 +0100 | [diff] [blame] | 38 | $client->GET('http://localhost:3000/getVersion'); |
| 39 | $res = $client->responseContent(); |
Marc Kupietz | b36bc74 | 2023-11-05 17:46:11 +0100 | [diff] [blame] | 40 | like($res, qr/^"\d+\.?\d*\.?\d*"$/, "version ok"); |
Marc Kupietz | af708c2 | 2023-11-05 11:20:20 +0100 | [diff] [blame] | 41 | |
Marc Kupietz | dea505e | 2023-11-05 11:42:36 +0100 | [diff] [blame] | 42 | $client->GET('http://localhost:3000/getModelName'); |
| 43 | $res = $client->responseContent(); |
Marc Kupietz | b36bc74 | 2023-11-05 17:46:11 +0100 | [diff] [blame] | 44 | is($res, '"wpd19_10000"', "model name ok"); |
| 45 | |
Marc Kupietz | 043db15 | 2023-11-05 17:47:53 +0100 | [diff] [blame^] | 46 | $client->GET('http://localhost:3000/getVocabSize'); |
| 47 | $res = $client->responseContent(); |
| 48 | ok($res > 1000, "vocab size ok"); |
Marc Kupietz | dea505e | 2023-11-05 11:42:36 +0100 | [diff] [blame] | 49 | |
Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame] | 50 | for (my $i=0; $i<4; $i++) { |
| 51 | $pid++; |
| 52 | print STDERR "killing PID $pid\n"; |
| 53 | system("kill -9 $pid"); |
| 54 | } |
| 55 | done_testing; |