我有一個HashMap,其中某些鍵像「崩潰」和「崩潰」,它們返回相同的響應。我想創建一個新的HashMap,它將同義詞映射到responseMap中的唯一鍵(例如,映射「崩潰」,「崩潰」和「崩潰」到synonym中的「崩潰」)。散列圖鍵將不會工作
private void fillSynonymMap()
{
synonymMap.put("crash", "crash");
synonymMap.put("crashes", "crash");
synonymMap.put("crashed", "crash");
}
我被困在什麼是如何輸入這些鍵,以便我可以在下面簡化代碼。
private void fillResponseMap()
{
responseMap.put("crash",
"Well, it never crashes on our system. It must have something\n" +
"to do with your system. Tell me more about your configuration.");
responseMap.put("crashes",
"Well, it never crashes on our system. It must have something\n" +
"to do with your system. Tell me more about your configuration.");\
responseMap.put("crashed",
"Well, it never crashes on our system. It must have something\n" +
"to do with your system. Tell me more about your configuration.");
}
public String generateResponse(HashSet<String> words)
{
for (String word : words) {
String response = responseMap.get(word);
if(response != null) {
return response;
}
}
// If we get here, none of the words from the input line was recognized.
// In this case we pick one of our default responses (what we say when
// we cannot think of anything else to say...)
return pickDefaultResponse();
}
告訴我更多關於您的配置的信息。 – vikingsteve 2013-02-26 07:47:53
我不明白這個問題。你能否更清楚地解釋一下。可能會有一些樣本輸入和輸出。這兩張地圖應該包含哪些地圖? – 2013-02-26 07:48:24
請詳細說明您所需的輸入和輸出。這裏沒有上下文。 – 2013-02-26 07:48:33