Web Analytics Made Easy -
StatCounter JavaScript ChatBot - CodingForum


No announcement yet.

JavaScript ChatBot

  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaScript ChatBot

    Hello, you geniuses.

    For a while now I have been working on a Web ChatBot, where you type something into a text-box in the header frame page, such as "hello" or "what is the time", and the computer shall recognize particular words or sentences from what you said and take you to the appropriate page in it's bottom frame, e.g. 'greetings.html' or 'time.html'; depending on what WebPage it was programmed to respond with.

    Unfortunately, as good as it is; I require for my Web ChatBot to be more specific, rather than just referring to keywords and loading it's set WebPage in the 'footer' frame below. Right now, my ChatBot runs from nothing more than recognizing keywords.
    For example: if I were to programme it to recognize the "WHAT IS" keyword string, I could programme the ChatBot to take me to the 'what_is.html' WebPage where it's response shall be stored.
    So if I ask a question such as "WHAT IS the capital of England?" or "I don't know, WHAT IS your name?" it would recognize the words 'WHAT IS' and take me to that specific 'what_is.html' page, or whatever WebPage I've set it to.
    All seems fine doesn't it? Incorrect.

    Because of my ChatBot recognizing nothing more than keywords, it always responds with inaccurate responses and answers to questions you ask it with WebPage responses that don't match up to what you asked; this is because it takes certain words out of your query and then takes you to it's set page for that word or series of words.
    For example, if I programmed in the word "TIME" and made it take me to a WebPage that had the time on it, e.g. 'time.html', I could say something to it like "What's the TIME" or "Don't tell me the TIME." and it would recognize the word 'TIME' and take me to the 'time.html' WebPage, and display the current system time.

    I require my ChatBot to be more specific with picking out words and sentences, like the popular ChatBot programming language AIML (Artifical Intelligence Manual Language) does. Where, for example, instead of having to programme the queries and responses to only like so:

    I don't know what it is.


    and there being nothing more to it.
    I want instead to be able to programme my ChatBot to have more specific tags, like this:

    The what? You didn't state anything.

    What is the, what?

    I don't know what it is.

    * WHAT IS THE *
    It could be anything.

    The asterisk above represents anything you say or type.
    Where the asterisk resembles whatever the computer user may decide to say to the ChatBot, for example:

    If you were to say to the ChatBot:
    'WHAT IS THE capital of England?', the ChatBot should recognize it as 'WHAT IS THE *' and the asterisk at the end representing what you said after it, because it represents anything; and would respond with it's response "I don't know what it is" on its set WebPage; because the asterisk represents any input and whatever the user types in after that 'WHAT IS THE' line.
    Another example is like if I enter: 'blar blar WHAT IS THE', then the ChatBot should recognize the '* WHAT IS THE' script and respond with "_what_is_the" as stated above in the example, because the asterisk represents what the user typed before the CODE.
    Basically, the asterisk resembles whatever text the user types into the ChatBot.

    Having this feature on my ChatBot instead of using keywords would massively improve it's the ChatBot's accuracy and allow it to link to it's respons-WebPages with more accurate responses; rather than just recognizing a word and taking you to a page set for it; and hoping it matches the question or query you entered into the ChatBot in the first place.

    Based upon the script I am currently using which I have copied below, is there anyway of reprogramming it so that instead of working from keywords, it can instead be more specific like demonstrated above, where preferablly I could use an asterisk character to represent anything the user may say?
    If anyone is able to do this, it would be fantastic; this ChatBot is something I really want to make professional and on a wider scale.
    And I don't want it changed drastically so that it works completely different, I still intend for it to redirect to WebPages instead of just making code appear on a single page (like someone did before).

    I have copied my header frame script below, there are two frames (header and main) on my Web ChatBot, and it has an index.html page to keep them together.

    So if anyone can re-programme my script below to recognize asterisks (*) as a tag for whatever the user may enter, then that would be great.

    Anyone capable of doing this, I will adore forever. Haa ha; here is the header script which consists of all the code:

    The code header.html (used in the 'header' frame also) code is below:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="imagetoolbar" content="no">

    <noscript><meta http-equiv="REFRESH" content="0;URL=JavaScript not enabled.html"></noscript>

    <style type="text/css">
    margin: 0 auto;
    width: 255px;
    border: 1px solid #111111;
    text-align: center;

    #login .txt
    width: 14em;
    <meta name="Author" content="James William Steven Parker">
    <script type="text/javascript">
    // <![CDATA[

    function containsAll(str,what)
    what = typeof(what) == "string" ? [what] : what;
    str = str.toLowerCase();
    for (var i=0;i<what.length;i++)
    if (str.indexOf(what[i].toLowerCase()) == -1) return false;
    return true;

    function loginFormSubmit(form_element)
    var data = form_element.data.value;
    var new_loc = false;

    // ChatBot
    if (containsAll(data,["britney","spears",])) new_loc = "AI/britney_spears.html";
    else if (containsAll(data,"YOU'RE NOT VERY INTELLIGENT")) new_loc = "AI/your_not_very_intelligent.html";
    else if (containsAll(data,"THE","Time")) new_loc = "AI/time.html";
    else if (containsAll(data,"****")) new_loc = "AI/user_cursed.html";
    else if (containsAll(data,"Chocolate")) new_loc = "AI/chocolate.html";

    // Other
    if (new_loc) parent.main.window.location = new_loc;
    else parent.main.window.location="AI/UNKNOWN RESPONSE.html"; done=1;
    form_element.data.value = "";
    if (form_element.data.focus) form_element.data.focus();
    return false;

    window.onload = function()
    var txt_input = document.getElementById("login").data;
    if (txt_input.focus) txt_input.focus();

    // ]]>
    <base target="main">
    <body background="../Images/wallpaper_header.jpg" style="background-attachment: fixed" text="#000000">

    <body oncontextmenu="return false;" background="../Images/wallpaper_header.jpg" style="background-attachment: fixed" text="#000000">
    <body ondragstart="return false" onselectstart="return false" background="../Images/wallpaper_header.jpg" style="background-attachment: fixed" text="#000000">
    <body onBeforePrint="document.body.style.display='none'" onAfterPrint="document.body.style.display='';" background="../Images/wallpaper_header.jpg" style="background-attachment: fixed" text="#000000">
    <script type="text/javascript">
    document.body.ondragstart = "return false";
    document.body.onselectstart = "return false";
    // -->

    <form id="login" onsubmit="return loginFormSubmit(this)">
    <font face="Arial"><b><font size="4">JWSP ChatBot<br>
    <font size="2">Created by: </font></b><font size="2">
    James William
    Steven Parker</font></font><input type="text" class="txt" name="data" size="30" style="font-family: Arial; border: 1px solid #000080; ; color:#FFFFFF; background-color:#6A7BA7" /><br>
    <br />
    <input type="submit" value="Respond" style="border:1px solid #000080; font-family: Arial; color:#FFFFFF; background-color:#4976C7" />

    <p align="center">&nbsp;</p>
    <p align="center"><font size="1" face="Arial">This software was created by James
    William Steven Parker, and remains the rightful property of his.<br>
    You may <b>not </b>modify any file related to this file, software, site, or
    Copyright © James William Steven Parker, All Rights Reserved</font></p>

    James William Steven Parker | Director of Phone Book Direct, Game-Cheats.co.uk, L J Doulton, A-Frame Leisure, Green Bolt Hosting, Civil Advice, and Parker's Dictionary.

  • #2
    Man, I really think you are using *WAY* the wrong language for this!

    You really NEED a language that is designed for text processing and AI, neither of which JavaScript is any good at.

    Wish you luck, but I think you are doomed to a series of incremental improvements with no really big breakthroughs.
    Be yourself. No one else is as qualified.