mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-25 21:39:27 +01:00
applets/wiktionary: group definitions w/examples; clean up output
This commit is contained in:
parent
3ef58c2bfa
commit
87eff496e9
33
applets/wiktionary.pl
vendored
33
applets/wiktionary.pl
vendored
@ -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";
|
||||
}
|
||||
|
@ -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 {}
|
||||
|
Loading…
Reference in New Issue
Block a user