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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:57:27+00:00 2026-05-15T02:57:27+00:00

I have `a string example = this site holds all the examples from The

  • 0

I have `a string example = “this site holds all the examples from The Java Developers Almanac and more. Copy and paste these examples directly into your applications”

after token and do some i want on string example i have arraylist like :

ArrayList <token > arl = " "this site holds ", "holds all the examples ", "the examples from The Java Developers", " Copy and paste " )

“this site holds “, i know position start and end in string test : star = 1 end = 3
” holds all the examples “, i know position stat = 3 end = 6,
“the examples from The Java Developers”, i know position stat = 5 end =10,
“Copy and paste” i know position stat = 14 end = 17,

we can see,some element in arl overlaping :”this site holds “,”holds all the examples “,”the examples from The Java Developers”.

The problem here is how can i merge overlaping element to recived arraylist like

ArrayList result =”” this site holds all the examples from The Java Developers”,”” Copy and paste””;

Here my code : but it only merge fist elecment if check is element overloaping

public ArrayList<TextChunks> finalTextChunks(ArrayList<TextChunks> textchunkswithkeyword) {
        ArrayList<TextChunks > result = (ArrayList<TextChunks>) textchunkswithkeyword.clone();
            //System.out.print(result.size());
            int j;
            for(int i=0;i< result.size() ;i++) {
                int index = i;
                if(i+1>=result.size()){
                    break;
                }
                j=i+1;
                if(result.get(i).checkOverlapingTwoTextchunks(result.get(j))== true) {
                    TextChunks temp = new TextChunks();
                    temp = handleOverlaping(textchunkswithkeyword.get(i),textchunkswithkeyword.get(j),resultSearchEngine);
                    result.set(i, temp);
                    result.remove(j);
                    i = index;
                    continue;
            }
        }
        return result;  
    }
}

Thanks in avadce

  • 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-15T02:57:27+00:00Added an answer on May 15, 2026 at 2:57 am

    The following should do it or at least illustrates an idea for merging the chunks. Basically I’m destroying the existing chunks and recreate new ones. Sounds horrible but simplifies a lot. I just store the words in a List and iterate over that word list to build new (merged!) chunks.

    private List<TextChunks> finalTextChunks(List<TextChunks> textchunkswithkeyword) {
    
       private List<TextChunks> result = new ArrayList<TextChunk>();
       private List<String> wordList = new ArrayList<String>();
    
       // store all words in an arraylist, words are stored at their correct positions,
       // ignored words from the original text are represented by null entries
       for (TextChunks chunk : textchunkswithkeyword) {
         int start = chunk.getStartTextchunks();
         List<Token> tokens = chunk.getTokens(); // TODO - implement getTokens() in TextChunks class
         for (int i = 0; i < tokens.length; i++) {
            wordList.set(start+i, tokens.get(i).toString()); // TODO - overwrite toString() in Token class
         }
       }
    
       // recreate the chunks
       int start = 0;
       boolean isChunk = false;
       StringBuilder chunkBuilder;
    
       for (int i = 0; i < wordList.size(); i++) {
         String word = wordList.get(i);
         if (word == null) {
           if (isChunk) {
             // end of chunk detected
             TextChunk chunk = new TextChunk(chunkBuilder.toString().split(" "), start, i);
             result.add(chunk);
             isChunk = false;
           } else {
             // do nothing
           }
         } else {
           if (isChunk) {
             // chunk gets longer by one word
             chunkBuilder.append(" ").append(word);
           } else {
             // new chunk starts here
             chunkBuilder = new StringBuilder(word);
             start = i;
             isChunk = true;
           }
       }
       if (isChunk) {
         // create and add the last chunk
         TextChunks chunk = new TextChunk(chunkBuilder.toString(), start, wordList.size()-1);
         result.add(chunk);
       }
       return result;
    }
    

    (Warning – absolutely not tested, I have neither an IDE nor a compiler at hand)

    EDIT

    changed the code – you said, that the TextChunk class holds a token (words?) array. It was just three simple modifications.

    EDIT 2

    Final edit – I partially adapted my code to your classes. What you need to do:

    1. implement a getTokens() method in TextChunks that simply returns the arrt field
    2. implement a TextChunks constructor that takes a String (with space-separated words), the start and the end. Your Token class already provides a static method to convert the String in an arraylist of tokens
    3. overwrite toString() method in Token class so that simply returns the token String.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have a string variable that represents the name of a custom class. Example:
Suppose I have a string 'nvarchar(50)', which is for example the T-SQL string segment
Say for example I have the following string: var testString = Hello, world; And
For example, if I have a unicode string, I can encode it as an
For example, I have an ASP.NET form that is called by another aspx: string
For example, suppose I have a class: class Foo { public: std::string& Name() {
I have a string coming from a table like can no pay{1},as your payment{2}due
Ok, I have the HDF5 library downloaded from the official site, and I have
I have a string in the following format: \main\stream\foo.h\3 it may have more or

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.