Class: Wongi::Engine::WME

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CoreExt

included

Constructor Details

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

Returns a new instance of WME.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wongi-engine/wme.rb', line 15

def initialize s, p, o, r = nil

  manual!

  @deleted = false
  @alphas = []
  @generating_tokens = []
  @neg_join_results = []
  @opt_join_results = []

  @rete = r

# TODO: reintroduce Network#import when bringing back RDF support
  super( s, p, o )

end

Instance Attribute Details

#generating_tokensObject (readonly)

Returns the value of attribute generating_tokens.



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

def generating_tokens
  @generating_tokens
end

#neg_join_resultsObject (readonly)

Returns the value of attribute neg_join_results.



10
11
12
# File 'lib/wongi-engine/wme.rb', line 10

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.



10
11
12
# File 'lib/wongi-engine/wme.rb', line 10

def opt_join_results
  @opt_join_results
end

#overlayObject

Returns the value of attribute overlay.



11
12
13
# File 'lib/wongi-engine/wme.rb', line 11

def overlay
  @overlay
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.



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

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

Instance Method Details

#==(other) ⇒ Object



46
47
48
# File 'lib/wongi-engine/wme.rb', line 46

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

#=~(template) ⇒ Object



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

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

#dupObject



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

def dup
  self.class.new( subject, predicate, object, rete ).tap do |wme|
    wme.overlay = overlay
    wme.manual = self.manual?
  end
end

#generated?Boolean

Returns:

  • (Boolean)


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

def generated?
  !generating_tokens.empty?
end

#hashObject



70
71
72
# File 'lib/wongi-engine/wme.rb', line 70

def hash
  @hash ||= [subject.hash, predicate.hash, object.hash].hash
end

#import_into(r) ⇒ Object



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

def import_into r
  self.class.new( subject, predicate, object, r ).tap do |wme|
    wme.overlay = overlay
    wme.manual = self.manual?
  end
end

#inspectObject



62
63
64
# File 'lib/wongi-engine/wme.rb', line 62

def inspect
  "{#{subject.inspect} #{predicate.inspect} #{object.inspect}}"
end

#to_sObject



66
67
68
# File 'lib/wongi-engine/wme.rb', line 66

def to_s
  inspect
end