From 6e55266f8701326e5dc7908eb63c19675e640afc Mon Sep 17 00:00:00 2001 From: Ben Moon Date: Wed, 3 Feb 2016 18:00:59 +0000 Subject: [PATCH 1/2] Remove 'sf' trigger Reduce over-triggering - 'sf' seems to be used for other things. --- lib/DDG/Goodie/SigFigs.pm | 4 ++-- t/SigFigs.t | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/DDG/Goodie/SigFigs.pm b/lib/DDG/Goodie/SigFigs.pm index 7a780a63b..0c3edacfb 100644 --- a/lib/DDG/Goodie/SigFigs.pm +++ b/lib/DDG/Goodie/SigFigs.pm @@ -5,7 +5,7 @@ use strict; use DDG::Goodie; with 'DDG::GoodieRole::NumberStyler'; -triggers any => 'sigfigs', 'sig figs', 'sf', 'significant'; +triggers any => 'sigfigs', 'sig figs', 'significant'; zci answer_type => "sig_figs"; zci is_cached => 1; @@ -35,7 +35,7 @@ my $number_re = number_style_regex(); handle query_raw => sub { my $query = $_; - $query =~ s/.*?(sf|sig(nificant)? ?(fig(ure)?|digit)s)[^,.\d]*+//i; + $query =~ s/.*?(sig(nificant)? ?(fig(ure)?|digit)s)[^,.\d]*+//i; return if $query eq ''; $query =~ /^($number_re)\D*?$/ or return; my $number_match = $1; diff --git a/t/SigFigs.t b/t/SigFigs.t index 10ebee28b..7c1c23b98 100644 --- a/t/SigFigs.t +++ b/t/SigFigs.t @@ -28,24 +28,26 @@ sub build_test { test_zci(build_structured_answer(@_)) } ddg_goodie_test( [qw( DDG::Goodie::SigFigs)], - 'sf 78' => build_test('2', '78'), + 'sigfigs 78' => build_test('2', '78'), "sigfigs 10.12404" => build_test('7', '10.12404'), "significant digits of 3030." => build_test('4', '3,030.'), "significant figures 0.0100235" => build_test('6', '0.0100235'), - "sf 302.056" => build_test('6', '302.056'), + "sig figs 302.056" => build_test('6', '302.056'), "significant figs 045.30" => build_test('4', '045.30'), 'sigfigs 01.1234000' => build_test('8', '01.1234000'), 'significant figures 000123000' => build_test('3', '000,123,000'), 'sigfigs 0' => build_test('0', '0'), - 'sf 001,70' => build_test('3', '001,70'), - 'sf 1_200.' => build_test('4', '1,200.'), - 'sf 1. 5h' => build_test('2', '1.5'), + 'sig figs 001,70' => build_test('3', '001,70'), + 'significant figs 1_200.' => build_test('4', '1,200.'), + 'significant figures 1. 5h' => build_test('2', '1.5'), 'sig figs 501,.3' => build_test('4', '501,.3'), 'sf' => undef, + 'sf 78' => undef, 'significant figures a' => undef, 'significant figures of 1.230' => build_test('4', '1.230'), 'sig figs 1h1' => undef, 'sig figs 000.' => build_test('0', '000.'), + # As Question 'What are the significant figures of 312?' => build_test('3', '312'), 'How many sig figs are there in 11.3' => build_test('3', '11.3'), ); From 1203c78e579c2fc03922b33ccc0700cf74e9bd57 Mon Sep 17 00:00:00 2001 From: Ben Moon Date: Wed, 3 Feb 2016 18:10:38 +0000 Subject: [PATCH 2/2] Fix triggering with non-numbers Would allow non-numbers to be present if numbers were already in the query. --- lib/DDG/Goodie/SigFigs.pm | 2 +- t/SigFigs.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DDG/Goodie/SigFigs.pm b/lib/DDG/Goodie/SigFigs.pm index 0c3edacfb..58fb0c835 100644 --- a/lib/DDG/Goodie/SigFigs.pm +++ b/lib/DDG/Goodie/SigFigs.pm @@ -37,7 +37,7 @@ handle query_raw => sub { my $query = $_; $query =~ s/.*?(sig(nificant)? ?(fig(ure)?|digit)s)[^,.\d]*+//i; return if $query eq ''; - $query =~ /^($number_re)\D*?$/ or return; + $query =~ /^($number_re)\??$/ or return; my $number_match = $1; my $style = number_style_for($number_match); return unless $style; diff --git a/t/SigFigs.t b/t/SigFigs.t index 7c1c23b98..88b7f01ea 100644 --- a/t/SigFigs.t +++ b/t/SigFigs.t @@ -39,13 +39,13 @@ ddg_goodie_test( 'sigfigs 0' => build_test('0', '0'), 'sig figs 001,70' => build_test('3', '001,70'), 'significant figs 1_200.' => build_test('4', '1,200.'), - 'significant figures 1. 5h' => build_test('2', '1.5'), 'sig figs 501,.3' => build_test('4', '501,.3'), 'sf' => undef, 'sf 78' => undef, 'significant figures a' => undef, 'significant figures of 1.230' => build_test('4', '1.230'), 'sig figs 1h1' => undef, + 'significant figures 1. 5h' => undef, 'sig figs 000.' => build_test('0', '000.'), # As Question 'What are the significant figures of 312?' => build_test('3', '312'),