megahal 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/README.md +1 -2
- data/VERSION +1 -1
- data/bin/megahal +5 -4
- data/lib/megahal/megahal.rb +4 -4
- data/megahal.gemspec +5 -6
- data/spec/megahal_spec.rb +90 -0
- data/spec/spec_helper.rb +30 -0
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f74c0203aa8d641b0ec819c3c780fe7d653d0f0
|
4
|
+
data.tar.gz: a371544c8627a102e7f1d97747504a3b2193ee6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d28031463298e5710e1d7cf2a5c330421354e323ace1860159e605e07b8fe9967306de5e367b57fd41baf607317a6c22707ce1cc9510a819c51b660ba6efdcc5
|
7
|
+
data.tar.gz: 26d85479e320a9045627ef795dfd0a9268a0ed0a7a6ffa9eaf56ee51de7b1158bdaa094cc38da915ae75131571c3864240a26a4e6c342cf72818f11d13442a89
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -29,7 +29,6 @@ GEM
|
|
29
29
|
oauth2
|
30
30
|
hashie (3.3.2)
|
31
31
|
highline (1.6.21)
|
32
|
-
hodel_3000_compliant_logger (0.1.1)
|
33
32
|
jeweler (2.0.1)
|
34
33
|
builder
|
35
34
|
bundler (>= 1.0)
|
@@ -89,7 +88,6 @@ DEPENDENCIES
|
|
89
88
|
byebug (~> 3.5)
|
90
89
|
cld (~> 0.7)
|
91
90
|
highline (~> 1.6)
|
92
|
-
hodel_3000_compliant_logger (~> 0.1)
|
93
91
|
jeweler (~> 2.0)
|
94
92
|
rdoc (~> 4.1)
|
95
93
|
rspec (~> 3.1)
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/megahal.svg)](http://badge.fury.io/rb/megahal)
|
3
3
|
[![Dependency Status](https://gemnasium.com/jasonhutchens/megahal.png)](https://gemnasium.com/jasonhutchens/megahal)
|
4
4
|
[![Build Status](https://semaphoreapp.com/api/v1/projects/6889bf33-e547-4200-a4fb-66b339a83d82/307128/shields_badge.svg)](https://semaphoreapp.com/jasonhutchens/megahal)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/jasonhutchens/megahal.png)](https://codeclimate.com/github/jasonhutchens/megahal)
|
6
5
|
|
7
6
|
MegaHAL
|
8
7
|
=======
|
@@ -11,7 +10,7 @@ MegaHAL is a learning chatterbot.
|
|
11
10
|
|
12
11
|
You can run it as a command-line application, or embed it in your own
|
13
12
|
application and make calls to it via a simple
|
14
|
-
[API](http://rubydoc.info/
|
13
|
+
[API](http://www.rubydoc.info/gems/megahal/).
|
15
14
|
|
16
15
|
It is built on top of [Sooth](https://github.com/jasonhutchens/sooth), a simple
|
17
16
|
stochastic predictive model.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/bin/megahal
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'megahal'
|
4
4
|
require 'highline/import'
|
5
|
-
require 'hodel_3000_compliant_logger'
|
6
5
|
require 'ruby-progressbar'
|
6
|
+
require 'logger'
|
7
7
|
|
8
8
|
say("<%= color('" + <<-EOS + "', BOLD) %>")
|
9
9
|
+----------------------------------------------------------+
|
@@ -21,11 +21,12 @@ EOS
|
|
21
21
|
|
22
22
|
class MegaLog
|
23
23
|
def initialize
|
24
|
-
@logger =
|
25
|
-
@logger.
|
24
|
+
@logger = Logger.new("megahal.log")
|
25
|
+
@logger.formatter = proc { |_, _, _, msg| msg + "\n" }
|
26
|
+
@logger.info "MegaHALv10\nStart at: [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
26
27
|
end
|
27
28
|
def exit
|
28
|
-
@logger.info "
|
29
|
+
@logger.info "Stop at: [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
29
30
|
end
|
30
31
|
def error(message)
|
31
32
|
@logger.error "(#{message})"
|
data/lib/megahal/megahal.rb
CHANGED
@@ -116,12 +116,12 @@ class MegaHAL
|
|
116
116
|
dictionary: @dictionary
|
117
117
|
}.to_json)
|
118
118
|
end
|
119
|
-
bar.increment
|
119
|
+
bar.increment unless bar.nil?
|
120
120
|
[:seed, :fore, :back, :case, :punc].each do |name|
|
121
121
|
tmp = _get_tmp_filename(name)
|
122
122
|
instance_variable_get("@#{name}").save(tmp)
|
123
123
|
zipfile.add(name, tmp)
|
124
|
-
bar.increment
|
124
|
+
bar.increment unless bar.nil?
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
@@ -137,12 +137,12 @@ class MegaHAL
|
|
137
137
|
raise "bad version" unless data['version'] == "MH10"
|
138
138
|
@learning = data['learning']
|
139
139
|
@dictionary = data['dictionary']
|
140
|
-
bar.increment
|
140
|
+
bar.increment unless bar.nil?
|
141
141
|
[:seed, :fore, :back, :case, :punc].each do |name|
|
142
142
|
tmp = _get_tmp_filename(name)
|
143
143
|
zipfile.find_entry(name.to_s).extract(tmp)
|
144
144
|
instance_variable_get("@#{name}").load(tmp)
|
145
|
-
bar.increment
|
145
|
+
bar.increment unless bar.nil?
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
data/megahal.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: megahal 0.
|
5
|
+
# stub: megahal 0.5.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "megahal"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.5.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -42,7 +42,9 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/megahal/personalities/sherlock.rb",
|
43
43
|
"lib/megahal/personalities/startrek.rb",
|
44
44
|
"lib/megahal/personalities/starwars.rb",
|
45
|
-
"megahal.gemspec"
|
45
|
+
"megahal.gemspec",
|
46
|
+
"spec/megahal_spec.rb",
|
47
|
+
"spec/spec_helper.rb"
|
46
48
|
]
|
47
49
|
s.homepage = "http://github.com/jasonhutchens/megahal"
|
48
50
|
s.licenses = ["UNLICENSE"]
|
@@ -56,7 +58,6 @@ Gem::Specification.new do |s|
|
|
56
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
59
|
s.add_runtime_dependency(%q<sooth>, ["~> 1.0"])
|
58
60
|
s.add_runtime_dependency(%q<highline>, ["~> 1.6"])
|
59
|
-
s.add_runtime_dependency(%q<hodel_3000_compliant_logger>, ["~> 0.1"])
|
60
61
|
s.add_runtime_dependency(%q<ruby-progressbar>, ["~> 1.7"])
|
61
62
|
s.add_runtime_dependency(%q<rubyzip>, ["~> 1.1"])
|
62
63
|
s.add_runtime_dependency(%q<cld>, ["~> 0.7"])
|
@@ -70,7 +71,6 @@ Gem::Specification.new do |s|
|
|
70
71
|
else
|
71
72
|
s.add_dependency(%q<sooth>, ["~> 1.0"])
|
72
73
|
s.add_dependency(%q<highline>, ["~> 1.6"])
|
73
|
-
s.add_dependency(%q<hodel_3000_compliant_logger>, ["~> 0.1"])
|
74
74
|
s.add_dependency(%q<ruby-progressbar>, ["~> 1.7"])
|
75
75
|
s.add_dependency(%q<rubyzip>, ["~> 1.1"])
|
76
76
|
s.add_dependency(%q<cld>, ["~> 0.7"])
|
@@ -85,7 +85,6 @@ Gem::Specification.new do |s|
|
|
85
85
|
else
|
86
86
|
s.add_dependency(%q<sooth>, ["~> 1.0"])
|
87
87
|
s.add_dependency(%q<highline>, ["~> 1.6"])
|
88
|
-
s.add_dependency(%q<hodel_3000_compliant_logger>, ["~> 0.1"])
|
89
88
|
s.add_dependency(%q<ruby-progressbar>, ["~> 1.7"])
|
90
89
|
s.add_dependency(%q<rubyzip>, ["~> 1.1"])
|
91
90
|
s.add_dependency(%q<cld>, ["~> 0.7"])
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
describe MegaHAL do
|
6
|
+
|
7
|
+
let(:megahal) { MegaHAL.new }
|
8
|
+
|
9
|
+
describe "#list" do
|
10
|
+
it "returns an array of all personalities" do
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#inspect" do
|
15
|
+
it "doesn't return a massive string" do
|
16
|
+
expect(megahal.inspect.length).to be < 100
|
17
|
+
expect(megahal.inspect).to match(/MegaHAL/)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#clear" do
|
22
|
+
it "clears all internal state" do
|
23
|
+
expect(megahal.instance_variables.length).to eq(7)
|
24
|
+
megahal.clear
|
25
|
+
megahal.reply("one two three four five")
|
26
|
+
expect(megahal.instance_variable_get(:@dictionary).length).to eq(15)
|
27
|
+
expect(megahal.instance_variable_get(:@seed).count([1, 2])).to be > 0
|
28
|
+
expect(megahal.instance_variable_get(:@fore).count([1, 1])).to be > 0
|
29
|
+
expect(megahal.instance_variable_get(:@back).count([1, 1])).to be > 0
|
30
|
+
expect(megahal.instance_variable_get(:@case).count([1, 5])).to be > 0
|
31
|
+
expect(megahal.instance_variable_get(:@punc).count([1, 10])).to be > 0
|
32
|
+
megahal.clear
|
33
|
+
expect(megahal.instance_variable_get(:@dictionary).length).to eq(3)
|
34
|
+
expect(megahal.instance_variable_get(:@seed).count([0, 0])).to eq(0)
|
35
|
+
expect(megahal.instance_variable_get(:@fore).count([1, 1])).to eq(0)
|
36
|
+
expect(megahal.instance_variable_get(:@back).count([1, 1])).to eq(0)
|
37
|
+
expect(megahal.instance_variable_get(:@case).count([1, 5])).to eq(0)
|
38
|
+
expect(megahal.instance_variable_get(:@punc).count([1, 10])).to eq(0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#become" do
|
43
|
+
it "switches to another personality" do
|
44
|
+
expect(megahal.reply("holmes")).to_not match(/watson/i)
|
45
|
+
megahal.become(:sherlock)
|
46
|
+
expect(megahal.reply("holmes")).to match(/watson/i)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#reply" do
|
51
|
+
it "swaps keywords" do
|
52
|
+
expect(megahal.reply("why")).to match(/because/i)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#save" do
|
57
|
+
it "saves the brain" do
|
58
|
+
begin
|
59
|
+
file = Tempfile.new('megahal_spec')
|
60
|
+
megahal.clear
|
61
|
+
megahal.reply("one two three four five")
|
62
|
+
megahal.save(file.path)
|
63
|
+
megahal.clear
|
64
|
+
expect(megahal.reply("")).to eq("...")
|
65
|
+
megahal.load(file.path)
|
66
|
+
expect(megahal.reply("")).to eq("one two three four five")
|
67
|
+
ensure
|
68
|
+
file.close
|
69
|
+
file.unlink
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#train" do
|
75
|
+
it "learns from a text file" do
|
76
|
+
megahal.clear
|
77
|
+
begin
|
78
|
+
file = Tempfile.new('megahal_spec')
|
79
|
+
file.write("one two three four five")
|
80
|
+
file.close
|
81
|
+
expect(megahal.reply("")).to eq("...")
|
82
|
+
megahal.train(file.path)
|
83
|
+
expect(megahal.reply("")).to eq("one two three four five")
|
84
|
+
ensure
|
85
|
+
file.unlink
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_profile 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
|
22
|
+
require 'megahal'
|
23
|
+
|
24
|
+
# Requires supporting files with custom matchers and macros, etc,
|
25
|
+
# in ./support/ and its subdirectories.
|
26
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megahal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Hutchens
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: hodel_3000_compliant_logger
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.1'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.1'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: ruby-progressbar
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,6 +210,8 @@ files:
|
|
224
210
|
- lib/megahal/personalities/startrek.rb
|
225
211
|
- lib/megahal/personalities/starwars.rb
|
226
212
|
- megahal.gemspec
|
213
|
+
- spec/megahal_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
227
215
|
homepage: http://github.com/jasonhutchens/megahal
|
228
216
|
licenses:
|
229
217
|
- UNLICENSE
|