From 93f0a60e535c9e2254e85414fc5be07d4e55abc6 Mon Sep 17 00:00:00 2001 From: yhe Date: Tue, 5 Jul 2016 05:20:30 +0000 Subject: [PATCH] return if content dont contain Chinese and result don't contain special Pinyin character (e.g. yes3) --- lib/DDG/Goodie/ChineseToPinyin.pm | 8 ++++++++ t/ChineseToPinyin.t | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/DDG/Goodie/ChineseToPinyin.pm b/lib/DDG/Goodie/ChineseToPinyin.pm index 6c9eb650e..4c46e7492 100644 --- a/lib/DDG/Goodie/ChineseToPinyin.pm +++ b/lib/DDG/Goodie/ChineseToPinyin.pm @@ -97,6 +97,14 @@ handle remainder_lc => sub { my $result = $h2p->han2pinyin($spacedChineseString); $result = ConvertTone($result); + # if content dont contain Chinese + if(!(/[\p{Han}]/)){ + # and result don't contain special Pinyin character + if ($result !~ m/[āáǎàēéěèīíǐìōóǒòūúǔùǜǘǚǜ]/) { + return; + } + } + return "Pinyin of $_ is \"$result\"", structured_answer => { data => { diff --git a/t/ChineseToPinyin.t b/t/ChineseToPinyin.t index 1ac38855b..0f637a19b 100644 --- a/t/ChineseToPinyin.t +++ b/t/ChineseToPinyin.t @@ -54,6 +54,7 @@ ddg_goodie_test( # Try to include some examples of queries on which it might # appear that your answer will trigger, but does not. 'pinyin ' => undef, + 'pinyin yes3' => undef, 'pinyin how are you?' => undef, 'pinyin zhōng guó' => undef, );