cogibara 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ad9864dae4e0ce82e84f8659cfb2a9597176d1d
4
- data.tar.gz: 0ac39e5812965c0ece31f8a640debe63bd447561
3
+ metadata.gz: 7c1dc7b0524e5722308a6ba9859ef45b3229f6ea
4
+ data.tar.gz: abed0cbc0cf488faf5e7cd4757d6fb7099900697
5
5
  SHA512:
6
- metadata.gz: a2793dcb9631b658eed596366c4820edac9130a1bc7dbf2592a9b50da73ae4198352007ce65ca66747bf49a8be61b9b7584f773d2c50efcabd8f8d3cc00a163b
7
- data.tar.gz: 15cd6d378b86e5ae0cb41996e0a42ea892351e558fd2d3dcad8242e88c387f5cdcca6673e1558ad90efda7daab5f125d2905b94fc029b3f8e07211871554300d
6
+ metadata.gz: c597387ef14b260f1fabfc98ffd013a27aea44a2b9b669844be4956b955ceb86135e05a9dd7dca9d009f22c822929a4e84eed9b16212bfa5cb7aae84f89ee733
7
+ data.tar.gz: 3c53e0b828e8cdf1c478cfc8592e27494888f1b847fb4177d1845abaccc952a213bbd367621421c680eb3de8faaab694c6eb37e578d88be6cc23f5ba979391d9
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Cogibara
2
2
 
3
- Your friendly natural language interface to computer and the internet, leveraging the power of NLP techniques used in applications such as Siri! Why let your someone else decide what you need your personal assistant software to do? Cogibara uses free and open source libraries and APIs to let you ask general knowledge or math questions, manage your calendar, or just chat when you're bored. It's easy to add new capabilites or integrate other tools; The gem handles the infrastructure and language processing so you can focus on making your Cogibara do whatever awesome things you want it to!
3
+ Your friendly natural language interface to computer and the internet, leveraging the power of NLP techniques used in applications such as Siri! Why let your someone else decide what you need your personal assistant software to do? Cogibara uses free and open source libraries and APIs to let you ask general knowledge or math questions, manage your calendar, or just chat when you're bored. It's easy to add new capabilites or integrate other tools; the gem handles the infrastructure and language processing so you can focus on making your Cogibara do whatever awesome things you want it to.
4
4
 
5
- Check out the [demo client](http://goo.gl/7XOou) and its [github page](https://github.com/wstrinz/cogibara-client)! Its just something I put together with ExtJS and Rails, so it's got some bugs at the moment, but it should give you an idea of what the gem can do.
5
+ For a demo, try tweeting [@Cogibara](https://twitter.com/cogibara), or check out the [demo client](http://goo.gl/7XOou) and its [github page](https://github.com/wstrinz/cogibara-client). Its just something I put together with ExtJS and Rails, so it's got some bugs at the moment, but it should give you an idea of what the gem can do.
6
6
 
7
7
  **NOTE**
8
8
  This gem is still in development, there is no documentation besides this readme, I haven't written any tests, and important things may be implemented in very silly ways. Feel free [tell me](https://github.com/wstrinz/cogibara/issues) where this is so (I'd appreciate it in fact), but you've been warned. I was planning on keeping this private for a few more months of development, however other projects have come up for the summer, so I'm releasing what I have now in case I don't get much time to work on it.
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cogibara'
3
+ require 'slop'
4
+ require 'redis'
5
+
6
+ def text(msg)
7
+ Cogibara::message_handler.handle(msg)
8
+ end
9
+
10
+
11
+ def text_loop
12
+ loop do
13
+ text $stdin.gets
14
+ end
15
+ end
16
+
17
+ def text_or_file
18
+ puts @config_file
19
+ if !@config_file && File.exist?("./#{@msg}")
20
+ Cogibara::file_handler.handle(File.open("./#{ARGV[0]}",'rb').read, "local")
21
+ else
22
+ text(@msg)
23
+ end
24
+ end
25
+
26
+ def parse
27
+
28
+ opts = Slop.parse do
29
+ on 'v', 'verbose', 'Verbose output'
30
+ on 'm=', 'message', 'Message'
31
+ on 'n=', 'name', 'Name'
32
+ on 'c=', 'config', 'Configuration file (.rb)'
33
+ on 'r', 'redis', 'Standalone Redis mode'
34
+ end
35
+
36
+ @verbose = opts.verbose?
37
+ @msg = opts[:message]
38
+ @name = opts[:name] || "cogibara"
39
+ @config_file = opts[:config]
40
+ @redis_mode = opts[:redis]
41
+
42
+ if !@msg
43
+ if @config_file
44
+ @verbose = false
45
+ configure
46
+ text_loop
47
+ else
48
+ @msg = ARGV.join(' ')
49
+ if File.exist?("./#{@msg}")
50
+ ext = @msg.to_s.split('.').last
51
+ @config_file = @msg if %w(yml rb).include? ext
52
+ end
53
+ @verbose = false
54
+ end
55
+ end
56
+ end
57
+
58
+ def configure
59
+ if @config_file
60
+ ext = @config_file.to_s.split('.').last
61
+ if ext == 'yml'
62
+ Cogibara::dispatcher.config_from_yaml(@config_file.to_s)
63
+ else
64
+ load './' + @config_file.to_s
65
+ end
66
+ else
67
+ Cogibara.default_config
68
+ end
69
+ Cogibara.setup do |config|
70
+ config.name = @name unless @name.nil?
71
+ config.local = true
72
+ config.use_redis = false
73
+ config.verbose = @verbose unless @verbose.nil?
74
+ end
75
+ end
76
+
77
+ def standalone_redis
78
+ @red = Redis.new
79
+ Redis.new.subscribe(:toCapy) do |on|
80
+ on.message do |channel, msg|
81
+ file = @red.hmget("#{msg}",'file')
82
+ text = @red.hmget("#{msg}",'text')
83
+ client = @red.hmget("#{msg}",'client')[0].to_i
84
+ puts "message from #{client}"
85
+ if file[0]
86
+ puts "Handling as file "
87
+ begin
88
+ Cogibara::FileHandler.new.handle(file[0], client)
89
+ rescue Exception
90
+ puts "an error occured! " + ($!).to_s
91
+ end
92
+ elsif text[0]
93
+ puts "Handling as text"
94
+ Cogibara::message_handler.handle(Cogibara::Message.new(text[0],client))
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ parse
101
+
102
+ configure
103
+
104
+ standalone_redis if @redis_mode
105
+
106
+ ARGV[0] && (@msg != @config_file) ? text_or_file : text_loop
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Cogibara::VERSION
9
9
  spec.authors = ["wstrinz"]
10
10
  spec.email = ["wstrinz@gmail.com"]
11
- spec.description = %q{Modular, extensible personal assistant}
11
+ spec.description = %q{A framework for combining natural speech processing tools with public APIs. Basic functions work out of the box, and with a bit of configuration you can get weather information, manage your google calendar, or access wolfram alpha, all using your voice or natural language text. If you want more functionality, it's easy to associate your own code with a keyword or speech category. Try the demo interface by tweeting @Cogibara}
12
12
  spec.summary = %q{Modular, extensible personal assistant}
13
13
  spec.homepage = "https://github.com/wstrinz/cogibara"
14
14
  spec.license = "MIT"
@@ -5,7 +5,7 @@ module Cogibara
5
5
 
6
6
  def defaults
7
7
  {
8
- name: "cucumber",
8
+ name: "cogibara",
9
9
  speak: false,
10
10
  text: true,
11
11
  hard_parse: true,
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  module Cogibara
2
3
  class Dispatcher
3
4
  def operators
@@ -97,8 +98,8 @@ module Cogibara
97
98
  file_operators.has_key?(keyword)
98
99
  end
99
100
 
100
- def config_from_yaml(file)
101
- yml = file
101
+ def config_from_yaml(yml)
102
+ yml = YAML.load_file(yml) if yml.is_a? String
102
103
  yml["modules"].each do |mod|
103
104
  mod_name = mod["module_name"]
104
105
  mod_keywords = mod["keywords"]
@@ -4,6 +4,8 @@ require 'wolfram'
4
4
 
5
5
  class Knowledge < Cogibara::OperatorBase
6
6
 
7
+ PODS = %w(Result Exact\ result Basic\ information Decimal\ approximation)
8
+
7
9
  def initialize_operator
8
10
  Wolfram.appid = self.operator_config["WOLFRAM_KEY"]
9
11
  # @wolfram = WolframAlpha.new
@@ -18,38 +20,20 @@ class Knowledge < Cogibara::OperatorBase
18
20
  def process(query)
19
21
  word = query.text.split[0]
20
22
 
23
+ valid_result = false
21
24
  if is_question_word?(word)
22
25
  result = Wolfram::HashPresenter.new(Wolfram.fetch(query.text)).to_hash
23
- if result[:pods]["Result"] || result[:pods]["Exact result"] || result[:pods]["Basic information"]
26
+ recognized = result[:pods].keys & PODS
27
+ unless recognized.empty?
24
28
  valid_result = true
25
- if result[:pods]["Result"]
26
- msg = result[:pods]["Result"][0]
27
- elsif result[:pods]["Exact result"]
28
- msg = result[:pods]["Exact result"][0]
29
- elsif result[:pods]["Basic information"]
30
- msg = result[:pods]["Basic information"][0]
29
+ msg = result[:pods][recognized[0]][0]
30
+ if recognized.length > 1
31
+ recognized.shift
32
+ msg += ", " + recognized.map{|x| x + ": " + result[:pods][x][0].to_s}.join(", ")
31
33
  end
32
- else
33
- valid_result == false
34
34
  end
35
- # valid_result = !(!result[:pods]["Result"] || result[:pods]["Result"][0] == "(data not available)")
36
- else
37
- valid_result = false
38
35
  end
39
36
 
40
- if valid_result
41
- if msg == "(data not available)"
42
- # msg = @cleverbot.write(query.text) + " (dk)"
43
- # # puts msg
44
- # msg
45
- nil
46
- else
47
- msg
48
- end
49
- else
50
- # @cleverbot.write(query.text)
51
- nil
52
- end
53
- # valid_result ? result[:pods]["Result"][0] : @cleverbot.write(query.text)
37
+ valid_result ? msg : nil
54
38
  end
55
39
  end
@@ -1,3 +1,3 @@
1
1
  module Cogibara
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogibara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - wstrinz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -248,12 +248,16 @@ dependencies:
248
248
  - - '>='
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
- description: Modular, extensible personal assistant
251
+ description: A framework for combining natural speech processing tools with public
252
+ APIs. Basic functions work out of the box, and with a bit of configuration you can
253
+ get weather information, manage your google calendar, or access wolfram alpha, all
254
+ using your voice or natural language text. If you want more functionality, it's
255
+ easy to associate your own code with a keyword or speech category. Try the demo
256
+ interface by tweeting @Cogibara
252
257
  email:
253
258
  - wstrinz@gmail.com
254
259
  executables:
255
- - cogibara-local
256
- - cogibara-redis
260
+ - cogibara
257
261
  extensions: []
258
262
  extra_rdoc_files: []
259
263
  files:
@@ -262,8 +266,7 @@ files:
262
266
  - LICENSE.txt
263
267
  - README.md
264
268
  - Rakefile
265
- - bin/cogibara-local
266
- - bin/cogibara-redis
269
+ - bin/cogibara
267
270
  - cogibara.gemspec
268
271
  - lib/cogibara.rb
269
272
  - lib/cogibara/configuration.rb
@@ -291,7 +294,6 @@ files:
291
294
  - lib/cogibara/text_parser.rb
292
295
  - lib/cogibara/transcriber.rb
293
296
  - lib/cogibara/version.rb
294
- - tempfile-136980540654057
295
297
  homepage: https://github.com/wstrinz/cogibara
296
298
  licenses:
297
299
  - MIT
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'cogibara'
3
- require 'slop'
4
-
5
- def text(msg)
6
- Cogibara::message_handler.handle(msg)
7
- end
8
-
9
-
10
- def text_loop
11
- loop do
12
- text $stdin.gets
13
- end
14
- end
15
-
16
- def text_or_file
17
- if File.exist?("./#{@msg}")
18
- Cogibara::file_handler.handle(File.open("./#{ARGV[0]}",'rb').read, "local")
19
- else
20
- text(@msg)
21
- end
22
- end
23
-
24
- def parse
25
-
26
- opts = Slop.parse do
27
- on 'v', 'verbose', 'Verbose output'
28
- on 'm=', 'message', 'Message'
29
- on 'n=', 'name', 'Name'
30
- on 'c=', 'config', 'Configuration file (.rb)'
31
- end
32
-
33
- @verbose = opts.verbose?
34
- @msg = opts[:message]
35
- @name = opts[:name] || "cogibara"
36
- @config_file = opts[:config]
37
-
38
- if !@msg
39
- if @config_file
40
- @verbose = false
41
- @name = "cogibara"
42
- configure
43
- text_loop
44
- else
45
- @msg = ARGV.join(' ')
46
- @name = "cogibara"
47
- @verbose = false
48
- end
49
- end
50
- end
51
-
52
- def configure
53
- if @config_file
54
- load './' + @config_file.to_s
55
- else
56
- Cogibara.default_config
57
- end
58
- Cogibara.setup do |config|
59
- config.name = @name unless @name.nil?
60
- config.local = true
61
- config.use_redis = false
62
- config.verbose = @verbose unless @verbose.nil?
63
- end
64
- end
65
-
66
- parse
67
-
68
- configure
69
-
70
- ARGV[0] ? text_or_file : text_loop
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'cogibara'
4
-
5
- require 'redis'
6
- @red = Redis.new
7
-
8
- Cogibara.setup do |config|
9
- config.name = "cogibara"
10
- end
11
-
12
- if ARGV[0]
13
- load "./#{ARGV[0]}"
14
- else
15
- Cogibara.default_config
16
- end
17
-
18
- Redis.new.subscribe(:toCapy) do |on|
19
- on.message do |channel, msg|
20
- # puts msg
21
- file = @red.hmget("#{msg}",'file')
22
- text = @red.hmget("#{msg}",'text')
23
- @current_client = @red.hmget("#{msg}",'client')[0].to_i
24
- puts "message from #{@current_client}"
25
- if file[0]
26
- puts "Handling as file "
27
- begin
28
- Cogibara::FileHandler.new.handle(file[0], @current_client)
29
- rescue Exception
30
- puts "an error occured! " + ($!).to_s
31
- end
32
- elsif text[0]
33
- puts "Handling as text"
34
- Cogibara::message_handler.handle(Cogibara::Message.new(text[0],@current_client))
35
- end
36
- end
37
- end
@@ -1,6 +0,0 @@
1
- require 'yaml'
2
- Cogibara.setup_dispatcher do |dispatcher|
3
- yml = YAML.load_file('/home/wstrinz/Documents/Projects/speechrecog/config.yml')
4
- dispatcher.config_from_yaml(yml)
5
- # dispatcher.register_operator(["REMINDER"],{name: "Reminder Setter"})
6
- end