synonyms, and take all command

This commit is contained in:
jslightham
2019-05-29 10:56:22 -04:00
parent 2d40e5954a
commit bad3490b1e
6 changed files with 90 additions and 6 deletions

View File

@@ -16,7 +16,8 @@ import java.util.Scanner;
*/
class CommandWords {
// a constant array that holds all valid command words
private static HashMap<String, String> m_words = new HashMap<String, String>();;
private static HashMap<String, String> m_words = new HashMap<String, String>();
private static HashMap<String, String> m_synonyms = new HashMap<String, String>();
/**
* Constructor - initialise the command words.
*/
@@ -33,6 +34,18 @@ class CommandWords {
}catch (Exception e) {
e.printStackTrace();
}
try {
Scanner in = new Scanner(new File("data/synonyms.dat"));
while(in.hasNext()){
String text = in.nextLine();
String[] textarr = text.split(",");
m_synonyms.put(textarr[0], textarr[1].substring(1));
}
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}
/**
@@ -82,4 +95,16 @@ class CommandWords {
}
System.out.println();
}
public static String replaceSynonym(String word) {
try {
String words = m_synonyms.get(word);
if(words == null)
throw new Exception();
else
return words;
} catch(Exception e) {
return word;
}
}
}