Commonest[] function doesn't actually show commonest elementsIssues with a Counter that is tallying term...

Adjust starting of second line

School performs periodic password audits. Is my password compromised?

Has Wakanda ever accepted refugees?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

How to concatenate two command in shell

Should I use HTTPS on a domain that will only be used for redirection?

Where does the proton come in the reduction of NAD?

Where is the fallacy here?

The need of reserving one's ability in job interviews

What is the oldest European royal house?

What is the meaning of option 'by' in TikZ Intersections

I can't die. Who am I?

Giving a talk in my old university, how prominently should I tell students my salary?

Why can't we use freedom of speech and expression to incite people to rebel against government?

Bond discounting conventions

Split a number into equal parts given the number of parts

Paper published similar to PhD thesis

How do we objectively assess if a dialogue sounds unnatural or cringy?

What is the purpose of a disclaimer like "this is not legal advice"?

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

The (Easy) Road to Code

Can inspiration allow the Rogue to make a Sneak Attack?

Naming Characters after Friends/Family

Why won't the strings command stop?



Commonest[] function doesn't actually show commonest elements


Issues with a Counter that is tallying term appearancesHow does `LongestCommonSubsequence` work?Sorting an Array with words in different languagestext analysis: split document in seperated linesGraph showing valid English words obtained by insertion of single charactersAnalyzing frequency of individual letters in a large body of textHow to translate/convert UTF-16 code to its corresponding word/characters by Mathematica?Helping Mandy become a better spellerMost common prefixes in an English corpus (Hamlet)Optimisation of a loop













3












$begingroup$


I'm using Commonest function on a list with 500000 words to get 10 most frequent elements. Then by using WordCloud i found out that most frequent word is actually "far", and then checked it by StringCount. So the thing i would like to know is why results from WordCloud and Commonest are so different, and how to make Commonest work properly?



File with words i used



(Sorry for all mistakes, English is only my 3rd language..)



enter image description here










share|improve this question











$endgroup$












  • $begingroup$
    It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
    $endgroup$
    – Carl Woll
    50 mins ago










  • $begingroup$
    I removed the bugs tag for now, in accordance with the tag description.
    $endgroup$
    – Szabolcs
    40 mins ago












  • $begingroup$
    @CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
    $endgroup$
    – Szabolcs
    38 mins ago












  • $begingroup$
    @Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
    $endgroup$
    – Carl Lange
    28 mins ago












  • $begingroup$
    It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
    $endgroup$
    – Carl Lange
    18 mins ago


















3












$begingroup$


I'm using Commonest function on a list with 500000 words to get 10 most frequent elements. Then by using WordCloud i found out that most frequent word is actually "far", and then checked it by StringCount. So the thing i would like to know is why results from WordCloud and Commonest are so different, and how to make Commonest work properly?



File with words i used



(Sorry for all mistakes, English is only my 3rd language..)



enter image description here










share|improve this question











$endgroup$












  • $begingroup$
    It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
    $endgroup$
    – Carl Woll
    50 mins ago










  • $begingroup$
    I removed the bugs tag for now, in accordance with the tag description.
    $endgroup$
    – Szabolcs
    40 mins ago












  • $begingroup$
    @CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
    $endgroup$
    – Szabolcs
    38 mins ago












  • $begingroup$
    @Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
    $endgroup$
    – Carl Lange
    28 mins ago












  • $begingroup$
    It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
    $endgroup$
    – Carl Lange
    18 mins ago
















3












3








3





$begingroup$


I'm using Commonest function on a list with 500000 words to get 10 most frequent elements. Then by using WordCloud i found out that most frequent word is actually "far", and then checked it by StringCount. So the thing i would like to know is why results from WordCloud and Commonest are so different, and how to make Commonest work properly?



File with words i used



(Sorry for all mistakes, English is only my 3rd language..)



enter image description here










share|improve this question











$endgroup$




I'm using Commonest function on a list with 500000 words to get 10 most frequent elements. Then by using WordCloud i found out that most frequent word is actually "far", and then checked it by StringCount. So the thing i would like to know is why results from WordCloud and Commonest are so different, and how to make Commonest work properly?



File with words i used



(Sorry for all mistakes, English is only my 3rd language..)



enter image description here







list-manipulation string-manipulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 42 mins ago









Szabolcs

161k14440938




161k14440938










asked 57 mins ago









AplefullAplefull

453




453












  • $begingroup$
    It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
    $endgroup$
    – Carl Woll
    50 mins ago










  • $begingroup$
    I removed the bugs tag for now, in accordance with the tag description.
    $endgroup$
    – Szabolcs
    40 mins ago












  • $begingroup$
    @CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
    $endgroup$
    – Szabolcs
    38 mins ago












  • $begingroup$
    @Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
    $endgroup$
    – Carl Lange
    28 mins ago












  • $begingroup$
    It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
    $endgroup$
    – Carl Lange
    18 mins ago




















  • $begingroup$
    It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
    $endgroup$
    – Carl Woll
    50 mins ago










  • $begingroup$
    I removed the bugs tag for now, in accordance with the tag description.
    $endgroup$
    – Szabolcs
    40 mins ago












  • $begingroup$
    @CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
    $endgroup$
    – Szabolcs
    38 mins ago












  • $begingroup$
    @Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
    $endgroup$
    – Carl Lange
    28 mins ago












  • $begingroup$
    It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
    $endgroup$
    – Carl Lange
    18 mins ago


















$begingroup$
It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
$endgroup$
– Carl Woll
50 mins ago




$begingroup$
It's because "far" is a part of many of the words, e.g., "afar", "farsighted", "airfare", etc.
$endgroup$
– Carl Woll
50 mins ago












$begingroup$
I removed the bugs tag for now, in accordance with the tag description.
$endgroup$
– Szabolcs
40 mins ago






$begingroup$
I removed the bugs tag for now, in accordance with the tag description.
$endgroup$
– Szabolcs
40 mins ago














$begingroup$
@CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
$endgroup$
– Szabolcs
38 mins ago






$begingroup$
@CarlWoll Commonest definitely works correctly (can be verified with Counts/Tally). As for the WordCloud behaviour, I'm very sceptical about this, I would not consider it correct ... bug?
$endgroup$
– Szabolcs
38 mins ago














$begingroup$
@Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
$endgroup$
– Carl Lange
28 mins ago






$begingroup$
@Szabolcs The bug is within DeleteStopwords, if it is a bug - I show it at the bottom of my answer.
$endgroup$
– Carl Lange
28 mins ago














$begingroup$
It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
$endgroup$
– Carl Lange
18 mins ago






$begingroup$
It seems to me like DeleteStopwords, which WordCloud uses by default, is deleting a lot of words that it ought not be deleting, such as "custom-made", "runner-up", "interest" and so on (Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]). Perhaps it would be good to report this to WRI and see if they consider it a bug. OP, I would rename this question something like "WordCloud processes input text badly".
$endgroup$
– Carl Lange
18 mins ago












1 Answer
1






active

oldest

votes


















5












$begingroup$

You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart".



Commonest[TextWords[txt], 10]



{"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"}




WordCloud[TextWords[txt]]


enter image description here



You can use Counts to get the counts of each word as well:



TakeLargest[Counts[TextWords[txt]], 20]



<|"affirm" -> 29, "equation" -> 28, "veronica" -> 28, "ashen" -> 28,
"crispness" -> 28, "knacker" -> 27, "validly" -> 27,
"squander" -> 27, "nematode" -> 27, "autoimmune" -> 27,
"calligrapher" -> 27, "pus" -> 26, "sledding" -> 26,
"tablecloth" -> 26, "inclusive" -> 26, "variegated" -> 26,
"gastrointestinal" -> 26, "undercoat" -> 26, "washout" -> 26,
"reconnoitering" -> 26|>




It seems to me that the issue with WordCloud is actually an issue within DeleteStopwords, which WordCloud is using internally when the input is a string.



enter image description here



You can prevent WordCloud from using DeleteStopwords by passing PreprocessingRules -> None:



enter image description here



It seems to me that DeleteStopwords is deleting many words that perhaps it shouldn't be:



Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]



{"a", "about", "above", "across", "add-on", "after", "again", 
"against", "all", "almost", "alone", "along", "already", "also",
"although", "always", "among", "an", "and", "another", "any",
"anyone", "anything", "anywhere", "are", "around", "as", "at",
"back", "back-to-back", "be", "because", "become", "before",
"behind", "being", "below", "between", "born-again", "both",
"built-in", "but", "by", "can-do", "custom-made", "do", "done",
"down", "during", "each", "either", "enough", "even", "ever",
"every", "everyone", "everything", "everywhere", "far-off",
"far-out", "few", "find", "first", "for", "four", "from", "full",
"further", "get", "give", "go", "have-not", "he", "head-on", "her",
"here", "hers", "herself", "him", "himself", "his", "how", "however",
"if", "in", "interest", "into", "it", "its", "itself", "keep",
"laid-back", "last", "least", "less", "ma'am", "made", "man-made",
"many", "may", "me", "might", "more", "most", "mostly", "much",
"must", "my", "myself", "never", "next", "nobody", "nor", "no-show",
"not", "nothing", "now", "nowhere", "of", "off", "often", "on",
"once", "one", "only", "other", "our", "ours", "ourselves", "out",
"over", "own", "part", "per", "perhaps", "put", "rather",
"runner-up", "same", "seem", "seeming", "see-through",
"self-interest", "self-made", "several", "she", "show", "side",
"since", "sit-in", "so", "some", "someone", "something", "somewhere",
"still", "such", "take", "than", "that", "the", "their", "theirs",
"them", "themselves", "then", "there", "therefore", "these", "they",
"this", "those", "though", "three", "through", "thus", "to",
"together", "too", "toward", "two", "under", "until", "up", "upon",
"us", "very", "we", "well", "well-to-do", "what", "when", "where",
"where's", "whether", "which", "while", "who", "whole", "whom",
"whose", "why", "will", "with", "within", "without", "would-be",
"write-off", "yet", "you", "your", "yours", "yourself"}



I agree with some of those stopwords, but not really any of them that contain the - character. This is perhaps where the issue lies.



What appears to be happening is that DeleteStopwords is deleting part of some words, and what's left over is counted. We can see the outcome:



Counts[TextWords[txt]]["far"]



19




Counts[TextWords[DeleteStopwords[txt]]]["far"]



39




We can see that this behaviour is weird by comparing the following:



Select[TextWords[txt], StringStartsQ["far"]] // Counts // ReverseSort



<|"farinaceous" -> 19, "far" -> 19, "fare" -> 19, "faro" -> 18,
"farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
"faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
"farthermost" -> 14, "far-off" -> 14, "farming" -> 14,
"farrago" -> 13, "farm" -> 13, "farcically" -> 13, "farrowing" -> 12,
"farce" -> 11, "farsighted" -> 11, "farmland" -> 10,
"farsightedness" -> 10, "farmhouse" -> 9, "farseeing" -> 9,
"farad" -> 8, "farina" -> 8, "farthest" -> 8, "farmhand" -> 7,
"farewell" -> 7, "farrow" -> 6, "farmyard" -> 6, "far-out" -> 6|>




Select[TextWords[DeleteStopwords@txt], StringStartsQ["far"]] // Counts // ReverseSort



<|"far" -> 39, "farinaceous" -> 19, "fare" -> 19, "faro" -> 18,
"farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
"faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
"farthermost" -> 14, "farming" -> 14, "farrago" -> 13, "farm" -> 13,
"farcically" -> 13, "farrowing" -> 12, "farce" -> 11,
"farsighted" -> 11, "farmland" -> 10, "farsightedness" -> 10,
"farmhouse" -> 9, "farseeing" -> 9, "farad" -> 8, "farina" -> 8,
"farthest" -> 8, "farmhand" -> 7, "farewell" -> 7, "farrow" -> 6,
"farmyard" -> 6|>




Here we can see that DeleteStopwords is replacing "far-out" and "far-off" with "far-", which is segmented to "far" by TextWords, which completely throws off WordCloud's counting mechanism in this case.






share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192806%2fcommonest-function-doesnt-actually-show-commonest-elements%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5












    $begingroup$

    You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart".



    Commonest[TextWords[txt], 10]



    {"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"}




    WordCloud[TextWords[txt]]


    enter image description here



    You can use Counts to get the counts of each word as well:



    TakeLargest[Counts[TextWords[txt]], 20]



    <|"affirm" -> 29, "equation" -> 28, "veronica" -> 28, "ashen" -> 28,
    "crispness" -> 28, "knacker" -> 27, "validly" -> 27,
    "squander" -> 27, "nematode" -> 27, "autoimmune" -> 27,
    "calligrapher" -> 27, "pus" -> 26, "sledding" -> 26,
    "tablecloth" -> 26, "inclusive" -> 26, "variegated" -> 26,
    "gastrointestinal" -> 26, "undercoat" -> 26, "washout" -> 26,
    "reconnoitering" -> 26|>




    It seems to me that the issue with WordCloud is actually an issue within DeleteStopwords, which WordCloud is using internally when the input is a string.



    enter image description here



    You can prevent WordCloud from using DeleteStopwords by passing PreprocessingRules -> None:



    enter image description here



    It seems to me that DeleteStopwords is deleting many words that perhaps it shouldn't be:



    Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]



    {"a", "about", "above", "across", "add-on", "after", "again", 
    "against", "all", "almost", "alone", "along", "already", "also",
    "although", "always", "among", "an", "and", "another", "any",
    "anyone", "anything", "anywhere", "are", "around", "as", "at",
    "back", "back-to-back", "be", "because", "become", "before",
    "behind", "being", "below", "between", "born-again", "both",
    "built-in", "but", "by", "can-do", "custom-made", "do", "done",
    "down", "during", "each", "either", "enough", "even", "ever",
    "every", "everyone", "everything", "everywhere", "far-off",
    "far-out", "few", "find", "first", "for", "four", "from", "full",
    "further", "get", "give", "go", "have-not", "he", "head-on", "her",
    "here", "hers", "herself", "him", "himself", "his", "how", "however",
    "if", "in", "interest", "into", "it", "its", "itself", "keep",
    "laid-back", "last", "least", "less", "ma'am", "made", "man-made",
    "many", "may", "me", "might", "more", "most", "mostly", "much",
    "must", "my", "myself", "never", "next", "nobody", "nor", "no-show",
    "not", "nothing", "now", "nowhere", "of", "off", "often", "on",
    "once", "one", "only", "other", "our", "ours", "ourselves", "out",
    "over", "own", "part", "per", "perhaps", "put", "rather",
    "runner-up", "same", "seem", "seeming", "see-through",
    "self-interest", "self-made", "several", "she", "show", "side",
    "since", "sit-in", "so", "some", "someone", "something", "somewhere",
    "still", "such", "take", "than", "that", "the", "their", "theirs",
    "them", "themselves", "then", "there", "therefore", "these", "they",
    "this", "those", "though", "three", "through", "thus", "to",
    "together", "too", "toward", "two", "under", "until", "up", "upon",
    "us", "very", "we", "well", "well-to-do", "what", "when", "where",
    "where's", "whether", "which", "while", "who", "whole", "whom",
    "whose", "why", "will", "with", "within", "without", "would-be",
    "write-off", "yet", "you", "your", "yours", "yourself"}



    I agree with some of those stopwords, but not really any of them that contain the - character. This is perhaps where the issue lies.



    What appears to be happening is that DeleteStopwords is deleting part of some words, and what's left over is counted. We can see the outcome:



    Counts[TextWords[txt]]["far"]



    19




    Counts[TextWords[DeleteStopwords[txt]]]["far"]



    39




    We can see that this behaviour is weird by comparing the following:



    Select[TextWords[txt], StringStartsQ["far"]] // Counts // ReverseSort



    <|"farinaceous" -> 19, "far" -> 19, "fare" -> 19, "faro" -> 18,
    "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
    "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
    "farthermost" -> 14, "far-off" -> 14, "farming" -> 14,
    "farrago" -> 13, "farm" -> 13, "farcically" -> 13, "farrowing" -> 12,
    "farce" -> 11, "farsighted" -> 11, "farmland" -> 10,
    "farsightedness" -> 10, "farmhouse" -> 9, "farseeing" -> 9,
    "farad" -> 8, "farina" -> 8, "farthest" -> 8, "farmhand" -> 7,
    "farewell" -> 7, "farrow" -> 6, "farmyard" -> 6, "far-out" -> 6|>




    Select[TextWords[DeleteStopwords@txt], StringStartsQ["far"]] // Counts // ReverseSort



    <|"far" -> 39, "farinaceous" -> 19, "fare" -> 19, "faro" -> 18,
    "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
    "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
    "farthermost" -> 14, "farming" -> 14, "farrago" -> 13, "farm" -> 13,
    "farcically" -> 13, "farrowing" -> 12, "farce" -> 11,
    "farsighted" -> 11, "farmland" -> 10, "farsightedness" -> 10,
    "farmhouse" -> 9, "farseeing" -> 9, "farad" -> 8, "farina" -> 8,
    "farthest" -> 8, "farmhand" -> 7, "farewell" -> 7, "farrow" -> 6,
    "farmyard" -> 6|>




    Here we can see that DeleteStopwords is replacing "far-out" and "far-off" with "far-", which is segmented to "far" by TextWords, which completely throws off WordCloud's counting mechanism in this case.






    share|improve this answer











    $endgroup$


















      5












      $begingroup$

      You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart".



      Commonest[TextWords[txt], 10]



      {"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"}




      WordCloud[TextWords[txt]]


      enter image description here



      You can use Counts to get the counts of each word as well:



      TakeLargest[Counts[TextWords[txt]], 20]



      <|"affirm" -> 29, "equation" -> 28, "veronica" -> 28, "ashen" -> 28,
      "crispness" -> 28, "knacker" -> 27, "validly" -> 27,
      "squander" -> 27, "nematode" -> 27, "autoimmune" -> 27,
      "calligrapher" -> 27, "pus" -> 26, "sledding" -> 26,
      "tablecloth" -> 26, "inclusive" -> 26, "variegated" -> 26,
      "gastrointestinal" -> 26, "undercoat" -> 26, "washout" -> 26,
      "reconnoitering" -> 26|>




      It seems to me that the issue with WordCloud is actually an issue within DeleteStopwords, which WordCloud is using internally when the input is a string.



      enter image description here



      You can prevent WordCloud from using DeleteStopwords by passing PreprocessingRules -> None:



      enter image description here



      It seems to me that DeleteStopwords is deleting many words that perhaps it shouldn't be:



      Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]



      {"a", "about", "above", "across", "add-on", "after", "again", 
      "against", "all", "almost", "alone", "along", "already", "also",
      "although", "always", "among", "an", "and", "another", "any",
      "anyone", "anything", "anywhere", "are", "around", "as", "at",
      "back", "back-to-back", "be", "because", "become", "before",
      "behind", "being", "below", "between", "born-again", "both",
      "built-in", "but", "by", "can-do", "custom-made", "do", "done",
      "down", "during", "each", "either", "enough", "even", "ever",
      "every", "everyone", "everything", "everywhere", "far-off",
      "far-out", "few", "find", "first", "for", "four", "from", "full",
      "further", "get", "give", "go", "have-not", "he", "head-on", "her",
      "here", "hers", "herself", "him", "himself", "his", "how", "however",
      "if", "in", "interest", "into", "it", "its", "itself", "keep",
      "laid-back", "last", "least", "less", "ma'am", "made", "man-made",
      "many", "may", "me", "might", "more", "most", "mostly", "much",
      "must", "my", "myself", "never", "next", "nobody", "nor", "no-show",
      "not", "nothing", "now", "nowhere", "of", "off", "often", "on",
      "once", "one", "only", "other", "our", "ours", "ourselves", "out",
      "over", "own", "part", "per", "perhaps", "put", "rather",
      "runner-up", "same", "seem", "seeming", "see-through",
      "self-interest", "self-made", "several", "she", "show", "side",
      "since", "sit-in", "so", "some", "someone", "something", "somewhere",
      "still", "such", "take", "than", "that", "the", "their", "theirs",
      "them", "themselves", "then", "there", "therefore", "these", "they",
      "this", "those", "though", "three", "through", "thus", "to",
      "together", "too", "toward", "two", "under", "until", "up", "upon",
      "us", "very", "we", "well", "well-to-do", "what", "when", "where",
      "where's", "whether", "which", "while", "who", "whole", "whom",
      "whose", "why", "will", "with", "within", "without", "would-be",
      "write-off", "yet", "you", "your", "yours", "yourself"}



      I agree with some of those stopwords, but not really any of them that contain the - character. This is perhaps where the issue lies.



      What appears to be happening is that DeleteStopwords is deleting part of some words, and what's left over is counted. We can see the outcome:



      Counts[TextWords[txt]]["far"]



      19




      Counts[TextWords[DeleteStopwords[txt]]]["far"]



      39




      We can see that this behaviour is weird by comparing the following:



      Select[TextWords[txt], StringStartsQ["far"]] // Counts // ReverseSort



      <|"farinaceous" -> 19, "far" -> 19, "fare" -> 19, "faro" -> 18,
      "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
      "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
      "farthermost" -> 14, "far-off" -> 14, "farming" -> 14,
      "farrago" -> 13, "farm" -> 13, "farcically" -> 13, "farrowing" -> 12,
      "farce" -> 11, "farsighted" -> 11, "farmland" -> 10,
      "farsightedness" -> 10, "farmhouse" -> 9, "farseeing" -> 9,
      "farad" -> 8, "farina" -> 8, "farthest" -> 8, "farmhand" -> 7,
      "farewell" -> 7, "farrow" -> 6, "farmyard" -> 6, "far-out" -> 6|>




      Select[TextWords[DeleteStopwords@txt], StringStartsQ["far"]] // Counts // ReverseSort



      <|"far" -> 39, "farinaceous" -> 19, "fare" -> 19, "faro" -> 18,
      "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
      "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
      "farthermost" -> 14, "farming" -> 14, "farrago" -> 13, "farm" -> 13,
      "farcically" -> 13, "farrowing" -> 12, "farce" -> 11,
      "farsighted" -> 11, "farmland" -> 10, "farsightedness" -> 10,
      "farmhouse" -> 9, "farseeing" -> 9, "farad" -> 8, "farina" -> 8,
      "farthest" -> 8, "farmhand" -> 7, "farewell" -> 7, "farrow" -> 6,
      "farmyard" -> 6|>




      Here we can see that DeleteStopwords is replacing "far-out" and "far-off" with "far-", which is segmented to "far" by TextWords, which completely throws off WordCloud's counting mechanism in this case.






      share|improve this answer











      $endgroup$
















        5












        5








        5





        $begingroup$

        You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart".



        Commonest[TextWords[txt], 10]



        {"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"}




        WordCloud[TextWords[txt]]


        enter image description here



        You can use Counts to get the counts of each word as well:



        TakeLargest[Counts[TextWords[txt]], 20]



        <|"affirm" -> 29, "equation" -> 28, "veronica" -> 28, "ashen" -> 28,
        "crispness" -> 28, "knacker" -> 27, "validly" -> 27,
        "squander" -> 27, "nematode" -> 27, "autoimmune" -> 27,
        "calligrapher" -> 27, "pus" -> 26, "sledding" -> 26,
        "tablecloth" -> 26, "inclusive" -> 26, "variegated" -> 26,
        "gastrointestinal" -> 26, "undercoat" -> 26, "washout" -> 26,
        "reconnoitering" -> 26|>




        It seems to me that the issue with WordCloud is actually an issue within DeleteStopwords, which WordCloud is using internally when the input is a string.



        enter image description here



        You can prevent WordCloud from using DeleteStopwords by passing PreprocessingRules -> None:



        enter image description here



        It seems to me that DeleteStopwords is deleting many words that perhaps it shouldn't be:



        Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]



        {"a", "about", "above", "across", "add-on", "after", "again", 
        "against", "all", "almost", "alone", "along", "already", "also",
        "although", "always", "among", "an", "and", "another", "any",
        "anyone", "anything", "anywhere", "are", "around", "as", "at",
        "back", "back-to-back", "be", "because", "become", "before",
        "behind", "being", "below", "between", "born-again", "both",
        "built-in", "but", "by", "can-do", "custom-made", "do", "done",
        "down", "during", "each", "either", "enough", "even", "ever",
        "every", "everyone", "everything", "everywhere", "far-off",
        "far-out", "few", "find", "first", "for", "four", "from", "full",
        "further", "get", "give", "go", "have-not", "he", "head-on", "her",
        "here", "hers", "herself", "him", "himself", "his", "how", "however",
        "if", "in", "interest", "into", "it", "its", "itself", "keep",
        "laid-back", "last", "least", "less", "ma'am", "made", "man-made",
        "many", "may", "me", "might", "more", "most", "mostly", "much",
        "must", "my", "myself", "never", "next", "nobody", "nor", "no-show",
        "not", "nothing", "now", "nowhere", "of", "off", "often", "on",
        "once", "one", "only", "other", "our", "ours", "ourselves", "out",
        "over", "own", "part", "per", "perhaps", "put", "rather",
        "runner-up", "same", "seem", "seeming", "see-through",
        "self-interest", "self-made", "several", "she", "show", "side",
        "since", "sit-in", "so", "some", "someone", "something", "somewhere",
        "still", "such", "take", "than", "that", "the", "their", "theirs",
        "them", "themselves", "then", "there", "therefore", "these", "they",
        "this", "those", "though", "three", "through", "thus", "to",
        "together", "too", "toward", "two", "under", "until", "up", "upon",
        "us", "very", "we", "well", "well-to-do", "what", "when", "where",
        "where's", "whether", "which", "while", "who", "whole", "whom",
        "whose", "why", "will", "with", "within", "without", "would-be",
        "write-off", "yet", "you", "your", "yours", "yourself"}



        I agree with some of those stopwords, but not really any of them that contain the - character. This is perhaps where the issue lies.



        What appears to be happening is that DeleteStopwords is deleting part of some words, and what's left over is counted. We can see the outcome:



        Counts[TextWords[txt]]["far"]



        19




        Counts[TextWords[DeleteStopwords[txt]]]["far"]



        39




        We can see that this behaviour is weird by comparing the following:



        Select[TextWords[txt], StringStartsQ["far"]] // Counts // ReverseSort



        <|"farinaceous" -> 19, "far" -> 19, "fare" -> 19, "faro" -> 18,
        "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
        "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
        "farthermost" -> 14, "far-off" -> 14, "farming" -> 14,
        "farrago" -> 13, "farm" -> 13, "farcically" -> 13, "farrowing" -> 12,
        "farce" -> 11, "farsighted" -> 11, "farmland" -> 10,
        "farsightedness" -> 10, "farmhouse" -> 9, "farseeing" -> 9,
        "farad" -> 8, "farina" -> 8, "farthest" -> 8, "farmhand" -> 7,
        "farewell" -> 7, "farrow" -> 6, "farmyard" -> 6, "far-out" -> 6|>




        Select[TextWords[DeleteStopwords@txt], StringStartsQ["far"]] // Counts // ReverseSort



        <|"far" -> 39, "farinaceous" -> 19, "fare" -> 19, "faro" -> 18,
        "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
        "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
        "farthermost" -> 14, "farming" -> 14, "farrago" -> 13, "farm" -> 13,
        "farcically" -> 13, "farrowing" -> 12, "farce" -> 11,
        "farsighted" -> 11, "farmland" -> 10, "farsightedness" -> 10,
        "farmhouse" -> 9, "farseeing" -> 9, "farad" -> 8, "farina" -> 8,
        "farthest" -> 8, "farmhand" -> 7, "farewell" -> 7, "farrow" -> 6,
        "farmyard" -> 6|>




        Here we can see that DeleteStopwords is replacing "far-out" and "far-off" with "far-", which is segmented to "far" by TextWords, which completely throws off WordCloud's counting mechanism in this case.






        share|improve this answer











        $endgroup$



        You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart".



        Commonest[TextWords[txt], 10]



        {"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"}




        WordCloud[TextWords[txt]]


        enter image description here



        You can use Counts to get the counts of each word as well:



        TakeLargest[Counts[TextWords[txt]], 20]



        <|"affirm" -> 29, "equation" -> 28, "veronica" -> 28, "ashen" -> 28,
        "crispness" -> 28, "knacker" -> 27, "validly" -> 27,
        "squander" -> 27, "nematode" -> 27, "autoimmune" -> 27,
        "calligrapher" -> 27, "pus" -> 26, "sledding" -> 26,
        "tablecloth" -> 26, "inclusive" -> 26, "variegated" -> 26,
        "gastrointestinal" -> 26, "undercoat" -> 26, "washout" -> 26,
        "reconnoitering" -> 26|>




        It seems to me that the issue with WordCloud is actually an issue within DeleteStopwords, which WordCloud is using internally when the input is a string.



        enter image description here



        You can prevent WordCloud from using DeleteStopwords by passing PreprocessingRules -> None:



        enter image description here



        It seems to me that DeleteStopwords is deleting many words that perhaps it shouldn't be:



        Complement[TextWords[txt], TextWords[DeleteStopwords[txt]]]



        {"a", "about", "above", "across", "add-on", "after", "again", 
        "against", "all", "almost", "alone", "along", "already", "also",
        "although", "always", "among", "an", "and", "another", "any",
        "anyone", "anything", "anywhere", "are", "around", "as", "at",
        "back", "back-to-back", "be", "because", "become", "before",
        "behind", "being", "below", "between", "born-again", "both",
        "built-in", "but", "by", "can-do", "custom-made", "do", "done",
        "down", "during", "each", "either", "enough", "even", "ever",
        "every", "everyone", "everything", "everywhere", "far-off",
        "far-out", "few", "find", "first", "for", "four", "from", "full",
        "further", "get", "give", "go", "have-not", "he", "head-on", "her",
        "here", "hers", "herself", "him", "himself", "his", "how", "however",
        "if", "in", "interest", "into", "it", "its", "itself", "keep",
        "laid-back", "last", "least", "less", "ma'am", "made", "man-made",
        "many", "may", "me", "might", "more", "most", "mostly", "much",
        "must", "my", "myself", "never", "next", "nobody", "nor", "no-show",
        "not", "nothing", "now", "nowhere", "of", "off", "often", "on",
        "once", "one", "only", "other", "our", "ours", "ourselves", "out",
        "over", "own", "part", "per", "perhaps", "put", "rather",
        "runner-up", "same", "seem", "seeming", "see-through",
        "self-interest", "self-made", "several", "she", "show", "side",
        "since", "sit-in", "so", "some", "someone", "something", "somewhere",
        "still", "such", "take", "than", "that", "the", "their", "theirs",
        "them", "themselves", "then", "there", "therefore", "these", "they",
        "this", "those", "though", "three", "through", "thus", "to",
        "together", "too", "toward", "two", "under", "until", "up", "upon",
        "us", "very", "we", "well", "well-to-do", "what", "when", "where",
        "where's", "whether", "which", "while", "who", "whole", "whom",
        "whose", "why", "will", "with", "within", "without", "would-be",
        "write-off", "yet", "you", "your", "yours", "yourself"}



        I agree with some of those stopwords, but not really any of them that contain the - character. This is perhaps where the issue lies.



        What appears to be happening is that DeleteStopwords is deleting part of some words, and what's left over is counted. We can see the outcome:



        Counts[TextWords[txt]]["far"]



        19




        Counts[TextWords[DeleteStopwords[txt]]]["far"]



        39




        We can see that this behaviour is weird by comparing the following:



        Select[TextWords[txt], StringStartsQ["far"]] // Counts // ReverseSort



        <|"farinaceous" -> 19, "far" -> 19, "fare" -> 19, "faro" -> 18,
        "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
        "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
        "farthermost" -> 14, "far-off" -> 14, "farming" -> 14,
        "farrago" -> 13, "farm" -> 13, "farcically" -> 13, "farrowing" -> 12,
        "farce" -> 11, "farsighted" -> 11, "farmland" -> 10,
        "farsightedness" -> 10, "farmhouse" -> 9, "farseeing" -> 9,
        "farad" -> 8, "farina" -> 8, "farthest" -> 8, "farmhand" -> 7,
        "farewell" -> 7, "farrow" -> 6, "farmyard" -> 6, "far-out" -> 6|>




        Select[TextWords[DeleteStopwords@txt], StringStartsQ["far"]] // Counts // ReverseSort



        <|"far" -> 39, "farinaceous" -> 19, "fare" -> 19, "faro" -> 18,
        "farther" -> 17, "farmer" -> 17, "farcical" -> 17, "farthing" -> 17,
        "faraway" -> 16, "farmstead" -> 16, "farrier" -> 15,
        "farthermost" -> 14, "farming" -> 14, "farrago" -> 13, "farm" -> 13,
        "farcically" -> 13, "farrowing" -> 12, "farce" -> 11,
        "farsighted" -> 11, "farmland" -> 10, "farsightedness" -> 10,
        "farmhouse" -> 9, "farseeing" -> 9, "farad" -> 8, "farina" -> 8,
        "farthest" -> 8, "farmhand" -> 7, "farewell" -> 7, "farrow" -> 6,
        "farmyard" -> 6|>




        Here we can see that DeleteStopwords is replacing "far-out" and "far-off" with "far-", which is segmented to "far" by TextWords, which completely throws off WordCloud's counting mechanism in this case.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 5 mins ago

























        answered 36 mins ago









        Carl LangeCarl Lange

        4,2081735




        4,2081735






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192806%2fcommonest-function-doesnt-actually-show-commonest-elements%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Armoriale delle famiglie italiane (Car) Indice Armi | Bibliografia | Menu di navigazioneBlasone...

            Why does this relation fail symmetry and transitivity properties?Properties of Relations. Reflexive,...

            why typing a variable (or expression) prints the value to stdout?Calling a function of a module by using its...