ios.avapose.com

.NET/Java PDF, Tiff, Barcode SDK Library

The good thing about developing a bot is that it can be as simple or as complex as you like. Toward the end of this chapter we ll be looking at ways you can extend the bot, but the initial construction is quite simple. You ll be using most of the techniques covered so far in this book to build your bot. You ll be doing a bit of testing and documentation, as well as using classes and complex data structures. You ll also be using files to store information the bot uses, and looking at how to make your bot available to the general public using HTTP servers and CGI scripts. This project also demands you use a lot of string and list-related functions, along with comparison logic. These are all things you re likely to use in a larger development project, and as Ruby is a particularly good language for text processing, this project is perfect for demonstrating Ruby s strengths. A bot also allows you to have some fun and experiment. Working on a contact information management tool (for example) isn t that much fun, even though such a system would use similar techniques to your bot. You can still implement testing, documentation, classes, and storage systems, but end up with a fun result that can be extended and improved indefinitely.

winforms pdf 417 reader, winforms qr code reader, winforms upc-a reader, winforms data matrix reader, winforms gs1 128, winforms ean 13 reader, c# remove text from pdf, replace text in pdf c#, winforms code 39 reader, c# remove text from pdf,

After performing this, x can either contain the string 'Hello, world!', or the list [1, 2, 'e', 'e', 4] you don t know, and you don t have to worry about it. All you care about is how many times you find e in x, and you can find that out regardless of whether x is a list or a string. By calling the count method as before, you find out just that: >>> x.count('e') 2 In this case, it seems that the list won out. But the point is that you didn t have to check: Your only requirement was that x had a method called count that took a single character as an argument and returned an integer. If someone else had made their own class of objects that had this method, it wouldn t matter to you you could use their objects just as well as the strings and lists.

The primary focus of this chapter is to keep each fragment of functionality in your bot loosely coupled from the others. This is an important decision when developing certain types of applications if you plan to extend them in future. The plan for this bot is to make it as easy to extend, or change, as possible, allowing you to customize it, add features, and make it your own. In terms of the general operation of the chatterbot, your bot will exist within a class, allowing you to replicate bots easily by creating new instances. When you create a bot, it will be blank, except for the logic contained within the class, and you ll pass in a special data file to give it a set of knowledge and a set of responses it can use when conversing with users. User input will be via the keyboard, but the input mechanism will be kept flexible enough so that the bot could easily be used from a Web site or elsewhere. Your bot will only have a few public methods to begin with. It needs to be able to load its data file into memory and accept input given by the user, then return its responses. Behind the scenes, the bot will need to parse what the users say and be able to build up a coherent reply. Therefore, the first step is to begin processing language and recognizing words.

10

Several stages are required to accept input such as I am bored and turn it into a response such as Why are you bored The first is to perform some preprocessing tasks that make the text easier to parse such as cleaning up the text, expanding terms such as I m into I am and you re into you are, and so forth. Next, you ll split up the input into sentences and words, choose the best sentence to respond to, and finally look up responses from your data files that match the input. You can see these basic steps in the flowchart in Figure 12-2.

Note A flowchart is a graphical representation of the steps involved in a system, such as within a computer program. Producing flowcharts such as the one in Figure 12-2 can help to define the steps within a process, making it easier to tie up your expectations for a program with the resulting code. You can learn more about flowcharts, the symbols they use, and how they work at http://en.wikipedia.org/ wiki/Flowchart.

   Copyright 2020.