I have a problem with a hashmap. In my hashmap method, I want to have two or more keywords as a key, to oppose having one. For example, I want the user to enter a sentence containing two or more keywords, assuming that the “professor’s name” is a keyword. for instance
String[] temp3 = { "instructor","teacher","mentor" }; responses.put("professor name", temp3);
And the user enters "what is the professor’s name", the code just hangs. But, on the other hand, if
String[] temp3 = { "instructor","teacher","mentor" }; responses.put("professor", temp3);
the code works. Therefore, I want to be able to enter some kind of sentence containing two or more keywords that are opposite to one. I will be grateful for any help.
Here is my hashmap method
private static HashMap<String, String[]> populateSynonymMap() { String[] temp1 = { "instructor","teacher","mentor" }; responses.put("professor name", temp1); String[] temp2 = { "amount of test","test load","quantity of test" }; return responses; }
and here is my main method
public static void main(String args[]) throws ParseException, IOException { /* Initialization */ HashMap<String, String[]> synonymMap = new HashMap<String, String[]>(); synonymMap = populateSynonymMap(); // populate the map Scanner scanner = new Scanner(System.in); String input = null; /*End Initialization*/ System.out.println("Welcome To DataBase "); System.out.println("What would you like to know?"); System.out.print("> "); input = scanner.nextLine().toLowerCase(); String[] inputs = input.split(" "); for (String ing : inputs) { // iterate over each word of the sentence. boolean found = false; for (Map.Entry<String, String[]> entry : synonymMap.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); if (key.equals(ing) || Arrays.asList(value).contains(ing)) { found = true; parseFile(entry.getKey());`` } break; } if (found) { break; } } }
Assuming the ParseFile method works