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/syllogism.rb
CHANGED
@@ -1,171 +1,167 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
middle = "Error: this is not a three term syllogism"
|
31
|
+
middle
|
29
32
|
end
|
30
|
-
middle
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
minorterm
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
74
|
+
def figure
|
75
|
+
mjmp = @major.position_of_term(self.middle)
|
76
|
+
mnmp = @minor.position_of_term(self.middle)
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
139
|
-
|
139
|
+
def neg_from_affirms_test
|
140
|
+
if (@conclusion.quality.label == 'negative' && (@major.quality.label != 'negative' && @minor.quality.label != 'negative'))
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
validity = false
|
143
|
+
#validity = "pass"
|
144
|
+
else
|
145
|
+
validity = true
|
146
|
+
end
|
145
147
|
end
|
146
|
-
end
|
147
148
|
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
2
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Term
|
3
|
+
attr_reader :label
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(termname)
|
6
|
+
@label = termname
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def opposite
|
10
|
+
opposite = Term.new("non-#{@label}")
|
11
|
+
return opposite
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/catlogic/version.rb
CHANGED
data/lib/catlogic.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "catlogic/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
-
|
17
|
+
|