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
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.
(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:
arrtfieldTokenclass already provides a static method to convert the String in an arraylist of tokensTokenclass so that simply returns the token String.