class Syllogism::Statement
Constants
- ATOMIC_TYPES
- TERM_TYPES
Attributes
atoms[R]
errors[R]
Public Class Methods
[](string)
click to toggle source
# File lib/syllogism/statement.rb, line 5 def self.[](string) parse(string) end
atomize(word)
click to toggle source
# File lib/syllogism/statement.rb, line 9 def self.atomize(word) ATOMIC_TYPES.map do |type| type.new(word) end.detect { |atom| atom.match? } end
new(atoms)
click to toggle source
# File lib/syllogism/statement.rb, line 19 def initialize(atoms) @atoms = atoms @errors = [] end
parse(string)
click to toggle source
# File lib/syllogism/statement.rb, line 15 def self.parse(string) new(string.split(" ").map { |word| atomize(word) }) end
Public Instance Methods
distribute()
click to toggle source
# File lib/syllogism/statement.rb, line 24 def distribute TermDistributor.new(self).call end
formula()
click to toggle source
# File lib/syllogism/statement.rb, line 28 def formula formula_checker.formula end
general_terms()
click to toggle source
# File lib/syllogism/statement.rb, line 32 def general_terms terms.select { |term| term.instance_of?(GeneralTerm) } end
predicate()
click to toggle source
# File lib/syllogism/statement.rb, line 36 def predicate terms.last end
subject()
click to toggle source
# File lib/syllogism/statement.rb, line 40 def subject terms.first end
terms()
click to toggle source
# File lib/syllogism/statement.rb, line 44 def terms @terms ||= atoms.select { |atom| TERM_TYPES.include?(atom.class) } end
to_s()
click to toggle source
# File lib/syllogism/statement.rb, line 48 def to_s atoms.map(&:value).join(" ") end
wff?()
click to toggle source
# File lib/syllogism/statement.rb, line 52 def wff? known_atoms? && verb? && known_formula? end
Private Instance Methods
formula_checker()
click to toggle source
# File lib/syllogism/statement.rb, line 71 def formula_checker @formula_checker ||= WffChecker.new(self) end
known_atoms?()
click to toggle source
# File lib/syllogism/statement.rb, line 75 def known_atoms? unknown.none? end
known_formula?()
click to toggle source
# File lib/syllogism/statement.rb, line 79 def known_formula? formula_checker.any? end
unknown()
click to toggle source
# File lib/syllogism/statement.rb, line 83 def unknown @unknown ||= atoms.select do |atom| atom.instance_of?(Unknown) end.tap do |atoms| atoms.each { |atom| errors.push("'#{atom.value}' is an unknown atom") } end end
verb?()
click to toggle source
# File lib/syllogism/statement.rb, line 91 def verb? if atoms.any? { |atom| atom.instance_of?(Verb) } true else errors.push("'#{self}' does not contain the verb 'is' or 'are'") false end end