mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-17 01:19:31 +01:00
applets/wiktionary: refactor relations
This commit is contained in:
parent
68bd1e4d86
commit
bb1b43b089
103
applets/wiktionary.pl
vendored
103
applets/wiktionary.pl
vendored
@ -107,7 +107,7 @@ if ($ENV{DEBUG}) {
|
|||||||
print Dumper($entries), "\n";
|
print Dumper($entries), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my @valid_sections = qw/definitions etymology pronunciations participle/;
|
my @valid_sections = qw/definitions etymology pronunciations/;
|
||||||
|
|
||||||
if (not grep { $_ eq $section } @valid_sections) {
|
if (not grep { $_ eq $section } @valid_sections) {
|
||||||
print "Unknown section `$section`. Available sections are: " . join(', ', sort @valid_sections) . "\n";
|
print "Unknown section `$section`. Available sections are: " . join(', ', sort @valid_sections) . "\n";
|
||||||
@ -196,58 +196,49 @@ for (my $i = $start; $i < $num; $i++) {
|
|||||||
|
|
||||||
elsif ($section eq 'definitions') {
|
elsif ($section eq 'definitions') {
|
||||||
my $text;
|
my $text;
|
||||||
my $dsep = '';
|
|
||||||
|
|
||||||
foreach my $definition (@{$entry->{definitions}}) {
|
foreach my $definition (@{$entry->{definitions}}) {
|
||||||
$parts_of_speech{$definition->{partOfSpeech}} = 1;
|
$parts_of_speech{$definition->{partOfSpeech}} = 1;
|
||||||
|
|
||||||
next if defined $part_of_speech && $definition->{partOfSpeech} ne $part_of_speech;
|
next if defined $part_of_speech && $definition->{partOfSpeech} ne $part_of_speech;
|
||||||
|
|
||||||
$text .= "$dsep$definition->{partOfSpeech}) ";
|
my $relations = '';
|
||||||
$dsep = ";\n\n";
|
|
||||||
|
|
||||||
my $entry = -1;
|
|
||||||
my $rsep = '';
|
|
||||||
|
|
||||||
if (defined $relation) {
|
if (defined $relation) {
|
||||||
my $relations = $definition->{relatedWords};
|
foreach my $rel ($definition->{relatedWords}->@*) {
|
||||||
|
|
||||||
foreach my $rel (@$relations) {
|
|
||||||
$relationships{$rel->{relationshipType}} = 1;
|
$relationships{$rel->{relationshipType}} = 1;
|
||||||
if (!length $relation || $relation eq '*' || $rel->{relationshipType} eq $relation) {
|
if (!length $relation || $relation eq '*' || $rel->{relationshipType} eq $relation) {
|
||||||
$text .= "$rsep$rel->{relationshipType}) ";
|
if ($rel->{words}->@*) {
|
||||||
$text .= join (",\n", $rel->{words}->@*);
|
$relations .= "$rel->{relationshipType}) ";
|
||||||
$rsep = ";\n\n";
|
$relations .= join (", ", $rel->{words}->@*);
|
||||||
$entry++;
|
$relations .= "\n\n";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
if (@{$definition->{examples}}) {
|
|
||||||
foreach my $example (@{$definition->{examples}}) {
|
|
||||||
if ($example->{index} == $entry) {
|
|
||||||
$text .= " ($example->{text})\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry++;
|
|
||||||
$text .= "\n";
|
|
||||||
}
|
}
|
||||||
|
next if not length $relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $entry = -1;
|
||||||
|
|
||||||
|
$text .= "$definition->{partOfSpeech}) ";
|
||||||
|
|
||||||
|
foreach my $def (flatten @{$definition->{text}}) {
|
||||||
|
$def =~ s/^#//;
|
||||||
|
$text .= "$def\n";
|
||||||
|
|
||||||
|
if (!defined $relation && @{$definition->{examples}}) {
|
||||||
|
foreach my $example (@{$definition->{examples}}) {
|
||||||
|
if ($example->{index} == $entry) {
|
||||||
|
$text .= " ($example->{text})\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry++;
|
||||||
|
$text .= "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$text .= $relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
push @results, $text if length $text;
|
push @results, $text if length $text;
|
||||||
@ -256,17 +247,35 @@ for (my $i = $start; $i < $num; $i++) {
|
|||||||
|
|
||||||
if (not @results) {
|
if (not @results) {
|
||||||
if (defined $part_of_speech) {
|
if (defined $part_of_speech) {
|
||||||
$entries_text = $part_of_speech;
|
if (not exists $parts_of_speech{$part_of_speech}) {
|
||||||
|
print "There is no $part_of_speech available for `$term`.\n";
|
||||||
|
|
||||||
|
my @pos = sort keys %parts_of_speech;
|
||||||
|
|
||||||
|
if (@pos) {
|
||||||
|
print 'Try ', join (', ', @pos), ".\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined $relation) {
|
||||||
|
$relation = 'relations' if not length $relation;
|
||||||
|
if (not exists $relationships{$relation}) {
|
||||||
|
print "There are no $relation available for `$term`.\n";
|
||||||
|
|
||||||
|
my @relations = sort keys %relationships;
|
||||||
|
|
||||||
|
if (@relations) {
|
||||||
|
print 'Try ', join (', ', @relations), ".\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "There is no $entries_text available for `$term`.\n";
|
print "There is no $entries_text available for `$term`.\n";
|
||||||
|
|
||||||
my @pos = sort keys %parts_of_speech;
|
|
||||||
|
|
||||||
if (@pos) {
|
|
||||||
print 'Try ', join (', ', @pos), ".\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4795,
|
BUILD_REVISION => 4796,
|
||||||
BUILD_DATE => "2024-10-02",
|
BUILD_DATE => "2024-10-02",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user