cyc-console 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .*.sw?
3
+ .bundle
4
+ Gemfile
5
+ Gemfile.lock
6
+ work
7
+ doc
data/README.txt CHANGED
@@ -66,9 +66,20 @@ And then try to install the gem once again:
66
66
 
67
67
  == BASIC USAGE:
68
68
 
69
- The gem comes with +cyc+ command, so you can simply type
70
- (provided the Cyc server is running on localhost on the default
71
- port and you have rubygems bin directory in your path):
69
+ Prerequisites:
70
+ * Cyc server is running
71
+ * you can download it from http://www.opencyc.org
72
+ * Telnet connection is on
73
+ * type (enable-tcp-server :cyc-api 3601) in the cyc console or Cyc Browser
74
+ -> Tools -> Interactor
75
+ * rubygems +bin+ directory is in your PATH variable:
76
+ * +export PATH=/usr/lib/ruby/gems/1.8/bin+
77
+ * you might have to adjust it to your system (e.g. in Debian it would be
78
+ +/var/lib/gems.../+
79
+ * you might want to store it in your +.bashrc+
80
+
81
+
82
+ The gem comes with +cyc+ command, so you can simply type:
72
83
 
73
84
  $ cyc
74
85
  cyc@localhost:3601>
data/bin/cyc CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
- require 'readline'
3
+
4
4
  require 'cyc/console'
5
5
 
6
6
  if Readline.respond_to?("basic_word_break_characters=")
@@ -1,3 +1,7 @@
1
+ 0.0.7
2
+ - update cycr to v 0.2.0
3
+ 0.0.6
4
+ - dependency on cycr replacing built-in Cyc connection mechanism
1
5
  0.0.5
2
6
  - missing dependency on *colors* added
3
7
  0.0.4
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cyc-console"
3
- s.version = "0.0.5"
4
- s.date = "2009-10-08"
3
+ s.version = "0.0.7"
4
+ s.date = "#{Time.now.strftime("%Y-%m-%d")}"
5
5
  s.summary = "Ruby console for the Cyc ontology"
6
6
  s.email = "apohllo@o2.pl"
7
7
  s.homepage = "http://github.com/apohllo/cyc-console"
@@ -11,18 +11,15 @@ Gem::Specification.new do |s|
11
11
  # the lib path is added to the LOAD_PATH
12
12
  s.require_path = "lib"
13
13
  # include Rakefile, gemspec, README and all the source files
14
- s.files = [
15
- 'lib/cyc/console.rb',
16
- "Rakefile",
17
- "cyc-console.gemspec",
18
- "README.txt",
19
- "changelog.txt"
20
- ]
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
17
  # include README while generating rdoc
22
18
  s.rdoc_options = ["--main", "README.txt"]
23
19
  s.has_rdoc = true
24
20
  s.extra_rdoc_files = ["README.txt"]
25
21
  s.executables = ['cyc']
26
22
  s.add_dependency("colors", [">= 0.0.4"])
23
+ s.add_dependency("cycr", ["~> 0.2.0"])
27
24
  end
28
25
 
@@ -2,13 +2,11 @@
2
2
 
3
3
  require 'readline'
4
4
  require 'colors'
5
- require 'net/telnet'
5
+ require 'cycr'
6
6
 
7
7
  module Cyc
8
- class ParenthesisNotMatched < RuntimeError; end
9
-
10
8
  class Configurable
11
-
9
+
12
10
  attr_reader :configuration
13
11
  attr_writer :verbose
14
12
 
@@ -43,7 +41,7 @@ module Cyc
43
41
 
44
42
  end
45
43
  #
46
- # Stolen (with permission from the author :) from Wirble history for IRB
44
+ # Stolen (with permission from the author :) from Wirble history for IRB
47
45
  # http://pablotron.org/software/wirble/
48
46
  #
49
47
  class History < Configurable
@@ -82,7 +80,7 @@ module Cyc
82
80
  :path => ENV['CYC_FUNCTIONS_FILE'] || "~/.cyc_functions",
83
81
  :perms => File::WRONLY | File::CREAT | File::TRUNC
84
82
  }
85
-
83
+
86
84
  def initialize(opt = nil)
87
85
  @opt = DEFAULTS.merge(opt || {})
88
86
  super()
@@ -104,32 +102,11 @@ module Cyc
104
102
  History.new({})
105
103
  @host = host
106
104
  @port = port
107
- @conn = Net::Telnet.new("Port" => @port, "Telnetmode" => false,
108
- "Host" => @host, "Timeout" => 600)
105
+ @cyc = Cyc::Client.new(:host => @host,:port => @port)
109
106
  @line = ""
110
107
  @count = 0
111
108
  end
112
109
 
113
- # Scans the :str: to find out if the parenthesis are matched
114
- # raises ParenthesisNotMatched exception if there is not matched closing
115
- # parenthesis. The message of the exception contains the string with the
116
- # unmatched parenthesis highlighted.
117
- def match_par(str)
118
- position = 0
119
- str.scan(/./) do |char|
120
- position += 1
121
- next if char !~ /\(|\)/
122
- @count += (char == "(" ? 1 : -1)
123
- if @count < 0
124
- @count = 0
125
- raise ParenthesisNotMatched.
126
- new((position > 1 ? str[0..position-2] : "") +
127
- ")".hl(:red) + str[position..-1])
128
- end
129
- end
130
- @count == 0
131
- end
132
-
133
110
  def add_autocompletion(str)
134
111
  @@constants |= str.split(/[() ]/).select{|e| e =~ /\#\$/}
135
112
  end
@@ -138,38 +115,35 @@ module Cyc
138
115
  def main_loop
139
116
  loop do
140
117
  begin
141
- line = Readline::readline(("cyc@" + "#{@host}:#{@port}" +
142
- (@count > 0 ? ":#{"("*@count}" : "") + "> ").hl(:blue))
143
- case line
144
- when API_QUIT
145
- @conn.puts(line)
118
+ line = Readline::readline(("cyc@" + "#{@host}:#{@port}" +
119
+ (@count > 0 ? ":#{"("*@count}" : "") + "> "))
120
+ case line
121
+ when nil
122
+ puts
146
123
  break
147
- when "exit"
148
- @conn.puts(API_QUIT)
124
+ when API_QUIT,"exit"
125
+ @cyc.raw_talk(API_QUIT) rescue nil
149
126
  break
150
127
  else
151
128
  @line += "\n" unless @line.empty?
152
129
  @line += line
153
130
  letters = @line.split("")
154
131
  Readline::HISTORY.push(@line) if line
155
- if match_par(line)
156
- @conn.puts(@line)
157
- @line = ""
158
- answer = @conn.waitfor(/\d\d\d/)
159
- message = answer.sub(/(\d\d\d) (.*)\n/,"\\2") if answer
160
- if($1.to_i == 200)
161
- puts message
162
- add_autocompletion(message)
163
- else
164
- puts "Error: " + answer.to_s
165
- end
166
- end
132
+ message = @cyc.raw_talk(@line)
133
+ @line = ""
134
+ @count = 0
135
+ puts message.gsub(/(\#\$[\w-]+)/,"\\1".hl(:blue))
136
+ add_autocompletion(message)
167
137
  end
168
- rescue ParenthesisNotMatched => exception
169
- puts exception
138
+ rescue ::Cyc::UnbalancedClosingParenthesis => exception
139
+ puts exception.to_s.sub(/<error>([^<]*)<\/error>/,"\\1".hl(:red))
140
+ @line = ""
141
+ rescue ::Cyc::UnbalancedOpeningParenthesis => exception
142
+ @count = exception.count
143
+ rescue Exception => exception
144
+ puts "Error: " + exception.to_s
145
+ @count = 0
170
146
  @line = ""
171
- # rescue Exception => exception
172
- # puts exception
173
147
  end
174
148
  end
175
149
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyc-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ prerelease:
5
+ version: 0.0.7
5
6
  platform: ruby
6
7
  authors:
7
8
  - Aleksander Pohl
@@ -9,19 +10,30 @@ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-10-08 00:00:00 +02:00
13
- default_executable:
13
+ date: 2012-03-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colors
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.0.4
24
- version:
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: cycr
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.2.0
35
+ type: :runtime
36
+ version_requirements: *id002
25
37
  description: Ruby console for the Cyc ontology with support for readline, colorful output, history, etc.
26
38
  email: apohllo@o2.pl
27
39
  executables:
@@ -31,12 +43,13 @@ extensions: []
31
43
  extra_rdoc_files:
32
44
  - README.txt
33
45
  files:
34
- - lib/cyc/console.rb
35
- - Rakefile
36
- - cyc-console.gemspec
46
+ - .gitignore
37
47
  - README.txt
48
+ - Rakefile
49
+ - bin/cyc
38
50
  - changelog.txt
39
- has_rdoc: true
51
+ - cyc-console.gemspec
52
+ - lib/cyc/console.rb
40
53
  homepage: http://github.com/apohllo/cyc-console
41
54
  licenses: []
42
55
 
@@ -47,21 +60,21 @@ rdoc_options:
47
60
  require_paths:
48
61
  - lib
49
62
  required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
50
64
  requirements:
51
65
  - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  version: "0"
54
- version:
55
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
56
70
  requirements:
57
71
  - - ">="
58
72
  - !ruby/object:Gem::Version
59
73
  version: "0"
60
- version:
61
74
  requirements: []
62
75
 
63
76
  rubyforge_project:
64
- rubygems_version: 1.3.5
77
+ rubygems_version: 1.8.5
65
78
  signing_key:
66
79
  specification_version: 3
67
80
  summary: Ruby console for the Cyc ontology