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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:09:09+00:00 2026-05-21T22:09:09+00:00

i have text files as shown below ex: file 1: yamaha gladiator bike file

  • 0

i have text files as shown below

ex:

file 1:

       yamaha
       gladiator 
       bike  

file 2:

       bajaj 
       pulsar
       bike

file 3:

       yamaha 
       gladiator
       india

i have to read these file indivisually and create clusters. means to say, from above ex, file 1 and file 3 are similar and will create one cluster. i want atleast a single word to be matched between two files to make a cluster. so finally i have to get two clusters from above ex as
1: yamaha and 2: bajaj. pls help me with 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-21T22:09:10+00:00Added an answer on May 21, 2026 at 10:09 pm

    Sounds like you simply need to read each file into a Set<String> of words and then looking for intersections to build your clusters. That could be achieved, for example, by building a map of words to a count of occurrences (Map<String, Integer>) or a map of words to a set of filenames (Map<String, Set<String>>).

    Not sure where you second example cluster comes from as “bajaj” only exists in file 2.

    EDIT: based on request to explain how Maps and Sets work

    Instantiating a Map that maps strings (the word) to a set of filenames:

    Map<String, Set<String>> wordsToFilenames = new HashMap<String, Set<String>>();
    

    Adding a word found in a filename to this (assume we’ve read in a word from the file into the word variable and have the filename in a filename variable, both Strings):

    Set<String> filenamesForWord;
    
    if (wordsToFilenames.containsKey(word)) {
        filenamesForWord = wordsToFilenames.get(word);
    }
    else {
        filenamesForWord = new HashSet<String>();
        wordsToFilenames.put(word, filenamesForWord);
    }
    
    filenamesForWord.add(filename);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file (called print_1012720.txt ) that looks like the text shown below.
I have a text file as shown below. I need only PDB IDs after
hey i have text file shown as below. 11/2/2010     cat    6 11/2/2010   
I have a pipe delimited text file as shown below, which I need to
I have a file name foo. That file contains some text (shown below). Can
I'm trying to read a simple text file shown below with the Scanner class
I have a text file which contains protein sequences(200 sequences) as shown below. >ptn1
This is the data in my text file: (I have shown 10 rows out
I have two text files. hash_only.txt and final_output.txt hash_only.txt looks like below. 193548 401125
I have a screen as shown in the below image. Once a file is

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.