Fix keyword weights being flattened to 1 - #32
Open
Ppantaleo wants to merge 1 commit into
Open
Conversation
array_unique() was applied to the journal-wide list of keyword names before array_count_values() counted them. Since every value was distinct by then, each keyword got a count of 1: the cloud rendered every word at the same font size and the top-50 slice kept an arbitrary set instead of the most frequent ones. Deduplicate per publication instead, so a word's weight is the number of articles that use it. Also preserve keys in the array_slice() call: a purely numeric keyword had its key reindexed and reached the template as "0".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
array_unique()is applied to the journal-wide list of keyword names beforearray_count_values()counts them:By the time the count runs every value is distinct, so each keyword gets a count of 1. Two consequences:
fontSize.domain()inblock.tplgets[1, 1], a degenerate domain, so d3 maps every keyword to the same font size and the cloud carries no information.array_slice()keeps an arbitrary 50 keywords rather than the 50 most frequent, sincearsort()has nothing to sort by.The fix
Deduplicate per publication instead of across the whole journal, so a word's weight is the number of articles that use it. A keyword repeated inside a single publication still counts once.
Also passes
preserve_keys: truetoarray_slice(): a purely numeric keyword ("2020") had its key reindexed and reached the template as "0".Testing
Verified on OJS 3.5.0.5 against a journal with 879 published publications. The block now returns
covid-19: 22, argentina: 17, editorial: 15, ..., matching the counts obtained directly via SQL. Before the change every entry wassize: 1.Note on #31
#31 touches the same lines but addresses a different problem — the block coming out empty when
getBySymbolic()returns a flat array. It keeps thearray_unique()before the count, so it does not change the weights. Happy to rebase if #31 lands first.