From ff31d710240c79a0e02baf7eafb8013261739c63 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 29 Jun 2024 11:33:11 -0700 Subject: [PATCH] applets/wiktionary: add part of speech filter option --- applets/wiktionary.pl | 23 +++++++++++++++++++++-- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/applets/wiktionary.pl b/applets/wiktionary.pl index 81d1cd85..6c9d9e7f 100755 --- a/applets/wiktionary.pl +++ b/applets/wiktionary.pl @@ -24,9 +24,9 @@ binmode(STDOUT, ":utf8"); @ARGV = map { decode('UTF-8', $_, 1) } @ARGV; -my $usage = "Usage: wiktionary [-e] [-p] [-l ] [-n ]; -e for etymology; -p for pronunciation\n"; +my $usage = "Usage: wiktionary [-pos ] [-e] [-p] [-l ] [-n ]; -e for etymology; -p for pronunciation\n"; -my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p); +my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p, $part_of_speech); { my $opt_error; @@ -44,6 +44,7 @@ my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p); 'num|n=i' => \$num, 'all|a' => \$all, 'unique|u' => \$unique, + 'pos=s' => \$part_of_speech, 'p' => \$opt_p, 'e' => \$opt_e, ); @@ -161,6 +162,7 @@ if ($num <= 0 or $all or $unique) { } my @results; +my %parts_of_speech; for (my $i = $start; $i < $num; $i++) { my $entry = $entries->[$i]; @@ -194,6 +196,10 @@ for (my $i = $start; $i < $num; $i++) { my $text; foreach my $definition (@{$entry->{definitions}}) { + $parts_of_speech{$definition->{partOfSpeech}} = 1; + + next if defined $part_of_speech && $definition->{partOfSpeech} ne $part_of_speech; + $text .= "$definition->{partOfSpeech}) "; my $entry = -1; @@ -220,8 +226,21 @@ for (my $i = $start; $i < $num; $i++) { } if (not @results) { + if (defined $part_of_speech) { + $entries_text = $part_of_speech; + $entries_text =~ s/(? "PBot", - BUILD_REVISION => 4764, - BUILD_DATE => "2024-06-28", + BUILD_REVISION => 4765, + BUILD_DATE => "2024-06-29", }; sub initialize {}