Ask Experts Questions for FREE Help !
Ask
    jimrummy's Avatar
    jimrummy Posts: 1, Reputation: 1
    New Member
     
    #1

    Dec 9, 2015, 03:33 PM
    Chat bot help
    Hello,

    I'm programming a chatbot in Java. So far I've got it to read the default responses from a txt file (in the form of an ArrayList) but I can't get it to read my main response file. It prints out saying Blank response for... What is it I need to change?
    public HashMap<String, String> readAMap(String responses)
    {
    HashMap<String, String> map = new HashMap<>();
    try (BufferedReader reader =
    new BufferedReader(new FileReader("responses.txt"))) {
    String word;
    word =reader.readLine();
    while(word != null) {
    String response = reader.readLine();
    if(response != null) {
    response = response.trim();
    if(response.length() != 0) {
    map.put(word, response);
    }
    else {
    System.out.println("Blank response for " +
    word + " in file " +
    responses);
    }
    }
    else {
    System.out.println("Missing response for " +
    word + " in file " +
    responses);
    }
    word = reader.readLine();
    }
    }
    catch(IOException e) {
    System.out.println("Problem reading file: " + responses +
    " in readAMap");
    }
    return map;
    }

    After this I need to create a trainer mode which can be selected instead of the user mode. The idea of training mode is that a trainer should be able to add new word : response pairs
    to the system.
    There are two parts to this functionality:
    • The trainer can add a word and the associated response.
    • The program shows the trainer previously saved user input that had no matching
    response and requests one or more word:response pairs that could be used to
    match that same input on future runs in user mode.

    I'm looking for help with the above and help with understanding the concepts of cohesion, coupling and refactoring as they apply to this assignment. I hope someone can help.

    Kind regards,

Check out some similar questions!

How do I make my own chat room bot for america online desktop 9.6? [ 0 Answers ]

What code languages do I need to learn to build one myself if a website says their perl coded? If it isn't too big after I'm done I guess I can just host it on my desktop PC.

What is Yahoo [Bot]? [ 1 Answers ]

What is Yahoo ?

Google thinks I'm a bot! [ 1 Answers ]

This is a new one on me, I just did a Google search for Allinurl: 198082 And got this error message:...

Spy-bot recovery [ 5 Answers ]

I downloaded spybot search and destroy to get rid of any spyware problems but now when I open my hotmail e-mail account and use eBay boxes are continually popping up say "spybot s&d has blocked the download of "doubleclick" or "avenue A inc". These boxes are a complete pain in the ass and I want to...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.