java - Issues with Hashmaps -


i having issue trying iterate through sentence user inputs matching word in hashmap. example if user enters "i reading professor". professor keyword. want scan sentence user inputs keyword professor or it's synonyms in hashmap. far when run program code hangs.

here main method:

public static void main(string args[]) throws parseexception, ioexception { /* initialization */     hashmap<string, string[]> synonymmap = new hashmap<string, string[]>();     synonymmap= populatesynonymmap(); //populate map     system.out.println("welcome database ");     system.out.println("what know?");      system.out.print("> ");     input = scanner.nextline().tolowercase();     string[] inputs = input.split(" "); //here split sentence words.      (string in : inputs) { //iterate on each word of sentence.         if (synonymmap.containsvalue(in)) { //check if values of synonymmap has string in.             (map.entry<string, string[]> entry : synonymmap.entryset()) {                 string[] value = entry.getvalue();                 if (arrays.aslist(value).contains(in)) {                     parsefile(entry.getkey());                     system.out.println("have day!");                     break;                 }             }             break;         }     } } 

and hashmap method:

private static hashmap<string, string[]> populatesynonymmap() {     responses.put("professor", new string[]{"instructor", "teacher", "mentor"});     responses.put("book", new string[]{"script", "text", "portfolio"});     responses.put("office", new string[]{"room", "post", "place"});     responses.put("day", new string[]{"time",  "date"});     responses.put("asssignment", new string[]{"homework", "current assignment "});     responses.put("major", new string[]{"discipline", "focus"," study"});       return responses; } 

parsefile checks textfile word , returns sentence

public static void parsefile( string s) throws filenotfoundexception { file file = new file("data.txt");

    scanner scanner = new scanner(file);     while (scanner.hasnextline()) {         final string linefromfile = scanner.nextline();         if (linefromfile.contains(s)) {             // match!             system.out.println(linefromfile);             // break;         }      } } 

note types of input , synonymmap in code:

hashmap<string, string[]> synonymmap = new hashmap<string, string[]>(); // ... more code ... (string in : inputs) { //iterate on each word of sentence. 

so, return false:

if (synonymmap.containsvalue(in)) { //check if values of synonymmap has string in. 

now, need to:

scan sentence user inputs for keyword professor or it's synonyms in hashmap.

that tricky 'or' means need check both in key , values match, since key values not in list values redundant. inside for (string in : inputs) should have:

boolean found = false; (map.entry<string, string[]> entry : synonymmap.entryset()) {     string key = entry.getkey();     string[] value = entry.getvalue();     if (key.equals(in) || arrays.aslist(value).contains(in)) {         found = true;         parsefile(key);         system.out.println("have day!");         break;     } } if (found) {     break; } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -