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 i = 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 i = 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 i = 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 i = 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 as
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 am storing all the verbs, categories of the prepositions associated with it and the prepositions in a nested hash map. I have no trouble when printing only a particular category of prepositions associated with the verb, but when I display the whole hashmap the programs just runs and never stops...ending up in java out of space heap error. How can i fix this memory problem?