| use strict; |
| use warnings; |
| use Test::More tests=>13; |
| use Mojo::JSON qw(decode_json encode_json to_json); |
| use REST::Client; |
| use Data::Dump qw(dump); |
| |
| my $pid = fork(); |
| my $res; |
| unless ($pid) { |
| unless (fork) { |
| exec "MOJO_CONFIG=../example.conf morbo script/derekovecs-server"; |
| die "exec failed!"; |
| } |
| exit(0); |
| } |
| sleep(20); |
| |
| my $client = REST::Client->new(); |
| $client->GET('http://localhost:3000/?word=Grund&json=1'); |
| $res = decode_json($client->responseContent()); |
| is( $res->{list}->[0]->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" ); |
| is( $res->{collocators}->[0]->{word}, "Hitchcock", "primary syntagmatic neighbour of Grund" ); |
| |
| # "König - Mann + Frau": the neighbours of a position that belongs to no |
| # single word, and no syntagmatic answer for it. |
| $client->GET('http://localhost:3000/?word=K%C3%B6nig+-+Mann+%2B+Frau&json=1'); |
| $res = decode_json($client->responseContent()); |
| is( $res->{list}->[0]->[0]->{word}, "Dareios", "primary neighbour of a vector expression" ); |
| ok( $res->{collocators} && @{$res->{collocators}} > 0, "a vector expression has syntagmatic neighbours too" ); |
| |
| # The syntagmatic side used to read the input weights of the first operand |
| # alone: "Haus Auto" answered with the collocators of "Haus", "Auto Haus" with |
| # those of "Auto". It combines them now, so the order no longer matters and |
| # neither single word answer comes back unchanged. |
| $client->GET('http://localhost:3000/?word=Haus&json=1'); |
| my $haus = decode_json($client->responseContent()); |
| $client->GET('http://localhost:3000/?word=Haus+Auto&json=1'); |
| my $haus_auto = decode_json($client->responseContent()); |
| $client->GET('http://localhost:3000/?word=Auto+Haus&json=1'); |
| my $auto_haus = decode_json($client->responseContent()); |
| is_deeply( [map { $_->{word} } @{$haus_auto->{collocators}}], |
| [map { $_->{word} } @{$auto_haus->{collocators}}], |
| "the syntagmatic side does not depend on the order of the operands" ); |
| isnt( $haus_auto->{collocators}->[0]->{max}, $haus->{collocators}->[0]->{max}, |
| "and combines them rather than answering for the first" ); |
| |
| $client->GET('http://localhost:3000/?word=Grund+Blahfasel&json=1'); |
| $res = decode_json($client->responseContent()); |
| is( $res->{unknown}, "Blahfasel", "operands outside the vocabulary are reported" ); |
| |
| $client->GET('http://localhost:3000/getClassicCollocators?w=Grund'); |
| #print STDERR dump($res); |
| $res = decode_json($client->responseContent()); |
| is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" ); |
| |
| $client->GET('http://localhost:3000/getClassicCollocators?w=Grund'); |
| $res = decode_json($client->responseContent()); |
| is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund (cached)" ); |
| |
| $client->GET('http://localhost:3000/getCollocationAssociation?w=Grund&c=diesem'); |
| $res = decode_json($client->responseContent()); |
| is($res->{f1}, 29, "collocation association"); |
| |
| $client->GET('http://localhost:3000/getVersion'); |
| $res = $client->responseContent(); |
| like($res, qr/^"\d+\.?\d*\.?\d*"$/, "version ok"); |
| |
| $client->GET('http://localhost:3000/getModelName'); |
| $res = $client->responseContent(); |
| is($res, '"wpd19_10000"', "model name ok"); |
| |
| $client->GET('http://localhost:3000/getVocabSize'); |
| $res = $client->responseContent(); |
| ok($res > 1000, "vocab size ok"); |
| |
| for (my $i=0; $i<4; $i++) { |
| $pid++; |
| print STDERR "killing PID $pid\n"; |
| system("kill -9 $pid"); |
| } |
| done_testing; |