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 7830795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:24:40+00:00 2026-06-02T11:24:40+00:00

For my program I am creating an inverted index using data from the Twitter

  • 0

For my program I am creating an inverted index using data from the Twitter feed, however, when parsing and putting them into the mongodb, some funny problems occur.

The usual type of entry should be like this:

{"ax"=>1, "easyjet"=>1, "from"=>2}

However, when parsing some of the tweets they end up like this in the db:

{""=>{""=>{""=>{""=>{""=>{"giants"=>{"dhem"=>1, "giants"=>1, "giantss"=>1}}}}

I have got these lines that split a tweet up and increments the values in the db:

def pull_hash_tags(tweet, lang)
    hash_tags = tweet.split.find_all { |word| /^#.+/.match word }
    t = tweet.gsub(/https?:\/\/[\S]+/,"") # removing urls
    t = t.gsub(/#\w+/,"") # removing hash tags
    t = t.gsub(/[^0-9a-z ]/i, '') # removing non-alphanumerics and keeping spaces
    t = t.gsub(/\r/," ")
    t = t.gsub(/\n/," ")
    hash_tags.each { |tag| add_to_hash(lang, tag, t) }
end

def add_to_hash(lang, tag, t)
    t.gsub(/\W+/, ' ').split.each { |word| @db.collection.update({"_id" => lang}, {"$inc" => {"#{tag}.#{word}" => 1}}, { :upsert => true }) }
end

I’m trying to get normal words (with only alphanumeric characters) and no double spaces, and no carriage returns etc.

  • 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-06-02T11:24:41+00:00Added an answer on June 2, 2026 at 11:24 am

    You should add t.strip! as it seems the problem might be leading/trailing whitespace.

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

Sidebar

Related Questions

I am creating a program that is going to insert data into a table
I'm creating a program that authenticates from a before it runs. I also want
I'm creating a program using C# (in ASP.NET environment) that makes an XML file.
I'm creating a program in C# using System.Speech.Recognition that recognizes voice commands and translates
I use the following program for creating JTable using java class. If I get
I am creating a program that will be installed using the .net installer project.
I am creating a program that needs to store the user's data in encrypted
I am creating a program which can send test or data to Bluetooth devices.
I am creating a program using Visual Basic 2010 Express . I want to
I'm creating a program using C# and I have lots of textbox and buttons.

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.