<commit_before>package DDG::Goodie::GuitarChords;
# ABSTRACT: Returns diagrams of guitar chords

use DDG::Goodie;
with 'DDG::GoodieRole::ImageLoader';

# guitar script is stored in share directory
# including this way, because it limits duplicated code
my $g = share("chords.pm");
do "$g";
our %chord_lists; #from chords.pm

zci answer_type => 'guitarchord';
zci is_cached => 1;

name "GuitarChords";
description "Returns diagrams of guitar chords";
category "reference";
topics "music";

primary_example_queries 'G#m6 guitar chord', 'G guitar chord', 'Dbdim guitar chord';

attribution github  => ["charles-l",                  "<NAME>"],
            twitter => ["theninjacharlie",            "<NAME>"],
            web     => ["http://charels-l.github.io", "<NAME>"];

triggers startend => ('guitar chord');

handle remainder => sub
{
    if (my $c //= check_chord($_))
    {
        return
            heading => "$c",
            html => "<div class='text--secondary'>Guitar chord diagram for $c</div>" . get_chord_img($c),
            answer => "$c";
    }
    return;
};

sub check_chord
{
    if ($_[0] =~ /(?<a>[a-gA-G])(?<b>#|b)?(?<c>dim|min|maj|add|aug|m|M)?(?<d>M|maj|m|min)?(?<e>[0-9])?(\/(?<f>(#|b)?[0-9]+))?/) {
        my ($a,$b,$c,$d,$e,$f,$r);
        $a = uc($+{'a'});
        $b = $+{'b'} if $+{'b'};
        if ($c = $+{'c'}) {
            $c = 'm' if ($c =~ /^min$/);
            $c = 'M' if ($c =~ /^maj$/);
        }
        if ($d = $+{'d'}) {
            $d = 'm' if ($d =~ /^min$/);
            $d = 'M' if ($d =~ /^maj$/);
        }
        $e = $+{'e'} if $+{'e'};
        $f = '('.$+{'f'}.')' if $+{'f'};
        $r = $a if $a;
        $r .= $b if $b;
        $r .= $c if $c;
        $r .= $d if $d;
        $r .= $e if $e;
        $r .= $f if $f;
        if ($r ~~ @{[keys %chord_lists]}) {
            return $r;
        }
    }<commit_msg>fixed to allow sus<commit_after>package DDG::Goodie::GuitarChords;
# ABSTRACT: Returns diagrams of guitar chords

use DDG::Goodie;
with 'DDG::GoodieRole::ImageLoader';

# guitar script is stored in share directory
# including this way, because it limits duplicated code
my $g = share("chords.pm");
do "$g";
our %chord_lists; #from chords.pm

zci answer_type => 'guitarchord';
zci is_cached => 1;

name "GuitarChords";
description "Returns diagrams of guitar chords";
category "reference";
topics "music";

primary_example_queries 'G#m6 guitar chord', 'G guitar chord', 'Dbdim guitar chord';

attribution github  => ["charles-l",                  "<NAME>"],
            twitter => ["theninjacharlie",            "<NAME>"],
            web     => ["http://charels-l.github.io", "<NAME>"];

triggers startend => ('guitar chord');

handle remainder => sub
{
    if (my $c //= check_chord($_))
    {
        return
            heading => "$c",
            html => "<div class='text--secondary'>Guitar chord diagram for $c</div>" . get_chord_img($c),
            answer => "$c";
    }
    return;
};

sub check_chord
{
    if ($_[0] =~ /(?<a>[a-gA-G])(?<b>#|b)?(?<c>dim|min|maj|add|aug|m|M)?(?<d>M|maj|m|min)?(?<e>[0-9]?(sus[0-9])?)?(\/(?<f>(#|b)?[0-9]+))?/) {
        my ($a,$b,$c,$d,$e,$f,$r);
        $a = uc($+{'a'});
        $b = $+{'b'} if $+{'b'};
        if ($c = $+{'c'}) {
            $c = 'm' if ($c =~ /^min$/);
            $c = 'M' if ($c =~ /^maj$/);
        }
        if ($d = $+{'d'}) {
            $d = 'm' if ($d =~ /^min$/);
            $d = 'M' if ($d =~ /^maj$/);
        }
        $e = $+{'e'} if $+{'e'};
        $f = '('.$+{'f'}.')' if $+{'f'};
        $r = $a if $a;
        $r .= $b if $b;
        $r .= $c if $c;
        $r .= $d if $d;
        $r .= $e if $e;
        $r .= $f if $f;
        if ($r ~~ @{[keys %chord_lists]}) {
            return $r;
        }
    }
{'fraction_non_alphanumeric': 0.2444799148709763, 'fraction_numerical': 0.004256451183825486, 'mean_word_length': 2.157010915197313, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621570', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1447, 'n_words': 355}