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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:23:53+00:00 2026-05-20T09:23:53+00:00

Let’s pretend that I have a site where the users create topics and write

  • 0

Let’s pretend that I have a site where the users create topics and write threads on Fruit.

To keep the users informed of all Fruit conversations on the entire web, I collect tweets related to the specific topic and create threads based on the contents of the tweet.

It’s really important that the tweets are relevant to the topic, obviously. Let’s say that a user creates a topic called Apples and Oranges. I pull all tweets that contains the keywords Apples an/or Oranges.

The problem that I’m having is that some twitter users write a tweet that includes the keywords Apples, Oranges, Pears, for example, and it gets collected and posted as a thread to the Apples and Oranges discussion topic. This makes the users angry!

So what I need is a way to filter out any tweet that includes fruit words other than Apples and/or Oranges.

For example, if a twitter user writes “I love Apples, Oranges, Pears, and Grapes” then that tweet should not be included.

Now you can only make the Twitter search query so sophisticated. So the exclusion logic will have to be performed in Ruby after the tweets are collected.

Programmatically, how would you go about solving this?

  • 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-20T09:23:54+00:00Added an answer on May 20, 2026 at 9:23 am

    Determine the words that are related to the topic name. Pears, grapes, etc. You can then exclude tweets that use these related words.

    One way to do this is using Google Sets.

    NOTE: I am in the unfortunate position of not fully condoning my own solution due to this service not having an official API (as awesome as this would be!). Though if you are going to use this strategy then I would suggest storing the Google Set result.

    require 'google_set'
    
    twitter_search_terms = ['apples', 'oranges']
    # Mocked twitter search method
    tweets = search_twitter(twitter_search_terms)
    # returns ["Both apples and oranges are great!", "I love Apples, Oranges, Pears, and Grapes."]
    
    related_words = GoogleSet.for(*twitter_search_terms)
    # returns ["apples", "oranges", "bananas", "peaches", "pears", "grapes", "strawberries", "plums", ...]
    related_words = (related_words - twitter_search_terms).each(&:downcase)
    
    good_tweets = []
    bad_tweets = []
    tweets.each do |tweet|
      tweet_words = tweet.downcase.split
      # Remove any non-word characters
      tweet_words = tweet_words.map { |word| word.gsub(/\W+/, '') }.compact
    
      if (tweet_words - related_words).size == tweet_words.size
        good_tweets << tweet
      else
        bad_tweets << tweet
      end
    end
    
    p good_tweets
    # returns ["Both apples and oranges are great!"]
    
    p bad_tweets
    # returns ["I love Apples, Oranges, Pears, and Grapes."]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me try to explain what I need. I have a server that is
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
I have a French site that I want to parse, but am running into
Let's say that I have an arbitrary string like `A man + a plan
Let's say I have a table that looks something like this: ------------------------------- id|column2|column3 |column4
Let's say i have an android device that has some extra buttons on it,
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>

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.