Blockland Forums > Modification Help

How do I do a first-order markov chain? (Monty chatbot on torquescript)

Pages: << < (3/4) > >>

Axolotl:

OK, I think I might have a better algorithm

I don't have to put simsets in simsets

I just have to make a list thing that corresponds to the simsets

I could just set the name of a SimSet

* Axolotl facepalmsI have made some progress, now I can get stuff in a text file starting in S into a specific SimSet.

--- Code: ---new simSet(AxoBot_StartOfMarkov); // start of markov chain

%file = new FileObject();
%file.openForRead( $AxoBot_MarkovBrain );
while( !%file.isEoF() )
{
%line = %file.readLine();
if( firstWord( %line ) $= "S" )
AxoBot_StartOfMarkov.add( restWords( %line ) );
}
%file.close();
%file.delete();


--- End code ---


--- Quote from: otto-san on March 10, 2012, 11:36:09 PM ---i have a chatbot that does this


you basically have a huge network of single-word values connected and logged by arrays (i stored it in a scriptobject)


word[0] = word
wordChain[word, 0] = wordc
wordChain[word, 1] = wordc
wordChains[word] = 1
words = 0

and so on, and then to get a string, you'd just start at a random word (word[getRandom(0, words)]) and then continue tagging on random strung words (wordChain[lastword, getRandom(0, wordChains[lastword])])


--- End quote ---
I want it to actually learn, and then log it into a .txt file

Port:


--- Quote from: Axolotl on March 11, 2012, 12:36:01 PM ---
--- Code: ---new simSet(AxoBot_StartOfMarkov); // start of markov chain

%file = new FileObject();
%file.openForRead( $AxoBot_MarkovBrain );
while( !%file.isEoF() )
{
%line = %file.readLine();
if( firstWord( %line ) $= "S" )
AxoBot_StartOfMarkov.add( restWords( %line ) );
}
%file.close();
%file.delete();


--- End code ---

--- End quote ---

You can't add strings to a SimSet.

otto-san:


--- Quote from: Axolotl on March 11, 2012, 12:36:01 PM ---I want it to actually learn, and then log it into a .txt file

--- End quote ---
...what i gave you was not the code in its entirety


it was how you'd set up the library


you'd have to put forth the little effort it takes to write something that makes it learn and use the words then put it into a file if you wanted to have it do that

Axolotl:


--- Quote from: otto-san on March 11, 2012, 05:54:28 PM ---...what i gave you was not the code in its entirety


it was how you'd set up the library


you'd have to put forth the little effort it takes to write something that makes it learn and use the words then put it into a file if you wanted to have it do that

--- End quote ---
thanks otto

Truce:

I had made this code over two years ago so bad practices aside it might be a nice reference.


--- Code: ---function ChatAI_brown townyze(%line)
{
if(!isObject($ChatAI::Start))
$ChatAI::Start = new ScriptGroup();

%before = "\n";
%group = $ChatAI::Start;

for(%i = 0; %i < getWordCount(%line); %i++)
{
%word = getWord(%line,%i);
%cnt = %group.getCount();

for(%j = 0; %j < %cnt; %j++)
{
if(%group.getObject(%j).value $= %word)
break;
}

if(%j == %cnt)
{
%pointer = new ScriptObject();
%pointer.value = %word;
%group.add(%pointer);
}

if(!isObject($ChatAI::Word[%word]))
$ChatAI::Word[%word] = new ScriptObject();

if(!isObject($ChatAI::Word[%word]._[%before]))
$ChatAI::Word[%word]._[%before] = new ScriptGroup();

%group = $ChatAI::Word[%word]._[%before];
%before = %word;
}

for(%j = 0; %j < %group.getCount(); %j++)
{
if(%group.getObject(%j).getName() $= "End")
return;
}

%pointer = new ScriptObject(End);
%group.add(%pointer);
}

function ChatAI_Construct()
{
%obj = $ChatAI::Start.getObject(getRandom(0,$ChatAI::Start.getCount() - 1));
%last = "\n";
%word = %obj.value;

while(1)
{
%line = %line @ %word @ " ";

%target = $ChatAI::Word[%word];
%obj = %target._[%last].getObject(getRandom(0,%target._[%last].getCount() - 1));

if(!isObject(%obj))
{
echo("SOMETHING WENT DRASTICALLY WRONG, RUN FOR YOUR LIVES");
return;
}

if(%obj.getName() $= "End")
break;

%last = %word;
%word = %obj.value;
}

return trim(%line);
}
--- End code ---


Pages: << < (3/4) > >>

Go to full version