[PLUGIN][Pinboard] For tag list request, respond with the most common variant and the corresponding count for each canon tag
This commit is contained in:
parent
539104ec33
commit
556ac85061
@ -393,21 +393,26 @@ class APIv1 extends Controller
|
||||
$user = $check;
|
||||
}
|
||||
|
||||
$tags_freq = [];
|
||||
// Convert the list of all tags to a map from canon to
|
||||
// variations (i.e. tags that canonicalize to the same)
|
||||
$canon_to_variations = [];
|
||||
foreach ($user->getActor()->getNoteTags(Pin::note_type) as $tag) {
|
||||
if (!isset($tags_freq[$tag->getCanonical()])) {
|
||||
$tags_freq[$tag->getCanonical()] = [];
|
||||
if (!isset($canon_to_variations[$tag->getCanonical()])) {
|
||||
$canon_to_variations[$tag->getCanonical()] = [];
|
||||
}
|
||||
$tags_freq[$tag->getCanonical()][] = $tag->getTag();
|
||||
$canon_to_variations[$tag->getCanonical()][] = $tag->getTag();
|
||||
}
|
||||
|
||||
foreach ($tags_freq as $canon => $variations) {
|
||||
// Pick the most common variation and assign to it the count
|
||||
// of all the variations of each canon tag
|
||||
$most_common_variant_frequencies = [];
|
||||
foreach ($canon_to_variations as $variations) {
|
||||
$freqs = array_count_values($variations);
|
||||
arsort($freqs);
|
||||
$tags_freq[$canon] = $freqs[array_key_first($freqs)];
|
||||
$most_common_variant_frequencies[array_key_first($freqs)] = \count($variations);
|
||||
}
|
||||
|
||||
return self::respond($tags_freq);
|
||||
return self::respond($most_common_variant_frequencies);
|
||||
}
|
||||
|
||||
public function unimplmented(Request $request)
|
||||
|
Loading…
Reference in New Issue
Block a user