catlogic 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/catlogic/distribution.rb +14 -12
- data/lib/catlogic/figure.rb +37 -34
- data/lib/catlogic/form.rb +94 -93
- data/lib/catlogic/integer.rb +5 -0
- data/lib/catlogic/mood.rb +24 -12
- data/lib/catlogic/premise_collection.rb +92 -29
- data/lib/catlogic/premise_pair.rb +52 -50
- data/lib/catlogic/proposition.rb +145 -143
- data/lib/catlogic/proposition_type.rb +44 -40
- data/lib/catlogic/quality.rb +17 -11
- data/lib/catlogic/quantity.rb +16 -11
- data/lib/catlogic/string.rb +20 -0
- data/lib/catlogic/syllogism.rb +129 -133
- data/lib/catlogic/term.rb +29 -25
- data/lib/catlogic/version.rb +1 -1
- data/lib/catlogic.rb +3 -3
- data/scripts/displayInferredTruths.rb +59 -237
- data/scripts/getAllValidPropositions.rb +2 -2
- data/scripts/testCombineSets.rb +16 -16
- data/scripts/testIfUnique.rb +4 -4
- data/scripts/testPremisePair.rb +3 -3
- data/scripts/testProposition.rb +1 -1
- data/scripts/testPropositionType.rb +1 -1
- data/scripts/testQuantity.rb +1 -1
- data/scripts/testReduceToUniqueSet.rb +6 -6
- data/scripts/testSyllogism.rb +5 -5
- data/scripts/testSyllogismForm.rb +3 -3
- data/spec/distribution_spec.rb +3 -3
- data/spec/figure_spec.rb +1 -1
- data/spec/form_spec.rb +3 -3
- data/spec/mood_spec.rb +1 -1
- data/spec/premise_collection_spec.rb +72 -13
- data/spec/premise_pair_spec.rb +14 -9
- data/spec/proposition_spec.rb +24 -24
- data/spec/proposition_type_spec.rb +4 -4
- data/spec/quality_spec.rb +2 -2
- data/spec/quantity_spec.rb +2 -2
- data/spec/syllogism_spec.rb +13 -13
- data/spec/term_spec.rb +6 -6
- metadata +4 -2
data/lib/catlogic/proposition.rb
CHANGED
@@ -1,189 +1,191 @@
|
|
1
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Proposition
|
2
3
|
|
3
|
-
|
4
|
+
attr_reader :quantity, :subject, :quality, :predicate, :truthvalue
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
27
|
+
def contradictory
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
quantity = @quantity.opposite
|
30
|
+
quality = @quality.opposite
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
@contradictory = Proposition.new(quantity, @subject, quality, @predicate, !@truthvalue)
|
33
|
+
return @contradictory
|
34
|
+
end
|
34
35
|
|
35
|
-
|
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
|
-
|
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 =
|
65
|
+
truthvalue = !@truthvalue
|
42
66
|
elsif !@truthvalue
|
43
67
|
truthvalue = "unknown"
|
44
68
|
end
|
45
|
-
|
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
|
-
|
54
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
end
|
100
|
+
def obverse
|
101
|
+
quality = @quality.opposite
|
72
102
|
|
73
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
1
|
+
module Catlogic
|
2
|
+
class PropositionType
|
2
3
|
|
3
|
-
|
4
|
+
attr_reader :label, :truthvalue
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
quality
|
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
|
+
|
data/lib/catlogic/quality.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Quality
|
3
|
+
attr_reader :label
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
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
|
data/lib/catlogic/quantity.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Quantity
|
3
|
+
attr_reader :label
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(quantity)
|
6
|
+
@label = quantity
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|