Map<String, List<String>> words = new HashMap<String, List<String>>();
List<Map> listOfHash = new ArrayList<Map>();
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String word = getTagValue("word", eElement);
List<String> add_word = new ArrayList<String>();
String pos = getTagValue("POS", eElement);
if(words.get(pos)!=null){
add_word.addAll(words.get(pos));
add_word.add(word);
}
else{
add_word.add(word);
}
words.put(pos, add_word);
}
}
This is a segment of code I have written (it uses Stanford CoreNLP). The problem I am facing is that presently this code is working only with one Map i.e. “words”. Now, I want that as soon as the parser sees “000000000” which is my delimiter, then a new Map should be added to the List and then the keys and values to be inserted into it. If it does not see “000000000”, then the Keys and Values are to be added in the same Map.
Please help me with that as I am not able to do it even after a lot of efforts.
I guess listOfHash is to contain all your Maps…
So rename
wordstocurrentMapfor example and add to it. When you see “000000000” instantiate a new Map, assign it tocurrentMap, add it to the list and go on…something like:
And don’t forget to add your initial Map to listOfHash.
I also see you have other problems with your code, here is modified version (I have not tried to compile it):