cycr 0.0.6 → 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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .*.sw?
data/README.txt CHANGED
@@ -0,0 +1,137 @@
1
+ = cycr
2
+
3
+ * http://github.com/apohllo/cycr
4
+
5
+ = DESCRIPTION
6
+
7
+ 'cycr' is a Ruby client for the (Open)Cyc server http://www.opencyc.org.
8
+
9
+ = FEATURES/PROBLEMS
10
+
11
+ * The text protocol is used to talk with Cyc
12
+ * Ruby symbols are converted to Cyc symbols
13
+ * Ruby arrays are converted to SubL arrays
14
+ * Ruby calls on the client are transparently translated to SubL
15
+ * Support for subcalls (like 'with-any-mt')
16
+ * Support for NARTs might not be fully functional (but works somehow)
17
+ * Support for CycL queries not implemented yet!
18
+
19
+ = SYNOPSIS
20
+
21
+ 'cycr' is a Ruby client for the (Open)Cyc server. It is designed as a
22
+ substitution for the original Java client. It allows for conversation
23
+ with the ontology with regular Ruby objects (like symbols, arrays)
24
+ and also exposes the raw text protocol.
25
+
26
+ = REQUIREMENTS
27
+
28
+ (Open)Cyc server with TCP communication enabled.
29
+
30
+ = INSTALL
31
+
32
+ You need RubyGems v.1.3.5 at least:
33
+
34
+ $ gem -v
35
+ 1.2.0 # => not OK
36
+ $ gem update --system
37
+ ...
38
+ $ gem -v
39
+ 1.3.7 # => OK
40
+
41
+ The gem is available at rubygems.org, so you can install it with:
42
+
43
+ $ sudo gem install cycr
44
+
45
+ == BASIC USAGE
46
+
47
+ Prerequisites:
48
+
49
+ * Cyc server is running
50
+ ** you can download it from http://www.opencyc.org
51
+ * Telnet connection is on
52
+ ** type (enable-tcp-server :cyc-api 3601) in the cyc console or Cyc Browser
53
+ -> Tools -> Interactor
54
+
55
+ The you can start 'irb' to see it in action:
56
+
57
+ $ irb
58
+ # include the cycr gem
59
+ require 'cycr'
60
+
61
+ # create the cyc client object, default host: localhost, port: 3601
62
+ cyc = Cyc::Client.new
63
+
64
+ # check if Dog generalizes to Animal
65
+ cyc.genls? :Dog, :Animal # => T
66
+
67
+ # check if Animal generalizes to Dog
68
+ cyc.genls? :Animal, :Dog # => nil
69
+
70
+ # check the minimal generalizations of Animal
71
+ genls = cyc.min_genls :Animal
72
+ # => [:"Organism-Whole", :"PerceptualAgent-Embodied",
73
+ :"Agent-NonArtifactual", :SolidTangibleThing, [:CollectionUnionFn,
74
+ [:TheSet, :Animal, [:GroupFn, :Animal]]],...
75
+
76
+ # check the maximal specializations of the first of the above results
77
+ cyc.max_specs genls.first
78
+ # => [:Microorganism, :EukaryoticOrganism, :"Unvaccinated-Generic",
79
+ :"Vaccinated-Generic", :MulticellularOrganism, :Heterotroph, :Autotroph,
80
+ :Lichen, :TerrestrialOrganism, :Animal, :AquaticOrganism, :Mutant,
81
+ :Carnivore, :Extraterrestrial, :"Exotic-Foreign",...
82
+
83
+ # It works with NARTs (but I didn't tested this functionality extensively,
84
+ # so this might cause some problems - beware):
85
+ genls[4]
86
+ # => [:CollectionUnionFn, [:TheSet, :Animal, [:GroupFn, :Animal]]]
87
+
88
+ cyc.max_specs genls[4]
89
+ # => [:Animal, [:GroupFn, :Animal]]
90
+
91
+ # What is more, you might even build complex subcalls, such as:
92
+ cyc.genls? :Person, :HomoSapiens # => nil
93
+ cyc.with_any_mt{|cyc| cyc.genls? :Person, :HomoSapiens} # => T
94
+
95
+ # If you want to see the query which is send to Cyc, just turn on the
96
+ # debugging:
97
+ cyc.debug = true
98
+ cyc.genls? :Dog, :Anial
99
+ # Send: (genls? #$Dog #$Animal)
100
+ # Recv: 200 T
101
+ # => "T"
102
+
103
+ # The same way, you can turn it off:
104
+ cyc.debug = false
105
+
106
+ # Remember to close the client on exit
107
+ cyc.close
108
+
109
+ == LICENSE:
110
+
111
+ (The MIT License)
112
+
113
+ Copyright (c) 2008-2010 Aleksander Pohl
114
+
115
+ Permission is hereby granted, free of charge, to any person obtaining
116
+ a copy of this software and associated documentation files (the
117
+ 'Software'), to deal in the Software without restriction, including
118
+ without limitation the rights to use, copy, modify, merge, publish,
119
+ distribute, sublicense, and/or sell copies of the Software, and to
120
+ permit persons to whom the Software is furnished to do so, subject to
121
+ the following conditions:
122
+
123
+ The above copyright notice and this permission notice shall be
124
+ included in all copies or substantial portions of the Software.
125
+
126
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
127
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
128
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
129
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
130
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
131
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
132
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
133
+
134
+ == FEEDBACK
135
+
136
+ * mailto:apohllo@o2.pl
137
+
data/changelog.txt ADDED
@@ -0,0 +1,34 @@
1
+ 0.0.7
2
+ - remove predefined SubL routines
3
+ 0.0.6
4
+ - write README with usage example
5
+ - fix NARTs containing NARTs
6
+ - fix spec for Ruby 1.9.2
7
+ 0.0.5
8
+ - fix parsing of assertions with NART MT
9
+ - fix other NART issues
10
+ 0.0.4
11
+ - remove special NART treatment
12
+ - allow for nested SubL calls
13
+ 0.0.3
14
+ - support for assertions
15
+ - fix library initialization
16
+ - typo in specs
17
+ 0.0.2
18
+ - NARTs accessible via their names
19
+ - parser extracted into separate file
20
+ 0.0.1
21
+ - namespace changed to Cyc
22
+ - gem name changed to cycr
23
+ - server changed to client :-)
24
+ - allow for reconnection
25
+ - host and port of client are readable
26
+ - fix: multiline answer
27
+ - fix: empty answer
28
+ - fix: loading of predefined routines
29
+ - fix: waiting for newline before processing answer
30
+ - basic support for NARTs
31
+ - basic configuration of host and port
32
+ - denotation query added
33
+ - support for quotation in message
34
+ - running in multiple processes creates independent connectors
data/cycr.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cycr"
3
- s.version = "0.0.6"
4
- s.date = "2010-12-07"
3
+ s.version = "0.0.7"
4
+ s.date = "2010-12-22"
5
5
  s.summary = "Ruby client for the (Open)Cyc server"
6
6
  s.email = "apohllo@o2.pl"
7
7
  s.homepage = "http://github.com/apohllo/cycr"
@@ -9,12 +9,11 @@ Gem::Specification.new do |s|
9
9
  s.description = "Ruby wrapper for (Open)Cyc server and ontology"
10
10
  s.has_rdoc = false
11
11
  s.authors = ['Aleksander Pohl']
12
- s.files = ["Rakefile", "cycr.gemspec", 'lib/cycr.rb'] +
13
- Dir.glob("lib/**/*")
12
+ s.files = `git ls-files`.split("\n")
14
13
  s.test_files = Dir.glob("spec/**/*")
15
14
  s.rdoc_options = ["--main", "README.txt"]
16
15
  s.has_rdoc = true
17
16
  s.extra_rdoc_files = ["README.txt"]
18
- s.add_dependency("rspec", [">= 1.2.9"])
17
+ s.add_development_dependency("rspec", [">= 1.2.9"])
19
18
  end
20
19
 
data/lib/cycr/client.rb CHANGED
@@ -19,20 +19,6 @@ module Cyc
19
19
  @parser = Parser.new
20
20
  @mts_cache = {}
21
21
  @builder = Builder.new
22
-
23
- # read domains mapings
24
- # talk(File.read(File.join(
25
- # File.dirname(__FILE__), 'domains.lisp')))
26
-
27
- # read utility functions
28
- talk(File.read(File.join(
29
- File.dirname(__FILE__), 'words_reader.lisp')))
30
-
31
- # wait untill files are processed
32
- send_message("(define end-of-routines () ())")
33
- while answer = receive_answer do
34
- break if answer =~ /END-OF-ROUTINES/
35
- end
36
22
  end
37
23
 
38
24
  # (Re)connects to the cyc server.
data/spec/client.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'lib/cycr'
1
+ $:.unshift "lib"
2
+ require 'cycr'
2
3
 
3
4
  describe Cyc::Client do
4
5
  before(:each) do
@@ -21,9 +22,9 @@ describe Cyc::Client do
21
22
  it "should allow multiple processes to use the client" do
22
23
  parent_pid = Process.pid
23
24
  if fork
24
- @client.find_collection("Cat")
25
+ @client.find_constant("Cat")
25
26
  else
26
- @client.find_collection("Dog")
27
+ @client.find_constant("Dog")
27
28
  end
28
29
  if Process.pid == parent_pid
29
30
  Process.waitall
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aleksander Pohl
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-07 00:00:00 +01:00
17
+ date: 2010-12-22 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  - 2
31
31
  - 9
32
32
  version: 1.2.9
33
- type: :runtime
33
+ type: :development
34
34
  version_requirements: *id001
35
35
  description: Ruby wrapper for (Open)Cyc server and ontology
36
36
  email: apohllo@o2.pl
@@ -41,24 +41,25 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.txt
43
43
  files:
44
+ - .gitignore
45
+ - README.txt
44
46
  - Rakefile
47
+ - changelog.txt
45
48
  - cycr.gemspec
46
49
  - lib/cycr.rb
47
- - lib/cycr/sexpr.rex
48
- - lib/cycr/parser.rb
49
- - lib/cycr/domains.lisp
50
- - lib/cycr/sexpr.flex
50
+ - lib/cycr/assertion.rb
51
51
  - lib/cycr/builder.rb
52
- - lib/cycr/constants.rb
53
- - lib/cycr/collection.rb
54
- - lib/cycr/sexpr.rex.rb
55
52
  - lib/cycr/client.rb
53
+ - lib/cycr/collection.rb
54
+ - lib/cycr/constants.rb
55
+ - lib/cycr/domains.lisp
56
56
  - lib/cycr/extensions.rb
57
- - lib/cycr/assertion.rb
58
- - lib/cycr/words_reader.lisp
59
- - README.txt
60
- - spec/client.rb
57
+ - lib/cycr/parser.rb
58
+ - lib/cycr/sexpr.flex
59
+ - lib/cycr/sexpr.rex
60
+ - lib/cycr/sexpr.rex.rb
61
61
  - spec/assertion.rb
62
+ - spec/client.rb
62
63
  has_rdoc: true
63
64
  homepage: http://github.com/apohllo/cycr
64
65
  licenses: []
@@ -1,204 +0,0 @@
1
- ;(csetq *PATH* "/home/fox/src/nlp/wsd/cyc/~A")
2
- (csetq *PATH* "/mnt/cyc/export/~A")
3
- ;(csetq *WORDS-PATH* (format nil *PATH* "m_100_en_hasla.txt"))
4
- (csetq *WORDS-PATH* (format nil *PATH* "all_english.txt"))
5
- (csetq *WORDS-FILE* "")
6
- (csetq *WORDS-OUTPUT* "")
7
- (csetq *WORDS-OUTPUT-PROP* "")
8
- (csetq *WORDS-MISSING* "")
9
-
10
- (define load-code () (load (format nil *PATH* "words_reader.lisp")))
11
- (define next-word ()
12
- (clet (
13
- (word (read *WORDS-FILE* nil))
14
- )
15
- (pif (null word) (ret '(("EOF" :eof))) ())
16
- (clet (
17
- (denotations (denotation-mapper (format nil "~A" word)))
18
- (correct-denots ())
19
- )
20
- (pif (consp denotations)
21
- ()
22
- (princ (format nil "~A~%" word) *WORDS-MISSING*)
23
- )
24
- ; (csetq *PROP-WORD* word)
25
- (cdolist (denot denotations)
26
- (pif (denot-word-p denot word) (cpush denot correct-denots) nil)
27
- )
28
- ; (csetq denotations (mremove-if #'prop-word-p denotations))
29
- (ret (reverse correct-denots))
30
- )
31
- )
32
- )
33
-
34
- (define symbol-str (symbol)
35
- (ret (cdr (caar
36
- (cyc-query `(#$prettyString-Canonical ,symbol ?w) #$EnglishMt)
37
- )))
38
- )
39
-
40
- ; same as above but prettyString (without canonical) is used,
41
- ; so it can return many results
42
- (define symbol-strs (symbol)
43
- (clet ((result ()))
44
- (cdolist (el (cyc-query `(#$prettyString ,symbol ?w) #$EnglishMt))
45
- (cpush (cdar el) result))
46
- (ret result))
47
- )
48
-
49
- (define print-names (symbols output)
50
- (cdolist (el symbols)
51
- (princ (format nil "~A" el) output)
52
- (princ (format nil " ~S"
53
- (strip-s (symbol-str el) "type of "))
54
- output)
55
- ; (terpri output)
56
- )
57
- )
58
- (define min-genls-flat (concept stop-words)
59
- ;(ret (remove-invalid (min-genls concept #$EverythingPSC) stop-words))
60
- ;CycNounLearnerMt UniversalVocabularyMt
61
- (ret (remove-invalid (min-genls concept #$CycNounLearnerMt) stop-words))
62
- )
63
- (define min-isa-flat (concept stop-words)
64
- ;(ret (remove-invalid (min-isa concept #$EverythingPSC) stop-words))
65
- (ret (remove-invalid (min-isa concept #$CycNounLearnerMt) stop-words))
66
- )
67
-
68
- (define read-all ()
69
- (clet (
70
- (stop-words (read-stop))
71
- (output nil)
72
- )
73
- (cdo ((words (next-word) (next-word)))
74
- ((equal words '(("EOF" :eof))))
75
- (cdolist (word words)
76
- (pif (consp word)
77
- (progn
78
- (pif (isa? (cdr word) #$Individual)
79
- (csetq output *WORDS-OUTPUT-PROP*)
80
- (csetq output *WORDS-OUTPUT*))
81
- (princ (format nil "~A[~A]"
82
- (car word)
83
- (cdr word)
84
- )
85
- output)
86
- (print-names (min-genls-flat (cdr word) stop-words) output)
87
- (princ " ISA" output)
88
- (print-names (min-isa-flat (cdr word) stop-words) output)
89
- (terpri output)
90
- )
91
- ()
92
- )
93
- )
94
- )
95
- )
96
- )
97
-
98
- ; my implementation of the mapcar function
99
- (defmacro mmapcar (fun elems)
100
- (clet ((var (gensym)))
101
- (ret `(clet ((result nil))
102
- (cdolist (,var ,elems)
103
- (cpush (funcall ,fun ,var ) result) )
104
- (reverse result))
105
- )
106
- )
107
- )
108
-
109
- ; removes elements from list if the fun returns nil
110
- (define mremove-if (fun elems)
111
- (remove-if #'null (mmapcar fun elems))
112
- )
113
-
114
- ;T if denotation's word equals word
115
- (define denot-word-p (denot word)
116
- (fif (equal (car denot) word) denot nil))
117
-
118
- ;T if the car of the cons is equal to word
119
- (define prop-word-p (el word)
120
- (fif (equal (car (eval el)) word) (eval el) nil))
121
-
122
-
123
- (define open-words ()
124
- (csetq *WORDS-FILE* (open-text *WORDS-PATH* :input))
125
- )
126
-
127
- (define open-missing ()
128
- (csetq *WORDS-MISSING* (open-text (format nil *PATH* "missing.txt") :output))
129
- )
130
-
131
- (define close-words ()
132
- (close *WORDS-FILE*))
133
-
134
-
135
- (define open-output (version)
136
- (csetq *WORDS-OUTPUT*
137
- (open-text (format nil *PATH* (format nil "pohl_cyc_~A.txt" version)) :output))
138
- (csetq *WORDS-OUTPUT-PROP*
139
- (open-text (format nil *PATH* (format nil "pohl_cyc_prop_~A.txt" version)) :output))
140
- )
141
-
142
- ;close output file
143
- (define close-output ()
144
- (close *WORDS-OUTPUT*)
145
- (close *WORDS-OUTPUT-PROP*)
146
- )
147
-
148
- ;returns the stop-list
149
- (define read-stop ()
150
- (clet ((stop-file (open-text (format nil *PATH* "stop_list.txt") :input))
151
- (stop-words (read stop-file))
152
- )
153
- (close stop-file)
154
- (ret stop-words)
155
- )
156
- )
157
-
158
- ; removes sequence #removed from the beginning of the sequence #sequence
159
- (define strip-s (sequence removed)
160
- (ret(fif (eq 0 (search removed sequence))
161
- (subseq sequence (length removed))
162
- sequence))
163
- )
164
-
165
- ;main transforming loop
166
- (define main-prog (version)
167
- (open-words)
168
- (open-output version)
169
- (open-missing)
170
- (read-all)
171
- (close-words)
172
- (close-output)
173
- (close *WORDS-MISSING*)
174
- )
175
-
176
- (define remove-invalid (elements invalid)
177
- (clet ( (result () ) )
178
- (cdolist (el elements)
179
- (pif (null (cor (member el invalid)
180
- (cand (nart-p el)
181
- (intersection invalid (nart-hl-formula el)) )))
182
- (cpush el result) ())
183
- )
184
- (ret result)
185
- )
186
- )
187
-
188
- (define term-mts (term)
189
- (clet ((result ()))
190
- (cdolist (e (gather-index-in-any-mt term))
191
- (csetq result (adjoin (assertion-mt e) result)))
192
- result)
193
- )
194
-
195
- (define any-assertion? (term mt)
196
- (with-mt mt (pif (gather-index term) T ())))
197
-
198
- (define nart-denotation-mapper (word)
199
- (clet ((result ()))
200
- (cdolist (el (denotation-mapper word))
201
- (pif (nart-p (cdr el))
202
- (cpush (nart-id (cdr el)) result)
203
- (cpush (cdr el) result))) result
204
- (ret result)))