Dewey: Should not react to the query "dewey decimal system" without numbers etc
parent
b83db4c7c8
commit
5a91961dd8
|
@ -24,7 +24,7 @@ sub get_info {
|
||||||
}
|
}
|
||||||
|
|
||||||
# add a key-value pair with number and description to $data
|
# add a key-value pair with number and description to $data
|
||||||
sub line {
|
sub add_line {
|
||||||
my($num, $data) = @_;
|
my($num, $data) = @_;
|
||||||
chomp $num;
|
chomp $num;
|
||||||
if(exists($nums{"$num\n"})) {
|
if(exists($nums{"$num\n"})) {
|
||||||
|
@ -35,68 +35,58 @@ sub line {
|
||||||
handle remainder => sub {
|
handle remainder => sub {
|
||||||
return unless s/^(?:the)?\s*(?:decimal)?\s*(?:system)?\s*(?:numbers?|\#)?\s*
|
return unless s/^(?:the)?\s*(?:decimal)?\s*(?:system)?\s*(?:numbers?|\#)?\s*
|
||||||
(?:
|
(?:
|
||||||
(\d{1,3})(?:\.\d+)?(s)? |
|
(?<num>\d{1,3})(?:\.\d+)?(?<multi>s)? |
|
||||||
([\w\s]+?)
|
(?<word>[\w\s]+?)
|
||||||
)
|
)
|
||||||
\s*(?:in)?\s*(?:the)?\s*(?:decimal)?\s*(?:system)?$
|
\s*(?:in)?\s*(?:the)?\s*(?:decimal)?\s*(?:system)?$
|
||||||
/defined $1?$1:$3/eix;
|
/defined $1?$1:$3/eix;
|
||||||
|
|
||||||
# the 's' like in '400s'
|
# the 's' like in '400s'
|
||||||
my $multi = $2;
|
my $multi = $+{'multi'};
|
||||||
# words that might describe the category
|
# words that might describe the category
|
||||||
my $word = $3;
|
my $word = $+{'word'};
|
||||||
#output rows
|
#output rows
|
||||||
my $output = {};
|
my $output = {};
|
||||||
|
|
||||||
if (defined $word) {
|
if (defined $word) {
|
||||||
return if lc($word) eq 'system'; # don't respond to "dewey decimal system"
|
return if lc($word) eq 'system';
|
||||||
|
|
||||||
my @results = grep(/$word/i, keys %types);
|
my @results = grep(/$word/i, keys %types);
|
||||||
|
|
||||||
return unless @results;
|
return unless @results;
|
||||||
|
add_line($types{$_}, $output) for @results;
|
||||||
if (@results > 1) {
|
|
||||||
line($types{$_}, $output) for @results;
|
|
||||||
$multi = 1;
|
|
||||||
} else {
|
|
||||||
my $num = $types{$results[0]};
|
|
||||||
line($num, $output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
$_ = sprintf "%03d", $_;
|
#$_ = sprintf "%03d", $+{'num'};
|
||||||
|
my $formatted_num = sprintf "%03d", $+{'num'};
|
||||||
unless ($multi) {
|
unless($multi) {
|
||||||
line($_, $output);
|
add_line($formatted_num, $output)
|
||||||
}
|
}
|
||||||
elsif (/\d00/) {
|
elsif ($formatted_num =~ /\d00/) {
|
||||||
for ($_..$_+99) {
|
for my $x ($formatted_num .. $formatted_num+99) {
|
||||||
line($_, $output) or next;
|
add_line($x, $output) or next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif (/\d\d0/) {
|
elsif ($formatted_num =~ /\d\d0/) {
|
||||||
for ($_..$_+9) {
|
for my $x ($formatted_num .. $formatted_num+9) {
|
||||||
line($_, $output) or next;
|
add_line($x, $output) or next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output, structured_answer => {
|
return $output, structured_answer => {
|
||||||
id => 'dewey_decimal',
|
id => 'dewey_decimal',
|
||||||
name => 'Answer',
|
name => 'Answer',
|
||||||
templates => {
|
templates => {
|
||||||
group => 'list',
|
group => 'list',
|
||||||
options => {
|
options => {
|
||||||
content => 'record',
|
content => 'record',
|
||||||
moreAt => 0
|
moreAt => 0
|
||||||
}
|
|
||||||
},
|
|
||||||
data => {
|
|
||||||
title => 'Dewey Decimal System',
|
|
||||||
record_data => $output
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
data => {
|
||||||
|
title => 'Dewey Decimal System',
|
||||||
|
record_data => $output
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
13
t/Dewey.t
13
t/Dewey.t
|
@ -11,7 +11,7 @@ zci is_cached => 1;
|
||||||
|
|
||||||
sub build_structured_answer
|
sub build_structured_answer
|
||||||
{
|
{
|
||||||
my ($data) = @_;
|
my ($data) = @_;
|
||||||
return $data, structured_answer => {
|
return $data, structured_answer => {
|
||||||
id => "dewey_decimal",
|
id => "dewey_decimal",
|
||||||
name => "Answer",
|
name => "Answer",
|
||||||
|
@ -30,13 +30,13 @@ sub build_structured_answer
|
||||||
}
|
}
|
||||||
|
|
||||||
ddg_goodie_test(
|
ddg_goodie_test(
|
||||||
[qw(
|
[qw(
|
||||||
DDG::Goodie::Dewey
|
DDG::Goodie::Dewey
|
||||||
)],
|
)],
|
||||||
"dewey 123" => test_zci(build_structured_answer({
|
"dewey 123" => test_zci(build_structured_answer({
|
||||||
"123" => "Determinism and indeterminism"
|
"123" => "Determinism and indeterminism"
|
||||||
})),
|
})),
|
||||||
'646 dewey decimal system' => test_zci(build_structured_answer({
|
'646 dewey decimal system' => test_zci(build_structured_answer({
|
||||||
"646" => "Sewing, clothing, personal living"
|
"646" => "Sewing, clothing, personal living"
|
||||||
})),
|
})),
|
||||||
'dewey decimal system 640s' => test_zci(build_structured_answer({
|
'dewey decimal system 640s' => test_zci(build_structured_answer({
|
||||||
|
@ -69,6 +69,7 @@ ddg_goodie_test(
|
||||||
'dewey 644' => test_zci(build_structured_answer({
|
'dewey 644' => test_zci(build_structured_answer({
|
||||||
"644" => "Household utilities"
|
"644" => "Household utilities"
|
||||||
})),
|
})),
|
||||||
|
'dewey decimal system' => undef,
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue