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

  • Home
  • SEARCH
  • 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
  • 0 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

This is weird. It is a trivial problem: A std::string with bits with length
This is a weird problem I have started having recently. My team is developing
I've got this weird problem - I'm calling ChangeServiceConfig on a newly installed service
I'm experiencing this weird problem which my scrollbar jumps by itself to somewhere that
Today, I ran into this weird problem with a user using Mac OS X.
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
This is pretty weird. I have my Profiler open and it obviously shows that
This could be weird, Have you ever come across a blog which you wanted
This one is weird, I have a page that consists of a html table
I've seen this weird behavior on several sites recently: I scroll down a page

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.