Class: Wongi::Engine::Template
- Inherits:
-
Struct
- Object
- Struct
- Wongi::Engine::Template
show all
- Includes:
- CoreExt
- Defined in:
- lib/wongi-engine/template.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from CoreExt
included
Constructor Details
#initialize(s = :_, p = :_, o = :_, time = 0) ⇒ Template
Returns a new instance of Template.
14
15
16
17
18
19
|
# File 'lib/wongi-engine/template.rb', line 14
def initialize s = :_, p = :_, o = :_, time = 0
raise "Cannot work with continuous time" unless time.integer?
raise "Cannot look into the future" if time > 0
super
@filters = []
end
|
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
7
8
9
|
# File 'lib/wongi-engine/template.rb', line 7
def filters
@filters
end
|
#object ⇒ Object
Returns the value of attribute object
3
4
5
|
# File 'lib/wongi-engine/template.rb', line 3
def object
@object
end
|
#predicate ⇒ Object
Returns the value of attribute predicate
3
4
5
|
# File 'lib/wongi-engine/template.rb', line 3
def predicate
@predicate
end
|
#subject ⇒ Object
Returns the value of attribute subject
3
4
5
|
# File 'lib/wongi-engine/template.rb', line 3
def subject
@subject
end
|
#time ⇒ Object
Returns the value of attribute time
3
4
5
|
# File 'lib/wongi-engine/template.rb', line 3
def time
@time
end
|
Class Method Details
.hash_for(*args) ⇒ Object
39
40
41
|
# File 'lib/wongi-engine/template.rb', line 39
def self.hash_for *args
args.map( &:hash ).hash
end
|
.variable?(thing) ⇒ Boolean
10
11
12
|
# File 'lib/wongi-engine/template.rb', line 10
def self.variable? thing
Symbol === thing && thing =~ /^[A-Z]/
end
|
Instance Method Details
#==(other) ⇒ Object
47
48
49
50
|
# File 'lib/wongi-engine/template.rb', line 47
def == other
return false unless Template === other
subject == other.subject && predicate == other.predicate && object == other.object
end
|
#===(wme) ⇒ Object
43
44
45
|
# File 'lib/wongi-engine/template.rb', line 43
def === wme
wme =~ self if WME === wme
end
|
#=~(template) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/wongi-engine/template.rb', line 52
def =~ template
case template
when Template
( template.subject == :_ || template.subject == subject ) &&
( template.predicate == :_ || template.predicate == predicate ) &&
( template.object == :_ || template.object == object )
else
raise "Templates can only match templates"
end
end
|
#compile(context) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/wongi-engine/template.rb', line 64
def compile context
tests, assignment = *JoinNode.compile( self, context.earlier, context.parameters )
alpha = context.rete.compile_alpha( self )
context.node = context.node.beta_memory.join_node( alpha, tests, assignment, @filters, context.alpha_deaf )
context.earlier << self
context
end
|
#contains?(var) ⇒ Boolean
31
32
33
|
# File 'lib/wongi-engine/template.rb', line 31
def contains? var
self.class.variable?( var ) && array_form.include?( var )
end
|
#hash ⇒ Object
35
36
37
|
# File 'lib/wongi-engine/template.rb', line 35
def hash
@hash ||= array_form.map( &:hash ).hash
end
|
#import_into(r) ⇒ Object
21
22
23
24
25
|
# File 'lib/wongi-engine/template.rb', line 21
def import_into r
copy = self.class.new r.import( subject ), r.import( predicate ), r.import( object ), time
@filters.each { |f| copy.filters << f }
copy
end
|
#inspect ⇒ Object
72
73
74
|
# File 'lib/wongi-engine/template.rb', line 72
def inspect
"<~ #{subject.inspect} #{predicate.inspect} #{object.inspect} #{time}>"
end
|
#root? ⇒ Boolean
27
28
29
|
# File 'lib/wongi-engine/template.rb', line 27
def root?
subject == :_ && predicate == :_ && object == :_
end
|
#to_s ⇒ Object
76
77
78
|
# File 'lib/wongi-engine/template.rb', line 76
def to_s
inspect
end
|