我正在使用wearet3.0来获取每个单词的同义词和光泽....我附加了一段代码(一个搜索词方法),其中我有2个arraylist ..我需要返回2个arraylist操作...。我该怎么做?我试图使用map ...但是仍然我没有任何唯一的键可以这样做...任何人都给我一些主意,我该如何获取两个数组列表(nums和nums1)的内容
public ArrayList<String> searchWord(String key)
{
nums.clear();
/* A word is having a different WordId in different synsets. Each Word is having a
* unique Index.
*/
//Get the index associated with the word, 'book' with Parts of Speech NOUN.
IIndexWord idxWord = idict.getIndexWord(key, POS.NOUN);
if(idxWord==null)
{
return nums;
}
System.out.println("Word ->"+key);
System.out.println("-------------");
System.out.println("-------------");
int i=1;
/*getWordIDs() returns all the WordID associated with a index
*
*/
IWord word;
ISynset wordSynset = null;
//if(StringUtils.isNotEmpty(idxWord.getWordIDs()))
for(IWordID wordID : idxWord.getWordIDs())
{
//Construct an IWord object representing word associated with wordID
word = idict.getWord(wordID);
//System.out.println("SENSE->"+i);
//System.out.println("---------");
wordSynset = word.getSynset();
System.out.print("Synset "+i+" {");
//Returns all the words present in the synset wordSynset
for(IWord synonym : wordSynset.getWords())
{
System.out.print(synonym.getLemma()+", ");
nums1.add(synonym.getLemma());
}
System.out.print("}"+"\n");
nums.add(wordSynset.getGloss());
for(String s:nums)
// {
// System.out.print(s);
// }
//Returns the gloss associated with the synset.
System.out.println("GLOSS -> "+wordSynset.getGloss());
System.out.println();
i++;
}
return nums;
// WordNetDatabase database=WordNetDatabase.getFileInstance();
}
最佳答案
您可以使用一个对象来保存/包装两个ArrayList
:
public Something searchWord(final String key) {
// ...
return new Something(num1, num2);
}
与:
public class Something {
private ArrayList<String> num;
private ArrayList<String> num1;
public Something(final List<String> num, final List<String> num1) {
this.num = num;
this.num1 = num1;
}
// getters, setters, ...
}
要么
使用Apache commons-lang中的
Pair
:public Pair<List<String>, List<String>> searchWord(final String key) {
// ...
return new Pair<List<String>, List<String>>(num1, num2);
}