mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-17 01:19:31 +01:00
applets/wiktionary: add -r flag for relations
This commit is contained in:
parent
a1ec2bfada
commit
68bd1e4d86
35
applets/wiktionary.pl
vendored
35
applets/wiktionary.pl
vendored
@ -24,9 +24,9 @@ binmode(STDOUT, ":utf8");
|
||||
|
||||
@ARGV = map { decode('UTF-8', $_, 1) } @ARGV;
|
||||
|
||||
my $usage = "Usage: wiktionary <term> [-pos <part of speech>] [-e] [-p] [-l <language>] [-n <entry number>]; -e for etymology; -p for pronunciation\n";
|
||||
my $usage = "Usage: wiktionary <term> [-pos <part of speech>] [-e] [-p] [-r [relation]] [-l <language>] [-n <entry number>]; -e for etymology; -p for pronunciation\n";
|
||||
|
||||
my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p, $part_of_speech);
|
||||
my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p, $part_of_speech, $relation);
|
||||
|
||||
{
|
||||
my $opt_error;
|
||||
@ -45,6 +45,7 @@ my ($term, $lang, $section, $num, $all, $unique, $opt_e, $opt_p, $part_of_speech
|
||||
'all|a' => \$all,
|
||||
'unique|u' => \$unique,
|
||||
'pos=s' => \$part_of_speech,
|
||||
'r:s' => \$relation,
|
||||
'p' => \$opt_p,
|
||||
'e' => \$opt_e,
|
||||
);
|
||||
@ -163,6 +164,7 @@ if ($num <= 0 or $all or $unique) {
|
||||
|
||||
my @results;
|
||||
my %parts_of_speech;
|
||||
my %relationships;
|
||||
|
||||
for (my $i = $start; $i < $num; $i++) {
|
||||
my $entry = $entries->[$i];
|
||||
@ -194,16 +196,42 @@ for (my $i = $start; $i < $num; $i++) {
|
||||
|
||||
elsif ($section eq 'definitions') {
|
||||
my $text;
|
||||
my $dsep = '';
|
||||
|
||||
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}) ";
|
||||
$text .= "$dsep$definition->{partOfSpeech}) ";
|
||||
$dsep = ";\n\n";
|
||||
|
||||
my $entry = -1;
|
||||
my $rsep = '';
|
||||
|
||||
if (defined $relation) {
|
||||
my $relations = $definition->{relatedWords};
|
||||
|
||||
foreach my $rel (@$relations) {
|
||||
$relationships{$rel->{relationshipType}} = 1;
|
||||
if (!length $relation || $relation eq '*' || $rel->{relationshipType} eq $relation) {
|
||||
$text .= "$rsep$rel->{relationshipType}) ";
|
||||
$text .= join (",\n", $rel->{words}->@*);
|
||||
$rsep = ";\n\n";
|
||||
$entry++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($entry == -1) {
|
||||
$relation = 'relations' if not length $relation;
|
||||
print "There are no $relation available for `$term`.\n";
|
||||
my @rel = sort keys %relationships;
|
||||
if (@rel) {
|
||||
print 'Try ', join(', ', @rel), ".\n";
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
} else {
|
||||
foreach my $def (flatten @{$definition->{text}}) {
|
||||
$def =~ s/^#//;
|
||||
$text .= "$def\n";
|
||||
@ -220,6 +248,7 @@ for (my $i = $start; $i < $num; $i++) {
|
||||
$text .= "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push @results, $text if length $text;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4793,
|
||||
BUILD_DATE => "2024-10-01",
|
||||
BUILD_REVISION => 4795,
|
||||
BUILD_DATE => "2024-10-02",
|
||||
};
|
||||
|
||||
sub initialize {}
|
||||
|
Loading…
Reference in New Issue
Block a user