Class DS::Rule
In: AS.dat.rb
Parent: Term

Methods

Attributes

is_transp  [R] 

Public Class methods

[Source]

     # File AS.dat.rb, line 242
242:       def generate_name
243:          begin
244:             name = Constant.new( "r#{@@counter += 1}" )
245:          end while @@rules[name]
246:          name
247:       end

[Source]

     # File AS.dat.rb, line 248
248:       def indexed_as_rule?(constant)
249:          @@rules[constant] ? true : false
250:       end

[Source]

     # File AS.dat.rb, line 253
253:    def initialize(*arg)
254:       # Fact: rule(consequent, strength, antecedent)
255:       # Rule: rule(consequent, strength, antecedent, dob, name)
256:       # Transpositie geven we aan met een attribuut-variabele.
257:       consequent  = arg[0]
258:       strength    = arg[1] || 1.0
259:       antecedent  = arg[2] || TermList.new
260:       if arg.length<5
261:          super('rule', consequent, strength, antecedent)
262:       else
263:          dob           = arg[3] || 1.0
264:          name          = arg[4] || Rule.generate_name
265:          @is_transp    = arg[5] ? true : false
266:          rule          = super('rule', consequent, strength, antecedent, dob, name)
267:          # To prevent different rules with names r5, r5(X, Y), r5(a, Z), this rule
268:          # is index (hashed) with its name's functor -- not with its name
269:          @@rules[name.functor] = rule
270:       end
271:       # 0.l "#{arg.length} args:  #{self.html}"
272:    end

Public Instance methods

[Source]

     # File AS.dat.rb, line 277
277:    def antecedent;  @args.at(2);  end

Apply substitution to present rule and return a new rule.

[Source]

     # File AS.dat.rb, line 292
292:    def apply(substitution)
293:       Rule.new( *@args.apply(substitution) )
294:    end

[Source]

     # File AS.dat.rb, line 318
318:    def argument(literal, needed=0.0, party=pro, n=0)
319: 
320:       unless unifier = literal.unify(consequent) # &asymp; &equiv;
321:          n.l "#{party}: unification #{literal.html} &asymp; #{consequent.html} fails."
322:          return
323:       end
324:       instantiation = apply(unifier)
325:       n.l "#{party}: instantiated to #{instantiation.html}." unless unifier.empty?
326:       # coisa = conclusions of immediate subarguments
327:       coisa = instantiation.antecedent # .dup is not necessary (I think)
328:       coisa.unshift(instantiation.name) if instantiation.is_proper_rule?
329:       coisa.argument( needed/strength.to_f, party, n+1, self) { |subargs|
330:          # in a former life this was in the wrong order..
331:          # argsubst  = subargs.substitution.compose(unifier)
332:          argsubst = unifier.compose(subargs.substitution)
333:          support  = strength.to_f
334:          support *= subargs.collect{ |arg| arg.dos }.min unless subargs.empty?
335:          if support >= needed
336:             toprule = apply(argsubst)
337:             arg =  Argument.new( toprule, support, argsubst, subargs, party, n )
338:             needed = support if subargs.empty? # Moore's lemma (saying that
339:             # all arguments must be tried since strong arguments may be defeated
340:             # while weak arguments may surive.
341:             # arg.linenr = n.l "#{party}: found #{arg.name}: #{arg.html(n)}"
342:             yield arg
343:          end
344:       }
345: #       if args_yielded.zero?
346: #          n.l "#{party}: there are no arguments to support this #{foundrtxt}."
347: #       else
348: #          n.l "#{party}: tried #{args_yielded} argument(s) for #{foundrtxt} #{html}."
349: #       end
350:    end

[Source]

     # File AS.dat.rb, line 275
275:    def consequent;  @args.at(0);  end

[Source]

     # File AS.dat.rb, line 278
278:    def dob;         @args.at(3);  end

Return a html-representation of this rule, as a String.

[Source]

     # File AS.dat.rb, line 308
308:    def html
309:       repr = []
310:       repr << "#{name.html}:" if name
311:       repr << "#{consequent.html}"
312:       repr << "#{strength.html}" if strength < 1.0
313:       repr << "&larr; #{antecedent.html}" if is_proper_rule?
314:       repr << "#{dob.html}" if dob && dob < 1.0
315:       repr.join(' ')
316:    end

Return a human-readable representation of this rule, as a String.

[Source]

     # File AS.dat.rb, line 297
297:    def inspect
298:       repr = []
299:       repr << "#{name}:" if name
300:       repr << "#{consequent.inspect}"
301:       repr << "#{strength}" if strength < 1.0
302:       repr << "<- #{antecedent.inspect}" if is_proper_rule?
303:       repr << "#{dob}" if dob && dob < 1.0
304:       repr.join(' ')
305:    end

Rule has empty antecedent.

[Source]

     # File AS.dat.rb, line 287
287:    def is_fact?
288:       antecedent.empty?
289:    end

Rule is not a fact.

[Source]

     # File AS.dat.rb, line 282
282:    def is_proper_rule?
283:       not is_fact?
284:    end

[Source]

     # File AS.dat.rb, line 279
279:    def name;        @args.at(4);  end

[Source]

     # File AS.dat.rb, line 276
276:    def strength;    @args.at(1);  end

[Validate]