Chatbot slecht één zin?!

Status
Niet open voor verdere reacties.

hiddevk

Gebruiker
Lid geworden
16 nov 2007
Berichten
58
Ik ben op basis van de chatbot van Chad Adams (http://www.flashcomponents.net/component/flash_chat_bot.html) bezig met het ontwikkelen van een chatbot in Flash.
Ik wil nu dat slechts één zin wordt weergeven. Dus als je een gesprek voert met meer dan een vraag erin, dat het antwoord op de vraag die je daarvoor had gesteld verdwijnt.

Dus als je iets vraagt:

KLANT: Wie ben jij?
CHATBOT: Ik ben de chatbot van blabla.
KLANT: Hoe oud ben je?
CHATBOT: Ik ben honderd jaar!

en niet:

KLANT: Wie ben jij?
CHATBOT: Ik ben de chatbot van blabla.
KLANT: Hoe oud ben je?
CHATBOT: Ik ben de chatbot van blabla.
Ik ben honderd jaar!
 
de enige actionscript code die er in voorkomt is dit geloof ik:

Code:
ChatBot(); //call constructor

// CONSTRUCTOR
function ChatBot(){
   
	this.callbackHandler = this.Handler; //parameter variable initialized via properties or component inspector panel
	this.callbackHandlerLocation = this._parent;

	Key.addListener(this);
	
	this.init();                
}


// ===============================================
// ::: PUBLIC METHODS :::
// ===============================================


// GETTERS ***********		




// SETTERS ***********

function setCallbackHandler(method, location){
	this.callbackHandlerLocation = (location == undefined) ? this.callbackHandlerLocation: location;
	this.callbackHandler = method;
}

// METHODS **********

function onKeyDown(){
	if(Key.isDown(Key.ENTER)){
		this.findAnswer(this.input_txt.text);
		this.output_txt.scroll = this.output_txt.maxscroll;
		this.input_txt.text = "";
		Selection.setFocus(this.input_txt);
	}		
}

function say(the_str){
	this.output_txt.text += the_str + newline;
}

function init(){
	me = this;
	this.my_xml = new XML();
	this.my_xml.ignoreWhite = true;
	this.my_xml.onLoad = function(success){
		if(success){
			var root_xml = this;
			while(root_xml.nodeName == null){
				root_xml = root_xml.firstChild;	
			}
			//trace(root_xml);
			me.dataObj = new Object();
			me.createObject(me.dataObj, root_xml);
			Selection.setFocus(this.input_txt);			
		}else{
			this.output_txt = "Er is een fout opgetreden!";	
		}

	}
	this.my_xml.load(this.the_file);	
}

// convert the XML database to native flash object database
function createObject(theObj, the_xml){
	for(var i in the_xml.childNodes){
		if(the_xml.childNodes[i].nodeValue == null){
			var obj = theObj[the_xml.childNodes[i].nodeName] = new Object();
			this.createObject(obj, the_xml.childNodes[i]);
		}else{
			theObj["text"] = the_xml.childNodes[i].nodeValue;
		}
	}
}

// search the database based on text entered
function findAnswer(the_str){
	the_str = this.shaveChars(the_str);
	var my_array = the_str.split(" ");
	var firstFound = null;
	my_array.push("text");
	var pos = this.dataObj;
	for(var i = 0; i < my_array.length; i++){
		if(pos[my_array[i]] != undefined){
			pos = pos[my_array[i]];
			if(firstFound == null){
				firstFound = my_array[i];	
			}
		}
	}
	if(pos.length != undefined){	
		var text_array = pos.split("|");
		for(var i = 0; i < text_array.length; i++){
			var n = text_array[i].lastIndexOf(":");
			if(n >= 0){
				var x_str = text_array[i].substr(n+1);				
				this.execCallback(x_str);
			}else{
				this.output_txt.text += text_array[i] + newline;
			}						
		}			
	}else{
		if(firstFound == null){
			this.output_txt.text += "Sorry, Ik snap niet wat u bedoeld!" + newline;
		}else{
			this.output_txt.text += "Ik weet het niet "+firstFound+" dat is." + newline;
		}
	}
}

// removes unwanted characters
function shaveChars(the_str){
	var chars_array = new Array(".", "?", ",", "!", "'");
	for(var i in chars_array){
		var str_array = the_str.split(chars_array[i]);
		the_str = str_array.join("");
	}
	return the_str;
}



// ===============================================
// ::: PRIVATE METHODS :::
// ===============================================


function execCallback(the_str){
	trace("exec: "+the_str+"  "+this.callbackHandler);
	this.callbackHandlerLocation[this.callbackHandler](this, the_str);
}
 
Wellicht zit het em hier in:
PHP:
this.output_txt.text += text_array[i] + newline;
Als je daar van de += eens alleen een = maakt. (Zit in de functie findAnswer)
 
Bedankt!

Hartelijk bedankt Tha Devil! Nu ben ik weer een stuk verder. Alleen het geweldige stukje code dat jij mij net gaf werkt niet bij de zinnen "Sorry, Ik snap niet wat u bedoelt." en "Ik weet niet wat "+firstFound+" is." Dit komt (waarschijnlijk) omdat deze zinnen in het actionscript zelf staan en niet in de xml. Hoe kan ik er voor zorgen dat als hij een van deze twee zinnen zegt, dat deze dan ook alleen komen te staan?

Geweldig bedankt!
 
Zelfde principe:
PHP:
if(firstFound == null){
	this.output_txt.text += "Sorry, Ik snap niet wat u bedoeld!" + newline;
}else{
	this.output_txt.text += "Ik weet het niet "+firstFound+" dat is." + newline;
}

Van de += alleen een = maken :)
 
G-e-w-e-l-d-i-g!

Dank je wel! Nog één klein dingetje (zie topic hieronder) en dan ben ik klaar!
 
Button

Ik heb nog een vraagje; is het mogelijk om een button te maken, waarvan als je er op klikt deze de tekst naar de chatbot stuurt die je in het invoervak hebt ingevuld?
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan