Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Are periods optional for .add()? #1

Closed
yocontra opened this issue Jan 28, 2014 · 10 comments
Closed

Are periods optional for .add()? #1

yocontra opened this issue Jan 28, 2014 · 10 comments

Comments

@yocontra
Copy link

I keep getting nothing back from getReply and getReplyFromSentence when not using periods

@yocontra
Copy link
Author

nvm im just dumb

@seiyria
Copy link
Owner

seiyria commented Jan 28, 2014

Glad you got it figured out. Is this something I should add to the README to make it more clear for newer users?

@yocontra
Copy link
Author

@seiyria No it was just me being stupid. Once I loaded a bunch of sentences into it then it seemed to spit responses back out. The only problem I had was that it never mixed any of the sentences for replies, it was just picking a random one with X phrase from the pool so it didn't work well as a chat bot

@seiyria
Copy link
Owner

seiyria commented Jan 28, 2014

@contra Fair enough. Hopefully you'd also seen the addMass function for adding large blobs of text too!

@yocontra
Copy link
Author

Couldn't you simplify the lib to just do this then?

add: (msg) -> @sentences.push msg
reply: (phrase) ->
  out = @sentences.filter (v) -> v.indexOf(phrase) isnt -1
  out = Math.random out[Math.floor(Math.random()*out.length)]
  return out

@seiyria
Copy link
Owner

seiyria commented Jan 28, 2014

I can not. This library is founded on the principle of markov chains. I suspect the reason you're getting your statements back verbatim is because your markov chain order is 4, which is very, very high for not having much data to work off of. My database of ~84k sentences, at a markov chain order of 4, would interpolate statements on common words. My first attempt, at around ~5k, was not nearly so successful in the interpolation process. I would recommend setting a markov order of 2 with a small data set and seeing if you get adequate results. If you would like to try something larger, I would make a test program to feed jsMegaHal War and Peace. One such program might resemble this:

jsmegahal = require './jsMegaHal'
fs = require 'fs'

bot = new jsmegahal(2)

fs.readFile 'wap.txt', 'utf8', (err,data) ->
    return console.log err if err
    lines = data.split("\r\n").join(' ').split(/[?!\.]/)

    bot.add line for line in lines
    console.log "Loaded WAP."

    process.stdin.resume()
    process.stdin.setEncoding 'utf8'
    process.stdin.on 'data', (chunk) -> 
        console.log "chunk: #{chunk}"
        console.log bot.getReplyFromSentence chunk

@yocontra
Copy link
Author

@seiyria That comment was tongue in cheek - I can be a bit of a troll. I'll try setting the markov order a bit lower and feeding it wap

@seiyria
Copy link
Owner

seiyria commented Jan 28, 2014

@contra It's hard to tell sometimes; better safe than sorry. Best of luck!

@yocontra
Copy link
Author

@seiyria Did you strip all of the headings/chapter marks from the source input?

@seiyria
Copy link
Owner

seiyria commented Jan 28, 2014

@contra Yes, in my tests, I did. I would recommend doing so, at least for the legalese at the bottom and the non-useful data at the top.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants