Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:54:18+00:00 2026-05-17T19:54:18+00:00

This is weird, so be patient while I try to explain. Basic problem: I

  • 0

This is weird, so be patient while I try to explain.

Basic problem: I have a massive string — it can be of varying lengths depending on the user. My job is to acquire this massive string depending on the user, then send it off to the other piece of software to make a tag cloud. If life were easy for me, I could simply send the whole thing. However, the tag cloud software will only accept a string that is 1000 words long, so I need to do some work on my string to send the most important words.

My first thought was to count each occurrence of the words, and throw all this into an array with each word’s count, then sort.

array(517) (
    "We" => integer 4
    "Five" => integer 1
    "Ten's" => integer 1
    "best" => integer 2
    "climbing" => integer 3
     (etc...)

Form here, I create a new string and spit out each word times its count. Once the total string hits 1000 words long, I stop. This creates a problem.

Let’s say the word “apple” shows up 900 times, and the word “cat” shows up 100 times. The resulting word cloud would consist of only two words.

My idea is to somehow spit out the words at some sort of ratio to the other words. My attempts so far have failed on different data sets where the ratio is not great — especially when there are a lot of words at “1”, thus making the GCD very low.

I figure this is a simple math problem I can’t get my head around, so I turn to the oracle that is stackoverflow.

thanks in advance.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:54:19+00:00Added an answer on May 17, 2026 at 7:54 pm

    count all words then do this for each word in your array:

    floor(count_of_the_word * (1000/numbber_of_total_words))
    

    this will result in a maximum of 1000 words and all word appear in x times reduced by the according proportion.

    so having 50 times cat 100 times gozilla 4000 looser and 4000 times bush 1000 times george will first result in

    array(
        cat[50]
        gozilla[100]
        looser[4000]
        bush[4000]
        george[1000]
    )
    

    after looping and converting the numbers you will get this:

    array(
        cat[5]
        gozilla[10]
        looser[437]
        bush[437]
        george[109]
    )
    

    resulting in 998 total words

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I had this weird problem a little while ago and haven't been able to
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have this weird problem where my Google Maps API script doesn't work, no
I have this weird problem whenever I roll my mouse over each of the
can anyone explain me this weird browser behavior: gist link It seems to be,
I have this weird kind of error. I am trying implement basic Euclidean algorithm
I have this weird problem, when I create a calendar with a locale, the
I have this weird bug that I cannot fix. Can anyone help me? Thank
Hi I have this weird problem with Google Maps V3 API. Showing multiple markers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.