求助,裸身跪求了!!!找各个单词所在的行
一个作业:从一篇文章中取单词,并按字母顺序进行了排列(已经实现)
现在根据这组单词,分别列出他们所在的行 ,比如 like {1,6,26}
不是这一个单词,是这一组已经排序的单词都要找出来,这个如何去实现呢?
我这个方法已经可以实现找一个单词,但是无法按排序的单词组,按从小到大的顺序进行找。
我贴了方法,帮我看看吧,裸身跪求了!!!
public String[] lecteur (String file) {
List<String> liste1 = new Vector<String>();
List<String> liste2 = new Vector<String>();
String chbuf;
String table[]=new String[3000];
//for( motListe1=0;motListe1<liste1.size();motListe1++)
try {
File f1 = new File(file);
Scanner sc1 = new Scanner(f1,"ISO-8859-1");
while (sc1.hasNext()) {
chbuf = nettoyage(sc1.next()) ;
if (!chbuf.equals("")){
ajouter_elt(chbuf, liste1);
}
Collections.sort(liste1); //par ordre
}
for(int i=0;i<liste1.size();i++) //create la table
{table[i]=liste1.get(i); //retire le mot dans la liste
//System.out.println(i+": "+table[i]);
}
// *****************************************************************
File f2 = new File(file);
Scanner sc2 = new Scanner(f2,"ISO-8859-1");
while (sc2.hasNextLine()) {
numbreLine++;
chbuf = nettoyage(sc2.nextLine()) ;
if (!chbuf.equals("")){
ajouter_elt(chbuf, liste2);
}
String[] word = chbuf.split(" ");
Pattern p1=Pattern.compile("[a-zA-Zé\\à\\ê\\è]{4,20}");
for(int j=0;j<word.length;j++){
Matcher matcher1=p1.matcher(word[j]);
while(matcher1.find())
m.put((String)matcher1.group(),0);
}
Set<String> set = m.keySet();
for(int i=0;i<word.length;i++)
{
Matcher matcher1=p1.matcher(word[i]);
Iterator<String> it = set.iterator();
while(matcher1.find()){
String wordNew=matcher1.group();
while(it.hasNext()){
String k = nettoyage(it.next());
if(wordNew.equals(k)){
int c = m.get(k);
c++;
m.put(nettoyage(wordNew),c);
}
//******************************************************************************
if(liste1.get(l).equals(wordNew)){
int c = 0;
c++;
m2.put(numbreLine,c);
}
}
}
}
m.clear();
}
for(int line=0;line<liste1.size();line++)
System.out.println(liste1.get(line)+":"+m2);
} catch (FileNotFoundException ex) {
Logger.getLogger(Question3_Refaire_4.class.getName()).log(Level.SEVERE, null, ex);
}
Collections.sort(liste2);
return liste2.toArray(new String[0]);
}
下面还有自己写的方法,这只是部分,谢谢了!!!