From 87eff496e9e8cd54f050e63ff201d0cc84924f0c Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 29 Jun 2022 19:38:17 -0700 Subject: [PATCH] applets/wiktionary: group definitions w/examples; clean up output --- applets/wiktionary.pl | 33 +++++++++++++++++---------------- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/applets/wiktionary.pl b/applets/wiktionary.pl index 19747b46..a9f4f9a6 100755 --- a/applets/wiktionary.pl +++ b/applets/wiktionary.pl @@ -172,13 +172,24 @@ for (my $i = $start; $i < $num; $i++) { foreach my $definition (@{$entry->{definitions}}) { $text .= "$definition->{partOfSpeech}) "; - $text .= join("\n\n", flatten @{$definition->{text}}) . "\n\n"; - if (@{$definition->{examples}}) { - $text .= "examples:\n\n"; - $text .= join("\n\n", map { $_->{text} } @{$definition->{examples}}) . "\n\n"; + my $entry = -1; + + foreach my $def (flatten @{$definition->{text}}) { + $def =~ s/^#//; + $text .= "$def\n"; + + if (@{$definition->{examples}}) { + foreach my $example (@{$definition->{examples}}) { + if ($example->{index} == $entry) { + $text .= " ($example->{text})\n"; + } + } + } + + $entry++; + $text .= "\n"; } - } push @results, $text if length $text; @@ -191,16 +202,6 @@ if (not @results) { exit 1; } -my $total_results_count = @results; - -if ($total_results_count == 1) { - $entries_text =~ s/s$//; -} else { - $entries_text =~ s/y$/ies/; -} - -print "$total_results_count $entries_text for $term:\n\n"; - if ($unique) { my %uniq; @@ -232,5 +233,5 @@ my $i = @results == 1 ? $num - 1 : 0; foreach my $result (@results) { $i++; next if not $result; - print "$i) $result\n\n"; + print "$i) $result\n"; } diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 4e7c268a..0ad3751d 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4547, - BUILD_DATE => "2022-06-27", + BUILD_REVISION => 4548, + BUILD_DATE => "2022-06-29", }; sub initialize {}