cycr 0.0.4 → 0.0.5
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/cycr.gemspec +2 -2
- data/lib/cycr/builder.rb +2 -2
- data/lib/cycr/client.rb +1 -1
- data/lib/cycr/extensions.rb +17 -5
- data/lib/cycr/parser.rb +2 -0
- data/lib/cycr/sexpr.rex +3 -1
- data/lib/cycr/sexpr.rex.rb +4 -1
- metadata +4 -4
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.
|
4
|
-
s.date = "2010-
|
3
|
+
s.version = "0.0.5"
|
4
|
+
s.date = "2010-11-23"
|
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"
|
data/lib/cycr/builder.rb
CHANGED
@@ -23,9 +23,9 @@ module Cyc
|
|
23
23
|
|
24
24
|
def method_missing(name,*args,&block)
|
25
25
|
@query << "(" << name.to_s.gsub("_","-") << " "
|
26
|
-
@query << args.map{|a| a.to_cyc}.join(" ")
|
26
|
+
@query << (args||[]).map{|a| a.to_cyc}.join(" ")
|
27
27
|
if block
|
28
|
-
|
28
|
+
block.call(self)
|
29
29
|
end
|
30
30
|
@query << ")"
|
31
31
|
end
|
data/lib/cycr/client.rb
CHANGED
@@ -121,7 +121,7 @@ module Cyc
|
|
121
121
|
while current_result.size == 100 do
|
122
122
|
send_message("(subseq #{last_message} #{result.size} " +
|
123
123
|
"#{result.size + 100})")
|
124
|
-
current_result = receive_answer(options)
|
124
|
+
current_result = receive_answer(options) || []
|
125
125
|
result.concat(current_result)
|
126
126
|
end
|
127
127
|
result
|
data/lib/cycr/extensions.rb
CHANGED
@@ -1,24 +1,36 @@
|
|
1
1
|
class String
|
2
|
-
def to_cyc
|
2
|
+
def to_cyc(raw=false)
|
3
3
|
"\"#{self}\""
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
7
|
class Symbol
|
8
|
-
def to_cyc
|
8
|
+
def to_cyc(raw=false)
|
9
9
|
"#\$#{self}"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
class Array
|
14
|
-
def to_cyc
|
15
|
-
"'("+map{|e| e.to_cyc}.join(" ")+")"
|
14
|
+
def to_cyc(raw=false)
|
15
|
+
contents = "'("+map{|e| e.to_cyc(raw)}.join(" ")+")"
|
16
|
+
if raw
|
17
|
+
contents
|
18
|
+
else
|
19
|
+
"(el-find-if-nart #{contents})"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
24
|
class Fixnum
|
20
|
-
def to_cyc
|
25
|
+
def to_cyc(raw=false)
|
21
26
|
to_s
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
30
|
+
module Cyc
|
31
|
+
class LiteralString < String
|
32
|
+
def to_cyc(raw=false)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cycr/parser.rb
CHANGED
data/lib/cycr/sexpr.rex
CHANGED
@@ -7,7 +7,7 @@ macro
|
|
7
7
|
LINE_TERMINATOR \r|\n|\r\n
|
8
8
|
INPUT_CHARACTER [^\r\n\"\(\):& ]
|
9
9
|
WHITE_SPACE [\ \t\f\r\n] | \r\n
|
10
|
-
SYMBOL :[^<>\r\n\"\(\)
|
10
|
+
SYMBOL :[^<>\r\n\"\(\):&\#\ ]+
|
11
11
|
CYC_SYMBOL \#\$[a-zA-Z0-9:_-]+
|
12
12
|
ATOM [^\r\n\"\(\):&\ ]+
|
13
13
|
OPEN_PAR \(
|
@@ -17,6 +17,7 @@ macro
|
|
17
17
|
OPEN_LIST_QUOTE \#<
|
18
18
|
CLOSE_LIST_QUOTE >
|
19
19
|
DOT \.
|
20
|
+
ASSERTION_SEP :
|
20
21
|
|
21
22
|
|
22
23
|
rule
|
@@ -35,6 +36,7 @@ rule
|
|
35
36
|
{ATOM} { [:atom,text] }
|
36
37
|
# literals
|
37
38
|
{QUOTE} { state = :STRING; @str = ""; [:in_string] }
|
39
|
+
{ASSERTION_SEP} { [:assertion_sep]}
|
38
40
|
# whitespace
|
39
41
|
{WHITE_SPACE} # ignore
|
40
42
|
:STRING [^\n\r\"\\]+ { @str << text; [:in_string]}
|
data/lib/cycr/sexpr.rex.rb
CHANGED
@@ -73,7 +73,7 @@ class SExpressionLexer
|
|
73
73
|
when (text = ss.scan(/NIL/))
|
74
74
|
@rex_tokens.push action { [:nil,text] }
|
75
75
|
|
76
|
-
when (text = ss.scan(/:[^<>\r\n\"\(\)
|
76
|
+
when (text = ss.scan(/:[^<>\r\n\"\(\):&\#\ ]+/))
|
77
77
|
@rex_tokens.push action { [:symbol,text] }
|
78
78
|
|
79
79
|
when (text = ss.scan(/\#\$[a-zA-Z0-9:_-]+/))
|
@@ -85,6 +85,9 @@ class SExpressionLexer
|
|
85
85
|
when (text = ss.scan(/\"/))
|
86
86
|
@rex_tokens.push action { state = :STRING; @str = ""; [:in_string] }
|
87
87
|
|
88
|
+
when (text = ss.scan(/:/))
|
89
|
+
@rex_tokens.push action { [:assertion_sep]}
|
90
|
+
|
88
91
|
when (text = ss.scan(/[\ \t\f\r\n]/))
|
89
92
|
;
|
90
93
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cycr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aleksander Pohl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-23 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|