HelpLine: add structured answer.
Also, restructure data sources to make it easier for non-technical people to contribute.master
parent
f2338c83d7
commit
fd1c66408d
|
@ -3,92 +3,48 @@ package DDG::Goodie::HelpLine;
|
|||
|
||||
use DDG::Goodie;
|
||||
|
||||
my @triggers = (
|
||||
'suicide',
|
||||
'suicide hotline',
|
||||
'kill myself',
|
||||
'suicidal thoughts',
|
||||
'end my life',
|
||||
'suicidal thoughts',
|
||||
'suicidal',
|
||||
'suicidal ideation',
|
||||
'i want to kill myself',
|
||||
'commit suicide',
|
||||
'suicide pills',
|
||||
'suicide pill',
|
||||
'suicide prevention',
|
||||
'kill myself',
|
||||
'suicide phone number',
|
||||
'suicide hot line',
|
||||
'suicide lifeline',
|
||||
'suicide life line',
|
||||
'crisis intervention',
|
||||
'i want to die',
|
||||
'committing suicide',
|
||||
'killing myself',
|
||||
'hang myself',
|
||||
'shoot myself',
|
||||
'fastest way to kill myself',
|
||||
'i\'m suicidal',
|
||||
'how to make suicide pill',
|
||||
'how to make suicide pills',
|
||||
'make suicide pills',
|
||||
'make suicide pill',
|
||||
'best way to kill myself',
|
||||
'easiest suicide method',
|
||||
'i want to end my life',
|
||||
'suicide help',
|
||||
'suicide intervention',
|
||||
'suicide method',
|
||||
'suicide methods',
|
||||
'how to kill myself',
|
||||
'ways to kill myself',
|
||||
);
|
||||
use YAML::XS qw( Load );
|
||||
|
||||
triggers any => @triggers;
|
||||
my $triggers = Load(scalar share('triggers.yml')->slurp);
|
||||
|
||||
triggers any => @$triggers;
|
||||
|
||||
zci answer_type => 'helpline';
|
||||
zci is_cached => 0;
|
||||
|
||||
primary_example_queries 'suicide hotline';
|
||||
description 'Checks if a query with the word "suicide" was made and returns a 24 hr suicide hotline.';
|
||||
attribution github => ['https://github.com/conorfl', 'conorfl'],
|
||||
twitter => '@areuhappylucia';
|
||||
attribution github => ['https://github.com/conorfl', 'conorfl'],
|
||||
twitter => '@areuhappylucia';
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Helpline.pm';
|
||||
topics 'everyday';
|
||||
category 'special';
|
||||
source 'https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines';
|
||||
|
||||
my %helpline = (
|
||||
# http://www.lifeline.org.au/Get-Help/I-Need-Help-Now and http://www.kidshelp.com.au/grownups/about-this-site.php
|
||||
AU => ['13 11 14 or 1800 55 1800 (kids)', 'Australia'],
|
||||
# http://www.suicidepreventionlifeline.org/ and http://org.kidshelpphone.ca/en
|
||||
CA => ['1-800-273-8255 or 1-800-668-6868 (kids)', 'Canada'],
|
||||
# http://samaritans.org.hk/24-hour-telephone-hotline (supports English, Cantonese and Mandarin)
|
||||
HK => [ '2896 0000', 'Hong Kong'],
|
||||
# http://www.samaritans.org/how-we-can-help-you/contact-us
|
||||
IE => ['1850 60 90 90', 'Ireland'],
|
||||
# http://www.lifeline.org.nz/corp_Home_378_2001.aspx
|
||||
NZ => ['0800 543 354', 'New Zealand'],
|
||||
# http://www.papyrus-uk.org/, http://www.samaritans.org/, and http://www.thecalmzone.net/help/helpline/helpline-nationwide/
|
||||
GB => ['0800 068 41 41, 08457 90 90 90, or 0800 58 58 58', 'the UK'],
|
||||
# http://www.samaritans.org.sg/contact/confide.htm#call_us
|
||||
SG => ['1800-221 4444', 'Singapore'],
|
||||
# http://www.suicidepreventionlifeline.org/
|
||||
US => ['1-800-273-TALK (8255)', 'the U.S.'],
|
||||
);
|
||||
my $helplines = Load(scalar share('helplines.yml')->slurp);
|
||||
my %suicide_phrases = map { $_ => 1 } @$triggers;
|
||||
|
||||
handle query_lc => sub {
|
||||
my $query = shift;
|
||||
|
||||
# Check if the query matches exatly the trigger word.
|
||||
my %suicide_phrases = map { $_ => 1 } @triggers;
|
||||
return unless exists $suicide_phrases{$query};
|
||||
|
||||
# Display the result.
|
||||
my $code = $loc->country_code;
|
||||
return "24 Hour Suicide Hotline in " . $helpline{$code}[1] . ": " . $helpline{$code}[0]
|
||||
if exists $helpline{$code}[0];
|
||||
my $helpline = $helplines->{$loc->country_code};
|
||||
return unless $helpline;
|
||||
|
||||
my @contacts = @{$helpline->{contacts}};
|
||||
my $numbers_string = join(', ', map { ($_->{for_kids}) ? $_->{phone} . ' (kids)' : $_->{phone}; } @contacts);
|
||||
my $operation = '24 Hour Suicide Hotline';
|
||||
$operation .= 's' if (scalar @contacts > 1);
|
||||
$operation .= ' in ' . $helpline->{display_country};
|
||||
|
||||
return $operation . ": " . $numbers_string,
|
||||
structured_answer => {
|
||||
input => [],
|
||||
operation => $operation,
|
||||
result => $numbers_string,
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
AU:
|
||||
contacts:
|
||||
- phone: 13 11 14
|
||||
web: http://www.lifeline.org.au/Get-Help/I-Need-Help-Now
|
||||
- for_kids: 1
|
||||
phone: 1800 55 1800
|
||||
web: http://www.kidshelp.com.au/grownups/about-this-site.php
|
||||
display_country: Australia
|
||||
CA:
|
||||
contacts:
|
||||
- phone: 1-800-273-8255
|
||||
web: http://www.suicidepreventionlifeline.org/
|
||||
- for_kids: 1
|
||||
phone: 1-800-668-6868
|
||||
web: http://org.kidshelpphone.ca/en
|
||||
display_country: Canada
|
||||
GB:
|
||||
contacts:
|
||||
- phone: 0800 068 41 41
|
||||
web: http://www.papyrus-uk.org/
|
||||
- phone: 08457 90 90 90
|
||||
web: http://www.samaritans.org/
|
||||
- phone: 0800 58 58 58
|
||||
web: http://www.thecalmzone.net/help/helpline/helpline-nationwide/
|
||||
display_country: the UK
|
||||
HK:
|
||||
contacts:
|
||||
- phone: 2896 0000
|
||||
web: http://samaritans.org.hk/24-hour-telephone-hotline
|
||||
display_country: Hong Kong
|
||||
IE:
|
||||
contacts:
|
||||
- phone: 1850 60 90 90
|
||||
web: http://www.samaritans.org/how-we-can-help-you/contact-us
|
||||
display_country: Ireland
|
||||
NZ:
|
||||
contacts:
|
||||
- phone: 0800 543 354
|
||||
web: http://www.lifeline.org.nz/corp_Home_378_2001.aspx
|
||||
display_country: New Zealand
|
||||
SG:
|
||||
contacts:
|
||||
- phone: 1800-221 4444
|
||||
web: http://www.samaritans.org.sg/contact/confide.htm#call_us
|
||||
display_country: Singapore
|
||||
US:
|
||||
contacts:
|
||||
- phone: 1-800-273-TALK (8255)
|
||||
web: http://www.suicidepreventionlifeline.org/
|
||||
display_country: the U.S.
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
- suicide
|
||||
- suicide hotline
|
||||
- kill myself
|
||||
- suicidal thoughts
|
||||
- end my life
|
||||
- suicidal thoughts
|
||||
- suicidal
|
||||
- suicidal ideation
|
||||
- i want to kill myself
|
||||
- commit suicide
|
||||
- suicide pills
|
||||
- suicide pill
|
||||
- suicide prevention
|
||||
- kill myself
|
||||
- suicide phone number
|
||||
- suicide hot line
|
||||
- suicide lifeline
|
||||
- suicide life line
|
||||
- crisis intervention
|
||||
- i want to die
|
||||
- committing suicide
|
||||
- killing myself
|
||||
- hang myself
|
||||
- shoot myself
|
||||
- fastest way to kill myself
|
||||
- i'm suicidal
|
||||
- how to make suicide pill
|
||||
- how to make suicide pills
|
||||
- make suicide pills
|
||||
- make suicide pill
|
||||
- best way to kill myself
|
||||
- easiest suicide method
|
||||
- i want to end my life
|
||||
- suicide help
|
||||
- suicide intervention
|
||||
- suicide method
|
||||
- suicide methods
|
||||
- how to kill myself
|
||||
- ways to kill myself
|
|
@ -48,7 +48,7 @@ ddg_goodie_test(
|
|||
query_raw => "$query",
|
||||
location => test_location("$locations[$_]")
|
||||
),
|
||||
test_zci(qr/24 Hour Suicide Hotline/),
|
||||
test_zci(qr/24 Hour Suicide Hotline/, structured_answer => { input => [], operation => qr/24 Hour Suicide Hotline/, result => qr/[0-9]{2}/}),
|
||||
} 0 .. scalar @locations - 1
|
||||
} 0 .. scalar @queries - 1),
|
||||
(map {
|
||||
|
|
Loading…
Reference in New Issue