Blondeamon Δημοσ. 26 Οκτωβρίου 2009 Δημοσ. 26 Οκτωβρίου 2009 > public String expandTemplateTopic(String remark) { String random_word = findKeyWord(remark); String str=" "; String kok2=" "; int num1=0; int num2=0; int num3=0; //find a random template int number = generator.nextInt(sentenceList.size()); String argument=sentenceList.get(number).getTemplate(); //split it into words using space as delimiter List ls=new LinkedList(); String[] array =argument.split (" "); //find if there are %NOUN% words and if yes replace them with a synonym of the random_word for (int i=0; i < array.length; i++) { if (array[i].equals("%NOUN%")) { System.out.println("Array["+i+"] is: "+array[i]); [b] ls.addAll(word.getSynonyms(POS.NOUN,random_word) );[/b] if (ls.size()>0) { str=(String)ls.get(num1); array[i]=str; num1++; for(int j=0;j<ls.size();j++) System.out.println("ls "+j+" is:"+ls.get(j) ); } else array[i]=word.getNounAtRandom(); } ////find if there are %VERB% words and if yes replace them with a synonym of the random_word else if (array[i].equals("%VERB%") ) { System.out.println("Array["+i+"] is: "+array[i]); [b]ls.addAll(word.getSynonyms(POS.VERB,random_word) );[/b] if (ls.size()>0) { str=(String)ls.get(num2); array[i]=str; num2++; } else array[i]=word.getVerbAtRandom(); } //find if there are %ADJECTIVE% words and if yes replace them with a synonym of the random_word else if (array[i].equals("%ADJECTIVE%")) { System.out.println("Array["+i+"] is: "+array[i]); [b] ls.addAll(word.getSynonyms(POS.ADJECTIVE,random_word) );[/b] if (ls.size()>0) { str=(String)ls.get(num3); array[i]=str; num3++; } else array[i]=word.getAdjectiveAtRandom(); }//if System.out.println("Array["+i+"] is: "+array[i]); //clearing the List before the next loop ls.clear(); }//for //re-assemble the sentence with the replaced words for (int k=1; k < array.length+1; k++) { kok2=kok2.concat(" "+array[k-1]); } //and return it return kok2; } H συνάρτηση κάνει compile κανονικά αλλά μου λέει οτι έχω unsafe or unchecked operations και το έψαξα και το εντόπισα οτι φταίνε οι μαύρες γραμμές κώδικα με την εντολή addAll(). Να διευκρινίσω οτι η εντολή getSynonyms(a, επιστρέφει ένα arraylist το οποίο όλο αυτό ταίζεται ώς ορισμα στην addAll(). Τι φταίει?
virxen75 Δημοσ. 26 Οκτωβρίου 2009 Δημοσ. 26 Οκτωβρίου 2009 με βάση τα παρακάτω κάνε τις απαιτούμενες αλλαγές στον κώδικα σου > List<String> ls=new LinkedList<String>(); ArrayList<String> aa=new ArrayList<String>(); ls.addAll(aa);
Blondeamon Δημοσ. 26 Οκτωβρίου 2009 Μέλος Δημοσ. 26 Οκτωβρίου 2009 ευχαριστώ για την απάντηση αλλά το έλυσα με τον εξής τρόπο Instead of ls.addAll(word.getSynonyms(POS.NOUN,random_word) ); i used ls = (word.getSynonyms(POS.NOUN,random_word) );
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.