Traore Project

Embed Size (px)

Citation preview

  • 8/8/2019 Traore Project

    1/17

    AFRICAN UNIVERSITY OF SCIENCE AND TECHNOLOGY, ABUJA-NIGERIA

    PROGRAMMING FUNDAMENTALS

    Course Instructor: Prof. Mamadou Traore

    Title: DESIGN OF AN INTELLIGENT TALKING SYSTEM (KARL).

    Group Members:

    Arreytambe Tabot 40163

    Patrick Mensah 40160

    18/10/2010

    A Project designed to provide hands-on experience in the management of dataflow in Java.

  • 8/8/2019 Traore Project

    2/17

    2 | P a g e

    I. INTRODUCTIONBACKGROUND AND PROBLEM STATEMENT

    This project is geared towards the design of an intelligent talking system called KARL whichis able to chat with a human user.

    Karl has a register used as the active part of his brain and memory used as the passive part.

    This memory is a text file containing sentences and their associated keywords. Each time one

    of these keywords appears in the text written by the user during the chat, Karl answers with

    the associated sentence. For example; If the keyword aust is associated to the sentence

    The best University inthe world! Im telling you! And if the user enters something like I

    love aust, then Karl responds with the answer, The best University in the world! Im telling

    you!

    Karl uses a hash table (the register-a class that allows dealing with pairs of values) into which

    the content of his memory (the file) is loaded. The chat is initiated by the chat() method. The

    Karl welcomes the user and starts reading his reply. Text is analysed by tokenizing and the

    keyword matched with that in the register and the appropriate answer is given.

    OBJECTIVE

    Our objective of this design is to do the following;

    1) Implement Karl to run in 2 different modes; $ALOON (NORMAL) MODE- For normal conversation. ADMIN MODE- For administrative mode in which the following tasks can be

    performed;

    # LEARN Here a pair (, ) is

    added to the knowledge base (the register) if no sentence is associated to this

    keyword. Otherwise a prompt is issued demanding if the existing association

    should be replaced or not.

    # DELETE Deleting the keyword automatically deletes the

    sentence associated with it in the knowledge base.

    # MODIFY Change former association concerning

    to be a new association with sentence.

  • 8/8/2019 Traore Project

    3/17

    3 | P a g e

    2) Designing the entire Karl system to include the generation of prompts asking user ifhe/she wants to really perform an operation or not. System will also send error

    messages and warnings for wrong messaging and for trying to perform unauthorized

    tasks respectively. e.g. deleting a word that doesnt exist (error message) and normal

    user trying to access admin mode privileges without proper authentication (warning ).

    3) Performing a GUI implementation of the entire KARL system so as to give it the lookand feel of a real intelligent system.

    DIAGRAM

    Fig1-Principlebehind the KARL system illustrated.

    II. LITERATURE REVIEW1. Java management of data flow

    A data flow represents incoming of data to a process or outgoing of data (or info) from a

    process. A data flow is also used to represent the creation, reading, deletion or updating of

    data in a database or file. A process is an activity or a function that is performed for a specific

    reason. Every process starts with a verb followed by a noun.

    Data flows are the glue that holds the processes together. One end of the data flow will

    always come from or go to a process, with an arrow showing the direction into or out of that

    process. A data store is a collection of data that is stored in a file or database.

  • 8/8/2019 Traore Project

    4/17

    4 | P a g e

    A data flow coming out of a data store indicates that information is retrieved from the data

    store and data flow going into a data store indicates that information is added to the data store

    or that information in the data store is changed. The data flow diagram is illustrated in fig1.

    above.

    2. Distinction between Stream and UnicodeStream represents bytes of data while Unicode represents characters. A bit is the smallest data

    item in a computer and can assume the value 0 or 1. It is however cumbersome for

    programmers to work with data in the low-level form of bits. Instead they prefer to work with

    data in such forms as decimal digits (0-9), letters (A-Z and a-z), and special symbols (e.g., $,

    @, %, &, *, etc). Digits, letters and special symbols are known as characters. Characters in

    java are Unicode characters composed of two bytes, each composed of eight bits. Unicode is

    the widely used industry standard for representing characters independent of the underlying

    program and language. File streams can be used to input and output data as either characters

    or bytes. Streams that input and output bytes to files are known as byte-based streams, storing

    data in its binary format. Streams that input and output characters to files are known as

    character-based streams, storing data as a sequence of characters.

    3. Standard stream manager and pre-defined management classesThe standard streams in java are referred to by System.in (for stdin), System.out (for stdout),

    and System.err (for stderr).

    Static PrintStream (err) - The standard error output stream. This stream is alreadyopen and ready to accept output data. This output stream is used to display error

    messages or other information.

    Static InputStream (in) - The standard input stream. This stream is already openand ready to supply input data. Typically this stream corresponds to keyboard input or

    another input source specified by the host environment or user.

    Static PrintStream (out) - The standard output stream. This stream is already openand ready to accept output data. Typically this stream corresponds to display output or

    another output destination specified by the host environment or user.

    Some major pre-defined management classes of stream Class (which has as parents

    InputStream and OutputStream) are described here below;

  • 8/8/2019 Traore Project

    5/17

    5 | P a g e

    -BufferedInputStream and BufferedOutputStream- Used for buffering input and output. It

    inherites the read() and write() methods of its Parent Class and implements other methods for

    input and output.

    -DataInputStream and DataOutputStream- Used for as a filter for writing and reading

    primitive data types and Strings. It has as some of its read and write methods; readInt(),

    readDouble(), writeInt() and writeDouble() including many others for the other primitive data

    types.

    -ObjectInputStream and ObjectOutputStream- Used for serialization and deserialization of

    java objects which has readObject() and writeObject() as its read and write methods.

    4. Standard Unicode manager and pre-defined Unicode management classesThe Reader and Writer classes are the Unicode managers. A Reader is used for performing

    character I/O and has as its read() method for obtaining input data. They perform thesame

    function for characters that the stream managers perform for byte data. From the standard

    Reader and Writer classes we as well have pre-defined Unicode management classes. We

    give a brief description of these classes along with their associated methods for input and

    output.

    -BufferedReader and BufferedWriter- For buffering the characters in the character stream.

    -InputStreamReader and OutputStreamWriter- For converting between byte streams and

    character streams.

    -PrintWriter-For printing text to either an output stream or a Writer (System.out is a

    PrintWriter object). The println() method is an output method of the PrintWriter class.

    5. Tokenizing classThe string tokenizer class allows an application to break a string into tokens. The

    tokenization method is much simpler than the one used by the StreamTokenizer class. The

    StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings,

    nor do they recognize and skip comments. The set of delimiters (the characters that separate

    tokens) may be specified either at creation time or on a per-token basis. Tokenizing a text is

    an ability java offers to programmers. When we tokenize like above we obtain the sequence

    of all the words contained in a sentence. Here is a description of some of the methods of this

    class that were used in our case study;

    The StringTokenizer constructor takes a string argument and creates aStringTokenizer for that string and will use the white spaces to separate the string.

  • 8/8/2019 Traore Project

    6/17

    6 | P a g e

    The method hasMoreTokens is used to determine whether there are more tokens inthe string being tokenized.

    The method toUpperCase converts the next token to uppercase letters.

    The next token is obtained with a call to StringTokenizer method nextToken thatreturns a String.

    6. HashMap classIn computer science, a hash table or hash map is a data structure that uses a hash function to

    map identifying values, known as keys (e.g., a person's name), to their associated values (e.g.,

    their telephone number). The hash function is used to transform the key into the index (the

    hash) of an array element (the slotor bucket) where the corresponding value is to be sought.

    Maps associate keys to values and cannot contain duplicate keys (i.e., each key can map to

    only one value; this is called one-to-one mapping). HashMaps are a generic class that take

    two types of arguments; the first specifies the type of key and the second (in this case study it

    is a String) and the second specifies the type of values (also String in this case study). Some

    of its methods as seen are case study are described here below;

    reg = new HashMap(); which is used to create a HashMap called regwhich is our register file.

    Iterator it = reg.keySet().iterator(); the HashMap method keyset() is usedhere to get a set of the keys.

    The containsKey method is used to determine whether the word is in the map (andthus has occurred previously in the string).

    If map does not contain a mapping for the word, the Map method put is used to createa new entry in the map, with the word as the key and a sentence associated to it as the

    value.

    If word does not exist in the Map the get method is used to obtain the keys associatedvalue in the map.

  • 8/8/2019 Traore Project

    7/17

    7 | P a g e

    III. DESIGN DIAGRAMS1) CLASS DIAGRAMS

    Fig 2. The Class diagram representation of the Karl System.

  • 8/8/2019 Traore Project

    8/17

    8 | P a g e

    2) USE CASE DIAGRAMS

    3)

    4)

    Save

    Update

    authenticate

    delete

    insert

    Change

    password

    chat

    Administrator

    User

    System

    Fig 3. Use Case diagram for Karl

  • 8/8/2019 Traore Project

    9/17

    9 | P a g e

    3) SEQUENCE DIAGRAM

    4):User :System :Register FileAsk path to Register File

    Supply path

    Ask user to select from Menu

    Choose (chat mode)

    Display chat window blink for sentence

    Enter a sentenceSearch [find a match=True]

    Respond with found sentenceRespond with found sentence

    Blink for sentence

    ALTERNATIVE [Enter sentence()=True]

    [else]

    Enter 0 (to exit)

    Fig 4. Sequence diagram for the Chat Use Case

  • 8/8/2019 Traore Project

    10/17

    10 | P a g e

    :User

    :System :Register File

    Ask path to Register File

    Supply path

    Ask user to select from Menu

    Choose (Admin Mode)

    Ask user to select from Admin Menu

    Ask for User Name and Password

    include

    Match not found

    Enter (user name and password)

    Search [find a match=False]

    ALTERNATIVE[Enter sentence()=True]

    [else]

    Enter 0 (to exit)

    authenticate:

    Choose (Insertion/Learning Mode)

    Ask for Keyword

    Enter (Keyword)

    Ask for new sentence

    Enter new sentence Save()

    Sentence saved

    Ask user to select from Admin Menu

    Fig 5. Sequence diagram for Update Use Case

  • 8/8/2019 Traore Project

    11/17

    11 | P a g e

    IV. DEMOA DESCRIPTION OF HOW THE PROGRAM WORKS

    1. SYSTEM REQUIREMENTS

    a. A text file (.txt extension called a Register) which contains the information theprogram uses to chat with users. This file can be located anywhere on the computer.

    b. A Microsoft Excel sheet (saved under extension .xls) is used to store the User Nameand Passwords. Excel is used because the user can lock it with a password to avoid

    unauthorized access. This filemust be located on the C: drive of the computer.

    2. DESCRIPTION OF THE SYSTEM

    When the program is launched,

    It asks the user to enter the path to the Register file; a wrong path or empty field willgenerate an error message.

    If the correct path is given, it displays a menu from which the user can log in as anAdministrator, or go straight to chat mode.

  • 8/8/2019 Traore Project

    12/17

    12 | P a g e

    When the user selects option 1, he/she is taken directly to the chat window. Usersentences appear highlighted on top of the chat window, while system responses

    appear below. Typing bye will exit the window.

  • 8/8/2019 Traore Project

    13/17

    13 | P a g e

    If the user chooses the option 2 from the main menu, the system displays the menu forAdministrative mode. In the Administrative mode, users with administrative rights

    can Insert New words (only if their Keyword does not already exist), Delete a

    association, Modify an existing , and

    Change his/her password. When the user chooses non of these menu items and then

    tries to continue, the system responses with an error message notifying the user to

    choose an item.

    Each of the options (1 to 4) requires the user to supply a User Name and a validPassword before access is granted.

    Inserting a new Sentence: The user is asked for his User name and Password.After three failed attempts, the system tells him to see the Administrator, and

    then logs him off. If the user supplies the correct login information, he is

    granted access to the Register, to which he can add a new provided that the Keyword does not already exist. The

    program searches its memory to see if the new Keyword already exist, if not, it

    asks the user to supply the associated sentence, and then saves it to memory.

  • 8/8/2019 Traore Project

    14/17

    14 | P a g e

    Deleting a Association: The user is authenticatedusing the same steps as for Inserting a new Sentence. The user is asked to

    enter the Keyword of the sentence to delete. If the Keyword exist, the user is

    asked to confirm either it should be deleted or not. The program then

    continues according to the users choice of Y/N.

  • 8/8/2019 Traore Project

    15/17

    15 | P a g e

    Otherwise if user enters Y, then the sentence is deleted.

    Modifying a Sentence: The process of modifying a sentence is similar to thatof the Delete, except that after the program finds the keyword to modify, it

    asks the user whether he really want to continue. A Y(es) response from the

    user allows the program to delete the Keyword and Sentence. It then waits for

    a replacement. This replacement must be supplied.

    Changing of a Password: The usual authentication process is carried out. Theuser is asked to enter his old password. The program searches for thispassword, and then asks the user if he actually wants to replace the old

  • 8/8/2019 Traore Project

    16/17

    16 | P a g e

    password with a new one. If the user responses with a Y, the system deletes

    the old password and asks for the new User name and Password (this program

    uses a default user name and password calledadmin).

    However, if the user enters the correct old password, the programs prompts for

    the new password before proceeding to save it to memory.

    We can now log into the administrator mode by using the new username and password.

    This program has not laid much emphasis on the User Name as compared to the Password.

    This implies that, during authentication, the program will accept any name, but will use the

    password to verify the authenticity of the user. This was done this way to conform with most

    chat programs that allow users to enter with different names at different times.

  • 8/8/2019 Traore Project

    17/17

    17 | P a g e

    CONCLUDING REMARKS

    We drew the sequence diagrams for the chat and update Use Cases. For the UpdateUse Case we drew that for the learning option. This was done as a result of the fact

    that each of the options considered separately would still have thesame process that

    would be followed. So it would suffice to draw just one option rather than repeating

    thesame thing for the other options.

    Assumption: It should also be worthy of note that the best case scenario was

    considered in drawing our sequence diagrams. That is the case where everything

    works out smoothly without any glitches.

    In conformity with the requirement document to make the system reflect a trueintelligent system, we carried out a GUI implementation of our system to give it a

    better look and feel. And the codes were written in java from scratch without the use

    of drag and drop utilities provided by the various IDEs which would make it pretty

    much easier.