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,189 +1,191 @@
1
- class Proposition
1
+ module Catlogic
2
+ class Proposition
2
3
 
3
- attr_reader :quantity, :subject, :quality, :predicate, :truthvalue
4
+ attr_reader :quantity, :subject, :quality, :predicate, :truthvalue
4
5
 
5
- def initialize(quantity, subject, quality, predicate, truthvalue)
6
- @quantity=quantity
7
- @subject=subject
8
- @quality=quality
9
- @predicate=predicate
10
- @truthvalue=truthvalue
11
- end
6
+ def initialize(quantity, subject, quality, predicate, truthvalue)
7
+ @quantity=quantity.to_quantity
8
+ @subject=subject.to_term
9
+ @quality=quality.to_quality
10
+ @predicate=predicate.to_term
11
+ @truthvalue=truthvalue
12
+ end
12
13
 
13
- def type
14
- if @quantity.label == 'universal' && @quality.label == 'affirmative'
15
- @type=PropositionType.new("A")
16
- elsif @quantity.label == 'universal' && @quality.label == 'negative'
17
- @type=PropositionType.new("E")
18
- elsif @quantity.label == 'particular' && @quality.label == 'affirmative'
19
- @type=PropositionType.new("I")
20
- elsif @quantity.label == 'particular' && @quality.label == 'negative'
21
- @type=PropositionType.new("O")
14
+ def type
15
+ if @quantity.label == 'universal' && @quality.label == 'affirmative'
16
+ @type=PropositionType.new("A")
17
+ elsif @quantity.label == 'universal' && @quality.label == 'negative'
18
+ @type=PropositionType.new("E")
19
+ elsif @quantity.label == 'particular' && @quality.label == 'affirmative'
20
+ @type=PropositionType.new("I")
21
+ elsif @quantity.label == 'particular' && @quality.label == 'negative'
22
+ @type=PropositionType.new("O")
23
+ end
24
+ return @type
22
25
  end
23
- return @type
24
- end
25
26
 
26
- def contradictory
27
+ def contradictory
27
28
 
28
- quantity = @quantity.opposite
29
- quality = @quality.opposite
29
+ quantity = @quantity.opposite
30
+ quality = @quality.opposite
30
31
 
31
- @contradictory = Proposition.new(quantity, @subject, quality, @predicate, !@truthvalue)
32
- return @contradictory
33
- end
32
+ @contradictory = Proposition.new(quantity, @subject, quality, @predicate, !@truthvalue)
33
+ return @contradictory
34
+ end
34
35
 
35
- def subaltern
36
+ def subaltern
37
+
38
+ quantity = @quantity.opposite
39
+
40
+ if @quantity.label == "universal"
41
+ if @truthvalue
42
+ truthvalue = @truthvalue
43
+ elsif !@truthvalue
44
+ truthvalue = "unknown"
45
+ end
46
+ elsif @quantity.label == "particular"
47
+ if !@truthvalue
48
+ truthvalue = !@truthvalue
49
+ elsif @truthvalue
50
+ truthvalue = "unknown"
51
+ end
52
+ end
36
53
 
37
- quantity = @quantity.opposite
54
+ @subaltern = Proposition.new(quantity, @subject, @quality, @predicate, truthvalue)
55
+ return @subaltern
56
+ end
57
+
58
+ def contrary
59
+ if @quantity.label == "particular"
60
+ abort("There is no contrary for this type of propostion. Try subcontrary")
61
+ end
62
+ quality = @quality.opposite
38
63
 
39
- if @quantity.label == "universal"
40
64
  if @truthvalue
41
- truthvalue = @truthvalue
65
+ truthvalue = !@truthvalue
42
66
  elsif !@truthvalue
43
67
  truthvalue = "unknown"
44
68
  end
45
- elsif @quantity.label == "particular"
69
+
70
+ contrary = Proposition.new(@quantity, @subject, quality, @predicate, truthvalue)
71
+ return contrary
72
+ end
73
+
74
+ def subcontrary
75
+ if @quantity.label == "universal"
76
+ abort("There is no subcontrary for this type of propostion. Try contrary.")
77
+ end
78
+
79
+ quality = @quality.opposite
80
+
46
81
  if !@truthvalue
47
82
  truthvalue = !@truthvalue
48
83
  elsif @truthvalue
49
84
  truthvalue = "unknown"
50
85
  end
51
- end
52
86
 
53
- @subaltern = Proposition.new(quantity, @subject, @quality, @predicate, truthvalue)
54
- return @subaltern
55
- end
56
-
57
- def contrary
58
- if @quantity.label == "particular"
59
- abort("There is no contrary for this type of propostion. Try subcontrary")
87
+ subcontrary = Proposition.new(@quantity, @subject, quality, @predicate, truthvalue)
88
+ return subcontrary
60
89
  end
61
- quality = @quality.opposite
62
90
 
63
- if @truthvalue
64
- truthvalue = !@truthvalue
65
- elsif !@truthvalue
66
- truthvalue = "unknown"
91
+ def converse
92
+ if self.type.label == "A" || self.type.label == "O"
93
+ truthvalue = "unknown"
94
+ else
95
+ truthvalue = @truthvalue
96
+ end
97
+ @converse = Proposition.new(@quantity, @predicate, @quality, @subject, truthvalue)
67
98
  end
68
99
 
69
- contrary = Proposition.new(@quantity, @subject, quality, @predicate, truthvalue)
70
- return contrary
71
- end
100
+ def obverse
101
+ quality = @quality.opposite
72
102
 
73
- def subcontrary
74
- if @quantity.label == "universal"
75
- abort("There is no subcontrary for this type of propostion. Try contrary.")
103
+ predicate = @predicate.opposite
104
+ @obverse = Proposition.new(@quantity, @subject, quality, predicate, @truthvalue)
76
105
  end
77
106
 
78
- quality = @quality.opposite
79
-
80
- if !@truthvalue
81
- truthvalue = !@truthvalue
82
- elsif @truthvalue
83
- truthvalue = "unknown"
84
- end
107
+ def contrapolated
108
+ if self.type.label == "E" || self.type.label == "I"
109
+ truthvalue = "unknown"
110
+ else
111
+ truthvalue = @truthvalue
112
+ end
113
+ subject = @subject.opposite
114
+ predicate = @predicate.opposite
85
115
 
86
- subcontrary = Proposition.new(@quantity, @subject, quality, @predicate, truthvalue)
87
- return subcontrary
88
- end
116
+ @contrapolated = Proposition.new(@quantity, predicate, @quality, subject, truthvalue)
89
117
 
90
- def converse
91
- if self.type.label == "A" || self.type.label == "O"
92
- truthvalue = "unknown"
93
- else
94
- truthvalue = @truthvalue
95
118
  end
96
- @converse = Proposition.new(@quantity, @predicate, @quality, @subject, truthvalue)
97
- end
98
-
99
- def obverse
100
- quality = @quality.opposite
101
-
102
- predicate = @predicate.opposite
103
- @obverse = Proposition.new(@quantity, @subject, quality, predicate, @truthvalue)
104
- end
105
119
 
106
- def contrapolated
107
- if self.type.label == "E" || self.type.label == "I"
108
- truthvalue = "unknown"
109
- else
110
- truthvalue = @truthvalue
120
+ def position_of_term(term)
121
+ if self.subject.label == term.label
122
+ @positionofmiddle = 'subject'
123
+ elsif self.predicate.label == term.label
124
+ @positionofmiddle = 'predicate'
125
+ end
126
+ return @positionofmiddle
111
127
  end
112
- subject = @subject.opposite
113
- predicate = @predicate.opposite
114
-
115
- @contrapolated = Proposition.new(@quantity, predicate, @quality, subject, truthvalue)
116
128
 
117
- end
118
-
119
- def position_of_term(term)
120
- if self.subject.label == term.label
121
- @positionofmiddle = 'subject'
122
- elsif self.predicate.label == term.label
123
- @positionofmiddle = 'predicate'
129
+ def label
130
+ if @quantity.label == "universal"
131
+ if @quality.label == "affirmative"
132
+ display_quantity = "All"
133
+ display_quality = "are"
134
+ elsif @quality.label == "negative"
135
+ display_quantity = "No"
136
+ display_quality = "are"
137
+ end
138
+ elsif @quantity.label == "particular"
139
+ if @quality.label == "affirmative"
140
+ display_quantity = "Some"
141
+ display_quality = "are"
142
+ elsif @quality.label == "negative"
143
+ display_quantity = "Some"
144
+ display_quality = "are not"
145
+ end
146
+ end
147
+ "#{display_quantity} #{@subject.label} #{display_quality} #{@predicate.label}"
124
148
  end
125
- return @positionofmiddle
126
- end
127
149
 
128
- def label
129
- if @quantity.label == "universal"
130
- if @quality.label == "affirmative"
131
- display_quantity = "All"
132
- display_quality = "are"
133
- elsif @quality.label == "negative"
134
- display_quantity = "No"
135
- display_quality = "are"
136
- end
137
- elsif @quantity.label == "particular"
138
- if @quality.label == "affirmative"
139
- display_quantity = "Some"
140
- display_quality = "are"
141
- elsif @quality.label == "negative"
142
- display_quantity = "Some"
143
- display_quality = "are not"
150
+ def distribution(position)
151
+ if position == 'subject'
152
+ distribution = @subject.distribution_subject(@quantity)
153
+ elsif position == 'predicate'
154
+ distribution = @predicate.distribution_predicate(@quality)
144
155
  end
156
+ return distribution
145
157
  end
146
- "#{display_quantity} #{@subject.label} #{display_quality} #{@predicate.label}"
147
- end
148
158
 
149
- def distribution(position)
150
- if position == 'subject'
151
- distribution = @subject.distribution_subject(@quantity)
152
- elsif position == 'predicate'
153
- distribution = @predicate.distribution_predicate(@quality)
159
+ def same_as?(proposition)
160
+ if (proposition.quantity.label == self.quantity.label &&
161
+ proposition.subject.label == self.subject.label &&
162
+ proposition.quality.label == self.quality.label &&
163
+ proposition.predicate.label == self.predicate.label &&
164
+ proposition.truthvalue == self.truthvalue)
165
+ true
166
+ else
167
+ false
168
+ end
154
169
  end
155
- return distribution
156
- end
157
170
 
158
- def same_as?(proposition)
159
- if (proposition.quantity.label == self.quantity.label &&
160
- proposition.subject.label == self.subject.label &&
161
- proposition.quality.label == self.quality.label &&
162
- proposition.predicate.label == self.predicate.label &&
163
- proposition.truthvalue == self.truthvalue)
164
- true
165
- else
166
- false
171
+ def unique?(set)
172
+ numerofoccurences = self.number_of_occurences(set)
173
+ if numerofoccurences == 0
174
+ true
175
+ else
176
+ false
177
+ end
167
178
  end
168
- end
169
179
 
170
- def unique?(set)
171
- numerofoccurences = self.number_of_occurences(set)
172
- if numerofoccurences == 0
173
- true
174
- else
175
- false
176
- end
177
- end
178
-
179
- def number_of_occurences(set)
180
- @occurences = 0
181
- set.each do |proposition|
182
- if self.same_as?(proposition)
183
- @occurences += 1
180
+ def number_of_occurences(set)
181
+ @occurences = 0
182
+ set.each do |proposition|
183
+ if self.same_as?(proposition)
184
+ @occurences += 1
185
+ end
184
186
  end
187
+ @occurences
185
188
  end
186
- @occurences
187
189
  end
190
+ end
188
191
 
189
- end
@@ -1,47 +1,51 @@
1
- class PropositionType
1
+ module Catlogic
2
+ class PropositionType
2
3
 
3
- attr_reader :label, :truthvalue
4
+ attr_reader :label, :truthvalue
4
5
 
5
- def initialize(type, truthvalue=true)
6
- @type = type
7
- @label = type
8
- @truthvalue = truthvalue
9
- end
10
- def getType
11
- @type
12
- end
6
+ def initialize(type, truthvalue=true)
7
+ @type = type
8
+ @label = type
9
+ @truthvalue = truthvalue
10
+ end
11
+ def to_proposition_type
12
+ self
13
+ end
13
14
 
14
- def quantity
15
- if @label == "A"
16
- quantity = Quantity.new("universal")
17
- elsif @label == "E"
18
- quantity = Quantity.new("universal")
19
- elsif @label == "I"
20
- quantity = Quantity.new("particular")
21
- elsif @label == "O"
22
- quantity = Quantity.new("particular")
23
- else
24
- quantity = "not a valid type"
15
+ def quantity
16
+ if @label == "A"
17
+ quantity = Quantity.new("universal")
18
+ elsif @label == "E"
19
+ quantity = Quantity.new("universal")
20
+ elsif @label == "I"
21
+ quantity = Quantity.new("particular")
22
+ elsif @label == "O"
23
+ quantity = Quantity.new("particular")
24
+ else
25
+ quantity = "not a valid type"
26
+ end
27
+ return quantity
25
28
  end
26
- return quantity
27
- end
28
- def quality
29
- if @label == "A"
30
- quality = Quality.new("affirmative")
31
- elsif @label == "E"
32
- quality = Quality.new("negative")
33
- elsif @label == "I"
34
- quality = Quality.new("affirmative")
35
- elsif @label == "O"
36
- quality = Quality.new("negative")
37
- else
38
- quality = "not a valid type"
29
+ def quality
30
+ if @label == "A"
31
+ quality = Quality.new("affirmative")
32
+ elsif @label == "E"
33
+ quality = Quality.new("negative")
34
+ elsif @label == "I"
35
+ quality = Quality.new("affirmative")
36
+ elsif @label == "O"
37
+ quality = Quality.new("negative")
38
+ else
39
+ quality = "not a valid type"
40
+ end
41
+ return quality
42
+ end
43
+
44
+ def proposition
45
+ proposition = Proposition.new(Quantity.new(self.quantity.label), Term.new("S"), Quality.new(self.quality.label), Term.new("P"), @truthvalue)
46
+ return proposition
39
47
  end
40
- return quality
41
- end
42
48
 
43
- def proposition
44
- proposition = Proposition.new(Quantity.new(self.quantity.label), Term.new("S"), Quality.new(self.quality.label), Term.new("P"), @truthvalue)
45
- return proposition
46
49
  end
47
- end
50
+ end
51
+
@@ -1,16 +1,22 @@
1
- class Quality
2
- attr_reader :label
1
+ module Catlogic
2
+ class Quality
3
+ attr_reader :label
3
4
 
4
- def initialize(quality)
5
- @label = quality
6
- end
5
+ def initialize(quality)
6
+ @label = quality
7
+ end
8
+
9
+ def opposite
10
+ if self.label == 'negative'
11
+ qualityopposite = Quality.new('affirmative')
12
+ elsif self.label == 'affirmative'
13
+ qualityopposite = Quality.new('negative')
14
+ end
15
+ return qualityopposite
16
+ end
7
17
 
8
- def opposite
9
- if self.label == 'negative'
10
- qualityopposite = Quality.new('affirmative')
11
- elsif self.label == 'affirmative'
12
- qualityopposite = Quality.new('negative')
18
+ def to_quality
19
+ self
13
20
  end
14
- return qualityopposite
15
21
  end
16
22
  end
@@ -1,16 +1,21 @@
1
- class Quantity
2
- attr_reader :label
1
+ module Catlogic
2
+ class Quantity
3
+ attr_reader :label
3
4
 
4
- def initialize(quantity)
5
- @label = quantity
6
- end
5
+ def initialize(quantity)
6
+ @label = quantity
7
+ end
7
8
 
8
- def opposite
9
- if self.label == 'universal'
10
- quantityopposite = Quantity.new('particular')
11
- elsif self.label == 'particular'
12
- quantityopposite = Quantity.new('universal')
9
+ def opposite
10
+ if self.label == 'universal'
11
+ quantityopposite = Quantity.new('particular')
12
+ elsif self.label == 'particular'
13
+ quantityopposite = Quantity.new('universal')
14
+ end
15
+ return quantityopposite
16
+ end
17
+ def to_quantity
18
+ self
13
19
  end
14
- return quantityopposite
15
20
  end
16
21
  end
@@ -0,0 +1,20 @@
1
+ class String
2
+ def to_proposition_type
3
+ Catlogic::PropositionType.new(self)
4
+ end
5
+
6
+ def to_quantity
7
+ Catlogic::Quantity.new(self)
8
+ end
9
+ def to_quality
10
+ Catlogic::Quality.new(self)
11
+ end
12
+ def to_term
13
+ Catlogic::Term.new(self)
14
+ end
15
+
16
+ def to_mood
17
+ Catlogic::Mood.new(self[0], self[1], self[2])
18
+ end
19
+
20
+ end