Class: Wongi::Engine::WME

Inherits:
Struct
  • Object
show all
Defined in:
lib/wongi-engine/wme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, p, o, r = nil) ⇒ WME

Returns a new instance of WME.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wongi-engine/wme.rb', line 10

def initialize s, p, o, r = nil

  @alphas = []
  @tokens = []
  @generating_tokens = []
  @neg_join_results = []
  @opt_join_results = []

  @rete = r

  if r
    super( r.import(s), r.import(p), r.import(o) )
  else
    super( s, p, o )
  end

end

Instance Attribute Details

#alphasObject (readonly)

Returns the value of attribute alphas.



7
8
9
# File 'lib/wongi-engine/wme.rb', line 7

def alphas
  @alphas
end

#generating_tokensObject (readonly)

Returns the value of attribute generating_tokens.



7
8
9
# File 'lib/wongi-engine/wme.rb', line 7

def generating_tokens
  @generating_tokens
end

#neg_join_resultsObject (readonly)

Returns the value of attribute neg_join_results.



8
9
10
# File 'lib/wongi-engine/wme.rb', line 8

def neg_join_results
  @neg_join_results
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



3
4
5
# File 'lib/wongi-engine/wme.rb', line 3

def object
  @object
end

#opt_join_resultsObject (readonly)

Returns the value of attribute opt_join_results.



8
9
10
# File 'lib/wongi-engine/wme.rb', line 8

def opt_join_results
  @opt_join_results
end

#predicateObject

Returns the value of attribute predicate

Returns:

  • (Object)

    the current value of predicate



3
4
5
# File 'lib/wongi-engine/wme.rb', line 3

def predicate
  @predicate
end

#reteObject (readonly)

Returns the value of attribute rete.



5
6
7
# File 'lib/wongi-engine/wme.rb', line 5

def rete
  @rete
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



3
4
5
# File 'lib/wongi-engine/wme.rb', line 3

def subject
  @subject
end

#tokensObject (readonly)

Returns the value of attribute tokens.



7
8
9
# File 'lib/wongi-engine/wme.rb', line 7

def tokens
  @tokens
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/wongi-engine/wme.rb', line 36

def == other
  subject == other.subject && predicate == other.predicate && object == other.object
end

#=~(template) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/wongi-engine/wme.rb', line 40

def =~ template
  raise "Cannot match a WME against a #{template.class}" unless Template === template
  result = match_member( template, :subject ) & match_member( template, :predicate ) & match_member( template, :object )
  if result.match?
    result
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wongi-engine/wme.rb', line 56

def destroy

  alphas.each { |alpha| alpha.remove self }.clear
  while tokens.first
    tokens.first.delete self    # => will remove itself from the array
  end

  destroy_neg_join_results
  destroy_opt_join_results

end

#dupObject



32
33
34
# File 'lib/wongi-engine/wme.rb', line 32

def dup
  self.class.new subject, predicate, object, rete
end

#generated?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/wongi-engine/wme.rb', line 52

def generated?
  !manual?
end

#hashObject



76
77
78
# File 'lib/wongi-engine/wme.rb', line 76

def hash
  @hash ||= array_form.map( &:hash ).hash
end

#import_into(r) ⇒ Object



28
29
30
# File 'lib/wongi-engine/wme.rb', line 28

def import_into r
  self.class.new subject, predicate, object, r
end

#inspectObject



68
69
70
# File 'lib/wongi-engine/wme.rb', line 68

def inspect
  "<WME #{subject.inspect} #{predicate.inspect} #{object.inspect}>"
end

#manual?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/wongi-engine/wme.rb', line 48

def manual?
  generating_tokens.empty?
end

#to_sObject



72
73
74
# File 'lib/wongi-engine/wme.rb', line 72

def to_s
  inspect
end