I have a string s1(contains a lot of english sentences),a list of string l1(which contains elements like bus, house, train, train engine, train engine's life(no. of words are never greater than 3), etc) and a list of string l2 (similar to l1) and an integer n.
For each element of l1, I have to find other elements of l1 or that of l2 within s(l1's elements can occur multiple times in s and we have to find it for every occurrence) such that their distance(distance is in no. of words,eg.: I have xyz.In this case, distance between I and xyz is 2) from that l1's element is less than or equal to n on either side of l1's element. Those words/phrases(elements of l1 or l2) are to be stored in a list in java.
e.g.:
Input:
s= i am asd fgh and studying in zxc vbn bnmkl. i am 100 years old.(may contain other symbols too)
l1= i
l2=asd, fgh, zxc, vbn
n=3.
Output:
asd,fgh,zxc,vbn
for(int j=0;j<l1.size();j++){
String s1=l1.get(j);
int index = s.indexOf(s1);
while(index >= 0) {
System.out.println(index);
for(int k=0;k<n;){
// how to detect the words before and after that element of l1 such that distance is <= n on either side in a passage and they are contained in either l1 or l2.
}
index = s.indexOf(s1, index+1);
}
}
Can anybody help me how to implement this?