TextConverter: Sorted static trigger words into to and from categories (#4490)

* TextConverter: Sorted static trigger words into to and from categories

* TextConverter: Moved to and from trigger words out of handle
master
tossj 2017-09-17 16:11:06 -04:00 committed by Rob Emery
parent 6b16ccdcd9
commit 2287be95c3
2 changed files with 40 additions and 7 deletions

View File

@ -35,6 +35,14 @@ my @merged_triggers = (@single_triggers, @triggers);
my $triggers_re = join "|", @merged_triggers;
my $generics_re = join "|", @generics;
# for static language based triggers e.g. 'base64 decode'
# these words mean we want to go from the type in the query to text
my @from_words = ('decoder', 'decode', 'converter', 'translator');
my $from_words_re = join '|', @from_words;
# these words mean we want to go from text to the type in the query
my @to_words = ('encode', 'encoder', 'translation', 'translate', 'convert', 'conversion');
my $to_words_re = join '|', @to_words;
for my $trig (@triggers) {
push @lang_triggers, map { "$trig $_" } @generics;
}
@ -89,7 +97,11 @@ handle query_lc => sub {
# check to see if query is a static language based trigger
# eg. binary converter, hex encoder
if(grep(/^$query$/, @lang_triggers)) {
$to_type = get_type_information($query);
if ($query =~ /${from_words_re}/gi) {
$from_type = get_type_information($query);
} elsif ($query =~ /${to_words_re}/gi) {
$to_type = get_type_information($query);
}
return '',
structured_answer => {

View File

@ -50,22 +50,22 @@ ddg_goodie_test(
'binary converter' => test_zci(
'', structured_answer => build_structured_answer({
from_type => '',
to_type => 'binary'
from_type => 'binary',
to_type => ''
})
),
'hex converter' => test_zci(
'', structured_answer => build_structured_answer({
from_type => '',
to_type => 'hexadecimal'
from_type => 'hexadecimal',
to_type => ''
})
),
'ascii converter' => test_zci(
'', structured_answer => build_structured_answer({
from_type => '',
to_type => 'text'
from_type => 'text',
to_type => ''
})
),
@ -83,6 +83,27 @@ ddg_goodie_test(
})
),
'base64 decoder' => test_zci(
'', structured_answer => build_structured_answer({
from_type => 'base64',
to_type => ''
})
),
'hex translator' => test_zci(
'', structured_answer => build_structured_answer({
from_type => 'hexadecimal',
to_type => ''
})
),
'binary translation' => test_zci(
'', structured_answer => build_structured_answer({
from_type => '',
to_type => 'binary'
})
),
##
## 2. LANGUAGE BASED QUERIES
##