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
27
# File 'lib/wongi-engine/wme.rb', line 10

def initialize s, p, o, r = nil

  @deleted = false
  @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



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

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

#=~(template) ⇒ Object



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

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

#deleted?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/wongi-engine/wme.rb', line 57

def deleted?
  @deleted
end

#destroyObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wongi-engine/wme.rb', line 61

def destroy

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

  destroy_neg_join_results
  destroy_opt_join_results

end

#dupObject



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

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

#generated?Boolean

Returns:

  • (Boolean)


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

def generated?
  !manual?
end

#hashObject



82
83
84
# File 'lib/wongi-engine/wme.rb', line 82

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

#import_into(r) ⇒ Object



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

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

#inspectObject



74
75
76
# File 'lib/wongi-engine/wme.rb', line 74

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

#manual?Boolean

Returns:

  • (Boolean)


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

def manual?
  generating_tokens.empty?
end

#to_sObject



78
79
80
# File 'lib/wongi-engine/wme.rb', line 78

def to_s
  inspect
end