rbprolog 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/lib/rbprolog/deduction.rb +2 -2
- data/lib/rbprolog/evaluation.rb +6 -5
- data/lib/rbprolog/rule.rb +3 -3
- data/lib/rbprolog/version.rb +1 -1
- data/test/test_evaluation.rb +15 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cea2edb5bbebc322e8b452964550d648524fc3c
|
4
|
+
data.tar.gz: a6fb9cea02cf48e00265a7a7b3f5f38e75e6f47d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d04a142120d61f6c8f2e367182c1f4359be3a50390b6529a77fdca925d41bb020824920fc1ad3b6706866c1206d107437538f7cafd218a71485984c37b44ac1
|
7
|
+
data.tar.gz: 25170cd1e81e96b96847ea6cc3f00df6efe040c9c98d1fba757ba8447b32d95c94314aaf0b4b797843fe1ff599d455da1be4628adb807ae4ff99fd4fd99c06c8
|
data/lib/rbprolog/deduction.rb
CHANGED
@@ -8,11 +8,11 @@ module Rbprolog
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def each_deduce(context, rules, id)
|
11
|
-
print "#{"\t" * id.size}#{id.join('.')} #{@sym}?(#{@args.join(', ')})"
|
11
|
+
#print "#{"\t" * id.size}#{id.join('.')} #{@sym}?(#{@args.join(', ')})"
|
12
12
|
|
13
13
|
rules.select {|rule| rule.sym == @sym}.each_with_index do |rule, rule_index|
|
14
14
|
context.scope(self) do |scoped_args|
|
15
|
-
puts " => #{@sym}?(#{scoped_args.join(', ')})" if rule_index == 0
|
15
|
+
#puts " => #{@sym}?(#{scoped_args.join(', ')})" if rule_index == 0
|
16
16
|
|
17
17
|
# rules.reject is to avoid endless loop caused by self reference
|
18
18
|
rule.each_match(rules.reject {|item| item == rule}, *scoped_args, id + [rule_index]) do |hash|
|
data/lib/rbprolog/evaluation.rb
CHANGED
@@ -9,17 +9,18 @@ module Rbprolog
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def each_deduce(context, rules, id)
|
12
|
-
print "#{"\t" * id.size}#{id.join('.')}
|
12
|
+
#print "#{"\t" * id.size}#{id.join('.')} #{@expression}?)"
|
13
13
|
|
14
14
|
context.scope(self) do |scoped_args|
|
15
|
-
puts " => ?(#{scoped_args.join(', ')})"
|
16
|
-
|
17
15
|
kclass = Class.new
|
18
16
|
kclass.send(:define_singleton_method, :const_missing) do |sym|
|
19
|
-
context.deduce(sym)
|
17
|
+
context.deduce(Var.new(sym))
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
evaluation = kclass.class_eval(@expression)
|
21
|
+
#puts " => #{evaluation}"
|
22
|
+
|
23
|
+
yield context.binds if evaluation
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/rbprolog/rule.rb
CHANGED
@@ -10,17 +10,17 @@ module Rbprolog
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def each_match(rules, *args, id)
|
13
|
-
print "#{"\t" * id.size}#{id.join('.')} #{@sym}(#{@args.join(', ')}).deduce(#{args.join(', ')})"
|
13
|
+
#print "#{"\t" * id.size}#{id.join('.')} #{@sym}(#{@args.join(', ')}).deduce(#{args.join(', ')})"
|
14
14
|
|
15
15
|
context = Context.new
|
16
16
|
context.scope(self) do |scoped_args|
|
17
17
|
if self.match!(context, args)
|
18
|
-
puts " => #{@sym}(#{@args.map {|arg| context.deduce(arg)}.join(', ')})"
|
18
|
+
#puts " => #{@sym}(#{@args.map {|arg| context.deduce(arg)}.join(', ')})"
|
19
19
|
deduce_deductions(context, rules, *@deductions, id) do
|
20
20
|
yield context.binds
|
21
21
|
end
|
22
22
|
else
|
23
|
-
print "\n"
|
23
|
+
#print "\n"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/rbprolog/version.rb
CHANGED
data/test/test_evaluation.rb
CHANGED
@@ -9,8 +9,16 @@ class EvaluationLogic
|
|
9
9
|
|
10
10
|
%w(a b c).each {|t| must 'win', t}
|
11
11
|
must_not 'linux', 'd'
|
12
|
-
|
13
|
-
|
12
|
+
must 'win', 'xp', 'e'
|
13
|
+
|
14
|
+
can_not TC, :if => must_not?(TC)
|
15
|
+
|
16
|
+
can_not X, TC, :if => [must?(U, TC), ->{'U != X'}]
|
17
|
+
can_not X, TC, :if => must_not?(X, TC)
|
18
|
+
|
19
|
+
can_not X, Y, TC, :if => [must?(U, V, TC), ->{'U != X || V != Y'}]
|
20
|
+
can_not X, TC, :if => must_not?(X, Y, TC)
|
21
|
+
|
14
22
|
#can X, Y, :if => !can_not?(X, Y)
|
15
23
|
end
|
16
24
|
|
@@ -25,5 +33,10 @@ class TestEvaluation < Test::Unit::TestCase
|
|
25
33
|
assert_equal true, l.can_not?('linux', 'c')
|
26
34
|
|
27
35
|
assert_equal(['a', 'b', 'c', 'd'], l.can_not!('linux', Rbprolog::Var.new(:G)).map {|hash| hash[:G]}.uniq.sort)
|
36
|
+
assert_equal([], l.can_not!('win', Rbprolog::Var.new(:G)).map {|hash| hash[:G]}.uniq.sort)
|
37
|
+
|
38
|
+
assert_equal true, l.must?('win', 'xp', 'e')
|
39
|
+
assert_equal([], l.can_not!('win', 'xp', Rbprolog::Var.new(:G)).map {|hash| hash[:G]}.uniq.sort)
|
40
|
+
assert_equal(['e'], l.can_not!('win', 'vista', Rbprolog::Var.new(:G)).map {|hash| hash[:G]}.uniq.sort)
|
28
41
|
end
|
29
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbprolog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruijia Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|