catlogic 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/catlogic/distribution.rb +14 -12
  4. data/lib/catlogic/figure.rb +37 -34
  5. data/lib/catlogic/form.rb +94 -93
  6. data/lib/catlogic/integer.rb +5 -0
  7. data/lib/catlogic/mood.rb +24 -12
  8. data/lib/catlogic/premise_collection.rb +92 -29
  9. data/lib/catlogic/premise_pair.rb +52 -50
  10. data/lib/catlogic/proposition.rb +145 -143
  11. data/lib/catlogic/proposition_type.rb +44 -40
  12. data/lib/catlogic/quality.rb +17 -11
  13. data/lib/catlogic/quantity.rb +16 -11
  14. data/lib/catlogic/string.rb +20 -0
  15. data/lib/catlogic/syllogism.rb +129 -133
  16. data/lib/catlogic/term.rb +29 -25
  17. data/lib/catlogic/version.rb +1 -1
  18. data/lib/catlogic.rb +3 -3
  19. data/scripts/displayInferredTruths.rb +59 -237
  20. data/scripts/getAllValidPropositions.rb +2 -2
  21. data/scripts/testCombineSets.rb +16 -16
  22. data/scripts/testIfUnique.rb +4 -4
  23. data/scripts/testPremisePair.rb +3 -3
  24. data/scripts/testProposition.rb +1 -1
  25. data/scripts/testPropositionType.rb +1 -1
  26. data/scripts/testQuantity.rb +1 -1
  27. data/scripts/testReduceToUniqueSet.rb +6 -6
  28. data/scripts/testSyllogism.rb +5 -5
  29. data/scripts/testSyllogismForm.rb +3 -3
  30. data/spec/distribution_spec.rb +3 -3
  31. data/spec/figure_spec.rb +1 -1
  32. data/spec/form_spec.rb +3 -3
  33. data/spec/mood_spec.rb +1 -1
  34. data/spec/premise_collection_spec.rb +72 -13
  35. data/spec/premise_pair_spec.rb +14 -9
  36. data/spec/proposition_spec.rb +24 -24
  37. data/spec/proposition_type_spec.rb +4 -4
  38. data/spec/quality_spec.rb +2 -2
  39. data/spec/quantity_spec.rb +2 -2
  40. data/spec/syllogism_spec.rb +13 -13
  41. data/spec/term_spec.rb +6 -6
  42. metadata +4 -2
@@ -1,171 +1,167 @@
1
- # Class for any syllogism object.
2
- class Syllogism
3
- attr_reader :major, :minor, :conclusion
4
-
5
- # Syllogism object initiation takes three Proposition objects
6
-
7
- def initialize(major, minor, conclusion=nil)
8
- @major = major
9
- @minor = minor
10
- if conclusion == nil
11
- @conclusion = self.getComputedConclusion
12
- else
13
- @conclusion = conclusion
1
+ module Catlogic
2
+ # Class for any syllogism object.
3
+ class Syllogism
4
+ attr_reader :major, :minor, :conclusion
5
+
6
+ # Syllogism object initiation takes three Proposition objects
7
+
8
+ def initialize(major, minor, conclusion=nil)
9
+ @major = major
10
+ @minor = minor
11
+ if conclusion == nil
12
+ @conclusion = self.getComputedConclusion
13
+ else
14
+ @conclusion = conclusion
15
+ end
14
16
  end
15
- end
16
17
 
17
- # This method gets the middle term by looking for the term in the major and minor terms that are used twice.
18
- def middle
19
- termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
20
- middle = nil
21
- if self.three_term?
22
- termarray.detect do |term|
23
- if termarray.count(term) == 2
24
- middle = Term.new(term)
18
+ # This method gets the middle term by looking for the term in the major and minor terms that are used twice.
19
+ def middle
20
+ termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
21
+ middle = nil
22
+ if self.three_term?
23
+ termarray.detect do |term|
24
+ if termarray.count(term) == 2
25
+ middle = Term.new(term)
26
+ end
25
27
  end
28
+ else
29
+ middle = "Error: this is not a three term syllogism"
26
30
  end
27
- else
28
- middle = "Error: this is not a three term syllogism"
31
+ middle
29
32
  end
30
- middle
31
- end
32
33
 
33
- def three_term?
34
- termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
35
- if termarray.uniq.size == 3
36
- answer = true
37
- else
38
- answer = false
34
+ def three_term?
35
+ termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
36
+ if termarray.uniq.size == 3
37
+ answer = true
38
+ else
39
+ answer = false
40
+ end
39
41
  end
40
- end
41
42
 
42
43
 
43
44
 
44
- # gets the major term as a String from the major premise by identifying the middle term
45
- # and then identifying the term in the premise that is not the middle
45
+ # gets the major term as a String from the major premise by identifying the middle term
46
+ # and then identifying the term in the premise that is not the middle
46
47
 
47
- def majorterm
48
- if @major.subject.label == self.middle.label
49
- majorterm = @major.predicate
50
- else
51
- majorterm = @major.subject
48
+ def majorterm
49
+ if @major.subject.label == self.middle.label
50
+ majorterm = @major.predicate
51
+ else
52
+ majorterm = @major.subject
53
+ end
54
+ majorterm
52
55
  end
53
- majorterm
54
- end
55
- def minorterm
56
- if @minor.subject.label == self.middle.label
57
- minorterm = @minor.predicate
58
- else
59
- minorterm = @minor.subject
56
+ def minorterm
57
+ if @minor.subject.label == self.middle.label
58
+ minorterm = @minor.predicate
59
+ else
60
+ minorterm = @minor.subject
61
+ end
62
+ minorterm
60
63
  end
61
- minorterm
62
- end
63
64
 
64
- # returns the Mood object of Syllogism (e.g. AAA, EEE)
65
+ # returns the Mood object of Syllogism (e.g. AAA, EEE)
65
66
 
66
- def mood
67
- mood = Mood.new(@major.type, @minor.type, @conclusion.type)
68
- return mood
69
- end
67
+ def mood
68
+ mood = Mood.new(@major.type, @minor.type, @conclusion.type)
69
+ return mood
70
+ end
70
71
 
71
- # gets the Figure of Syllogism (e.g. 1, 2, 3, 4)
72
+ # gets the Figure of Syllogism (e.g. 1, 2, 3, 4)
72
73
 
73
- def figure
74
- mjmp = @major.position_of_term(self.middle)
75
- mnmp = @minor.position_of_term(self.middle)
74
+ def figure
75
+ mjmp = @major.position_of_term(self.middle)
76
+ mnmp = @minor.position_of_term(self.middle)
76
77
 
77
- if mjmp == 'subject' && mnmp == 'predicate'
78
- figure = Figure.new(1)
79
- elsif mjmp == 'predicate' && mnmp == 'predicate'
80
- figure = Figure.new(2)
81
- elsif mjmp == 'subject' && mnmp == 'subject'
82
- figure = Figure.new(3)
83
- elsif mjmp == 'predicate' && mnmp == 'subject'
84
- figure = Figure.new(4)
78
+ if mjmp == 'subject' && mnmp == 'predicate'
79
+ figure = Figure.new(1)
80
+ elsif mjmp == 'predicate' && mnmp == 'predicate'
81
+ figure = Figure.new(2)
82
+ elsif mjmp == 'subject' && mnmp == 'subject'
83
+ figure = Figure.new(3)
84
+ elsif mjmp == 'predicate' && mnmp == 'subject'
85
+ figure = Figure.new(4)
86
+ end
87
+ return figure
85
88
  end
86
- return figure
87
- end
88
89
 
89
- # Retrieve Form object of the Syllogism (i.e. AAAI, EAI4)
90
- def form
91
- form = Form.new(self.mood, self.figure)
92
- return form
93
- end
90
+ # Retrieve Form object of the Syllogism (i.e. AAAI, EAI4)
91
+ def form
92
+ form = Form.new(self.mood, self.figure)
93
+ return form
94
+ end
94
95
 
95
- def undistributed_middle_test
96
- ## Rule Number 1 - middle distributed
97
- if @major.distribution(@major.position_of_term(self.middle)).label == 'undistributed' && @minor.distribution(@minor.position_of_term(self.middle)).label == 'undistributed'
98
- validity = false
99
- else
100
- validity = true
96
+ def undistributed_middle_test
97
+ ## Rule Number 1 - middle distributed
98
+ if @major.distribution(@major.position_of_term(self.middle)).label == 'undistributed' && @minor.distribution(@minor.position_of_term(self.middle)).label == 'undistributed'
99
+ validity = false
100
+ else
101
+ validity = true
102
+ end
103
+ return validity
101
104
  end
102
- return validity
103
- end
104
105
 
105
- def illicit_major_test
106
- ##Rule Number 2a distribution of major term
107
- if @conclusion.distribution('predicate').label == 'distributed' && @major.distribution(@major.position_of_term(self.majorterm)).label != 'distributed'
108
- validity = false
109
- else
110
- validity = true
106
+ def illicit_major_test
107
+ ##Rule Number 2a distribution of major term
108
+ if @conclusion.distribution('predicate').label == 'distributed' && @major.distribution(@major.position_of_term(self.majorterm)).label != 'distributed'
109
+ validity = false
110
+ else
111
+ validity = true
112
+ end
111
113
  end
112
- end
113
- def illicit_minor_test
114
- ##Rule Number 2b distribution of minor term - check fallacy of illicit minor
115
- if @conclusion.distribution('subject').label == 'distributed' && @minor.distribution(@minor.position_of_term(self.minorterm)).label != 'distributed'
116
- validity = false
117
- else
118
- validty = true
114
+ def illicit_minor_test
115
+ ##Rule Number 2b distribution of minor term - check fallacy of illicit minor
116
+ if @conclusion.distribution('subject').label == 'distributed' && @minor.distribution(@minor.position_of_term(self.minorterm)).label != 'distributed'
117
+ validity = false
118
+ else
119
+ validty = true
120
+ end
119
121
  end
120
- end
121
- # exclusive premises
122
- def exclusive_premises_test
123
- if @major.quality.label == 'negative' && @minor.quality.label == 'negative'
124
- validity = false
125
- else
126
- validity = true
122
+ # exclusive premises
123
+ def exclusive_premises_test
124
+ if @major.quality.label == 'negative' && @minor.quality.label == 'negative'
125
+ validity = false
126
+ else
127
+ validity = true
128
+ end
127
129
  end
128
- end
129
130
 
130
- def affirm_from_neg_test
131
- if (@major.quality.label == 'negative' || @minor.quality.label == 'negative') && @conclusion.quality.label != 'negative'
132
- validity = false
133
- else
134
- validity = true
131
+ def affirm_from_neg_test
132
+ if (@major.quality.label == 'negative' || @minor.quality.label == 'negative') && @conclusion.quality.label != 'negative'
133
+ validity = false
134
+ else
135
+ validity = true
136
+ end
135
137
  end
136
- end
137
138
 
138
- def neg_from_affirms_test
139
- if (@conclusion.quality.label == 'negative' && (@major.quality.label != 'negative' && @minor.quality.label != 'negative'))
139
+ def neg_from_affirms_test
140
+ if (@conclusion.quality.label == 'negative' && (@major.quality.label != 'negative' && @minor.quality.label != 'negative'))
140
141
 
141
- validity = false
142
- #validity = "pass"
143
- else
144
- validity = true
142
+ validity = false
143
+ #validity = "pass"
144
+ else
145
+ validity = true
146
+ end
145
147
  end
146
- end
147
148
 
148
149
 
149
- def validity
150
- if (self.undistributed_middle_test != true || self.illicit_major_test != true || self.illicit_minor_test != true || self.exclusive_premises_test != true || self.affirm_from_neg_test != true || self.neg_from_affirms_test != true)
151
- validity = false
152
- else
153
- validity = true
150
+ def validity
151
+ if (self.undistributed_middle_test != true || self.illicit_major_test != true || self.illicit_minor_test != true || self.exclusive_premises_test != true || self.affirm_from_neg_test != true || self.neg_from_affirms_test != true)
152
+ validity = false
153
+ else
154
+ validity = true
155
+ end
154
156
  end
155
- end
156
-
157
- def label
158
- return "#{@major.label}\n#{@minor.label}\n#{@conclusion.label}"
159
- end
160
-
161
157
 
158
+ def label
159
+ return "#{@major.label}\n#{@minor.label}\n#{@conclusion.label}"
160
+ end
162
161
 
163
-
164
-
165
-
166
-
167
- def displayPropositionalForm
168
- form = Form.new(self.mood, self.figure)
169
- form.displayPropositionalForm
162
+ def displayPropositionalForm
163
+ form = Form.new(self.mood, self.figure)
164
+ form.displayPropositionalForm
165
+ end
170
166
  end
171
167
  end
data/lib/catlogic/term.rb CHANGED
@@ -1,32 +1,36 @@
1
- class Term
2
- attr_reader :label
1
+ module Catlogic
2
+ class Term
3
+ attr_reader :label
3
4
 
4
- def initialize(termname)
5
- @label = termname
6
- end
5
+ def initialize(termname)
6
+ @label = termname
7
+ end
7
8
 
8
- def opposite
9
- opposite = Term.new("non-#{@label}")
10
- return opposite
11
- end
9
+ def opposite
10
+ opposite = Term.new("non-#{@label}")
11
+ return opposite
12
+ end
12
13
 
13
- def distribution_subject(quantity)
14
- if quantity.label == 'universal'
15
- @distribution = Distribution.new('distributed')
16
- elsif quantity.label == 'particular'
17
- @distribution = Distribution.new('undistributed')
18
- end
19
- return @distribution
14
+ def distribution_subject(quantity)
15
+ if quantity.label == 'universal'
16
+ @distribution = Distribution.new('distributed')
17
+ elsif quantity.label == 'particular'
18
+ @distribution = Distribution.new('undistributed')
19
+ end
20
+ return @distribution
20
21
 
21
- end
22
-
23
- def distribution_predicate(quality)
24
- if quality.label == 'affirmative'
25
- @distribution = Distribution.new('undistributed')
26
- elsif quality.label == 'negative'
27
- @distribution = Distribution.new('distributed')
28
22
  end
29
- return @distribution
30
- end
31
23
 
24
+ def distribution_predicate(quality)
25
+ if quality.label == 'affirmative'
26
+ @distribution = Distribution.new('undistributed')
27
+ elsif quality.label == 'negative'
28
+ @distribution = Distribution.new('distributed')
29
+ end
30
+ return @distribution
31
+ end
32
+ def to_term
33
+ self
34
+ end
32
35
  end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Catlogic
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/catlogic.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "catlogic/version"
2
2
 
3
- #module Catlogic
4
- # Your code goes here...
3
+ require "catlogic/string"
4
+ require "catlogic/integer"
5
5
  require "catlogic/distribution"
6
6
  require "catlogic/quality"
7
7
  require "catlogic/quantity"
@@ -14,4 +14,4 @@ require "catlogic/version"
14
14
  require "catlogic/form"
15
15
  require "catlogic/premise_pair"
16
16
  require "catlogic/premise_collection"
17
- #end
17
+