Add expanded usage information to commands

This commit is contained in:
Mispy 2014-04-18 22:51:33 -07:00
parent 47d600bb3b
commit 29f46629ed
2 changed files with 67 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.*.swp .*.swp
Gemfile.lock
pkg pkg

View file

@ -8,7 +8,12 @@ module Ebooks
APP_PATH = Dir.pwd # XXX do some recursive thing instead APP_PATH = Dir.pwd # XXX do some recursive thing instead
def self.new(reponame) def self.new(reponame)
usage = "Usage: ebooks new <reponame>" usage = <<STR
Usage: ebooks new <reponame>
Creates a new skeleton repository defining a template bot in
the current working directory specified by <reponame>.
STR
if reponame.nil? if reponame.nil?
log usage log usage
@ -33,10 +38,21 @@ module Ebooks
end end
def self.consume(pathes) def self.consume(pathes)
usage = <<STR
Usage: ebooks consume <corpus_path> [corpus_path2] [...]
Processes some number of text files or json tweet corpuses
into usable models. These will be output at model/<name>.model
STR
if pathes.empty?
log usage
exit
end
pathes.each do |path| pathes.each do |path|
filename = File.basename(path) filename = File.basename(path)
shortname = filename.split('.')[0..-2].join('.') shortname = filename.split('.')[0..-2].join('.')
hash = Digest::MD5.hexdigest(File.read(path))
outpath = File.join(APP_PATH, 'model', "#{shortname}.model") outpath = File.join(APP_PATH, 'model', "#{shortname}.model")
Model.consume(path).save(outpath) Model.consume(path).save(outpath)
@ -45,6 +61,17 @@ module Ebooks
end end
def self.gen(model_path, input) def self.gen(model_path, input)
usage = <<STR
Usage: ebooks gen <model_path> [input]
Make a test tweet from the processed model at <model_path>.
Will respond to input if provided.
STR
if model_path.nil?
log usage
exit
end
model = Model.load(model_path) model = Model.load(model_path)
if input && !input.empty? if input && !input.empty?
puts "@cmd " + model.make_response(input, 135) puts "@cmd " + model.make_response(input, 135)
@ -54,11 +81,35 @@ module Ebooks
end end
def self.score(model_path, input) def self.score(model_path, input)
usage = <<STR
Usage: ebooks score <model_path> <input>
Scores "interest" in some text input according to how
well unique keywords match the model.
STR
if model_path.nil? || input.nil?
log usage
exit
end
model = Model.load(model_path) model = Model.load(model_path)
model.score_interest(input) model.score_interest(input)
end end
def self.archive(username, outpath) def self.archive(username, outpath)
usage = <<STR
Usage: ebooks archive <username> <outpath>
Downloads a json corpus of the <username>'s tweets to <outpath>.
Due to API limitations, this can only receive up to ~3000 tweets
into the past.
STR
if username.nil? || outpath.nil?
log usage
exit
end
Archive.new(username, outpath).sync Archive.new(username, outpath).sync
end end
@ -73,6 +124,17 @@ module Ebooks
end end
def self.jsonify(paths) def self.jsonify(paths)
usage = <<STR
Usage: ebooks jsonify <old_corpus_path> [old_corpus_path2] [...]
Takes an old-style corpus of plain tweet text and converts it to json.
STR
if paths.empty?
log usage
exit
end
paths.each do |path| paths.each do |path|
name = File.basename(path).split('.')[0] name = File.basename(path).split('.')[0]
new_path = name + ".json" new_path = name + ".json"
@ -102,12 +164,12 @@ module Ebooks
def self.command(args) def self.command(args)
usage = """Usage: usage = """Usage:
ebooks new <reponame> ebooks new <reponame>
ebooks consume <corpus_path> [...] ebooks consume <corpus_path> [corpus_path2] [...]
ebooks gen <model_path> [input] ebooks gen <model_path> [input]
ebooks score <model_path> <input> ebooks score <model_path> <input>
ebooks archive <@user> <outpath> ebooks archive <@user> <outpath>
ebooks tweet <model_path> <@bot> ebooks tweet <model_path> <@bot>
ebooks jsonify <old_corpus_path> [...] ebooks jsonify <old_corpus_path> [old_corpus_path2] [...]
""" """
if args.length == 0 if args.length == 0