memory - Facing Problems while displaying entire hashmap - java out of heap space -
public static void main(string args[]) throws filenotfoundexception, ioexception { filereader in = new filereader("/home/aoblah/downloads/file1.txt"); bufferedreader br = new bufferedreader(in); // scanner in = null; string answer = null; string verb = null; string line = null; string [] split_npn = null; string [] split_pn = null; string [] split_dp2 = null; string [] split_dp3 = null; hashmap<string, hashmap<string, arraylist<string>>> hmap = new hashmap<string, hashmap<string, arraylist<string>>>(); try { while ((line = br.readline()) != null) { if(line.contains("verb")) { verb = line.substring(0, line.indexof("(")); if(line.contains("npn")){ string test = line.substring(line.indexof("npn")); answer = test.substring(test.indexof("npn"),test.indexof(']')); answer = answer.replace(",", " " ); split_npn = answer.split(" "); } if(line.contains("pn")){ string test = line.substring(line.indexof("pn")); answer = test.substring(test.indexof("pn"), test.indexof(']')); answer = answer.replace(",", " " ); split_pn = answer.split(" "); } if(line.contains("dp2")){ string test = line.substring(line.indexof("dp2")); answer = test.substring(test.indexof("dp2"), test.indexof(']')); answer = answer.replace(",", " " ); split_dp2 = answer.split(" "); } if(line.contains("dp3")){ string test = line.substring(line.indexof("dp3")); answer = test.substring(test.indexof("dp3"), test.indexof(']')); answer = answer.replace(",", " " ); split_dp3 = answer.split(" "); } } if(split_npn != null){ arraylist<string> npn = new arraylist<string>(); hmap.put(verb, new hashmap<string, arraylist<string>>()); for(int = 1; i< split_npn.length; i++){ npn.add(split_npn[i]); } npn.trimtosize(); hmap.get(verb).put("npn", npn); } if(split_pn != null){ arraylist<string> pn = new arraylist<string>(); hmap.put(verb, new hashmap<string, arraylist<string>>()); for(int = 1; i< split_pn.length; i++){ pn.add(split_pn[i]); } pn.trimtosize(); hmap.get(verb).put("pn", pn); } if(split_dp2 != null){ arraylist<string> dp2 = new arraylist<string>(); hmap.put(verb, new hashmap<string, arraylist<string>>()); for(int = 1; i< split_dp2.length; i++){ dp2.add(split_dp2[i]); } dp2.trimtosize(); hmap.get(verb).put("dp2", dp2); } if(split_dp3 != null){ arraylist<string> dp3 = new arraylist<string>(); hmap.put(verb, new hashmap<string, arraylist<string>>()); for(int = 1; i< split_dp3.length; i++){ dp3.add(split_dp3[i]); } dp3.trimtosize(); hmap.get(verb).put("dp3", dp3); } system.out.println(hmap); } } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } }
the file contains entries such
calm(verb,naux,[nullobj,[dp2,down],[dp3,down]],calm).
calms(verb,[sg],calm).
calmed(verb,[sg,pl,en],calm).
calm(verb,[pl,inf],calm).
calming(verb,[ing],calm).
calmly(adv,mv,calmly).
calmness(noun,[sg],calmness).
i storing verbs, categories of prepositions associated , prepositions in nested hash map. have no trouble when printing particular category of prepositions associated verb, when display whole hashmap programs runs , never stops...ending in java out of space heap error. how can fix memory problem?
one suggestion instead of doing system.out.println(hmap);
try print out sequentually:
for(string outerkey: hmap.keyset()) { system.out.println(outerkey + ": "); map inner = hmap.get(outerkey); for(string innerkey : innermap) { system.out.print(innerkey + ": "); system.out.println(inntermap.get(innerkey).tostring()); } }
Comments
Post a Comment