Class DS::KnowledgeBase
In: AS.dat.rb
Parent: Object

Class KnowledgeBase contains elements of type Rule.

Methods

<<   inspect   new   query  

Attributes

rules  [RW] 

Public Class methods

This method is used by the parser. Rules are stored in a hash that maps logical functor names (representing rule tags) to a hash that maps natural numbers &ge; 1 (representing antecedent length) to rules.

E.g.,:

   @rules = [ "neg_p" => [ 0=>[ ~p(X), ~p(1, Y),.. ], 1=>[ ~p(U)<-a(U), ..

[Source]

    # File AS.dat.rb, line 20
20:    def initialize
21:       @rules = Hash.new { |h1,k1|
22:          h1[k1] = Hash.new{ |h2, k2| h2[k2] = [] }
23:       }
24:       $kb = self # FIXME good for now, but remove once ..
25:    end

Public Instance methods

Add a Rule r to this KnowledgeBase. Method used by parser.

[Source]

    # File AS.dat.rb, line 28
28:    def <<(r)
29:       con, ant = r.consequent, r.antecedent
30:       n = r.antecedent.length
31:       @rules[con.rule_tag][n] << r
32: ??
33:    end

Return dump of KnowledgeBase as ASCII string.

[Source]

    # File AS.dat.rb, line 57
57:    def inspect
58:       @rules.keys.sort.collect { |id|
59:          "=== Regels voor #{id}: =========\n" +
60:          @rules[id].collect { |rule|
61:             rule.inspect }.join("\n")
62:       }.join("\n\n")
63:    end

Cycle through all queries.

[Source]

    # File AS.dat.rb, line 48
48:    def query
49:       @rules['root'].each { |arity, rules|
50:          rules.each { |query|
51:             yield query
52:          }
53:       }
54:    end

[Validate]