Author Topic: How do I do a first-order markov chain? (Monty chatbot on torquescript)  (Read 2759 times)

This is what I want to do: http://www.jibble.org/dynamicgraph.php

I want to do it without the GUI interface.

You can try using http://forum.blockland.us/index.php?topic=177446.0

If you can't code this, I'll try to do it myself.

Oh boy, I think I will have to do simsets using contents fileobjects to do this.

I will use a syntax in a text file like this

S = Start Node (start the chain with this)

E = End Node (break the while(){} loop with this)

Code: [Select]
S you
1 you are
1 you little
2 are cake
2 little cake
3 cake liar
E liar

I'd have to get firstWord for the first
« Last Edit: March 10, 2012, 08:21:41 PM by Axolotl »

Um
It says it's not intelligent.
So why would you use it?

I might just use this idea.

Um
It says it's not intelligent.
So why would you use it?
It is the easiest markov chain to script. The results are humorous, too.

oh god I have to do an index simset of all of the word container simset IDs
« Last Edit: March 10, 2012, 08:22:37 PM by Axolotl »

oh god I have to do an index simset of all of the word container simset IDs
Don't get all worked up now, think about it logically.

Think of it like this:

You have a word.
That word has variables, saying what it can connect too.
Each one of those is numbered, and the word has a connectedcount variable or something like that
When you get a new sentence, it adds missing connections and increases that count.

Just a splurge, but that makes sense to me.

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])])

Yeah he's immensely over complicating it.



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 facepalms

I have made some progress, now I can get stuff in a text file starting in S into a specific SimSet.
Code: [Select]
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();


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])])

I want it to actually learn, and then log it into a .txt file
« Last Edit: March 11, 2012, 12:48:05 PM by Axolotl »

Code: [Select]
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();


You can't add strings to a SimSet.

I want it to actually learn, and then log it into a .txt file
...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

...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
thanks otto

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

Code: [Select]
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);
}