catlogic 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/catlogic/form.rb +77 -1
- data/lib/catlogic/premise_collection.rb +23 -196
- data/lib/catlogic/proposition.rb +13 -5
- data/lib/catlogic/version.rb +1 -1
- data/scripts/displayInferredTruths.rb +259 -0
- data/{bin2 → scripts}/getAllValidPropositions.rb +7 -2
- data/{bin2 → scripts}/testCombineSets.rb +6 -1
- data/{bin2 → scripts}/testIfUnique.rb +6 -1
- data/{bin2 → scripts}/testPremisePair.rb +6 -1
- data/{bin2 → scripts}/testProposition.rb +0 -1
- data/{bin2 → scripts}/testPropositionType.rb +6 -1
- data/{bin2 → scripts}/testReduceToUniqueSet.rb +6 -1
- data/{bin2 → scripts}/testSyllogism.rb +6 -1
- data/{bin2 → scripts}/testSyllogismForm.rb +6 -1
- data/spec/form_spec.rb +5 -0
- data/spec/premise_collection_spec.rb +41 -0
- data/spec/proposition_spec.rb +15 -0
- metadata +22 -20
- data/bin2/displayInferredTruths.rb +0 -43
- /data/{bin2 → scripts}/.idea/.name +0 -0
- /data/{bin2 → scripts}/.idea/bin.iml +0 -0
- /data/{bin2 → scripts}/.idea/encodings.xml +0 -0
- /data/{bin2 → scripts}/.idea/misc.xml +0 -0
- /data/{bin2 → scripts}/.idea/modules.xml +0 -0
- /data/{bin2 → scripts}/.idea/scopes/scope_settings.xml +0 -0
- /data/{bin2 → scripts}/.idea/vcs.xml +0 -0
- /data/{bin2 → scripts}/.idea/workspace.xml +0 -0
- /data/{bin2 → scripts}/testQuantity.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90a09a9e2399112e248c597e72c7c9d28849fe84
|
|
4
|
+
data.tar.gz: ddc5fa27e7320b5f05ca279cf247c3daac25b876
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: daf7a9cb7f0409ad7dd4100dc787d43ea61f70d6798f872747c5554f4ee8a976d3e0706434b91ee8064dde15b16e9a85fc66582592343a768f7a07f1d01711a6
|
|
7
|
+
data.tar.gz: 1109801b36ac153639a25dbd5b4ca7fca6673db3a2f65d530cc2a3d612c9002352c41f067cc962c2ed9a36b5036158a924ccc65e0253792138817e1cedab4e81
|
data/.gitignore
CHANGED
data/lib/catlogic/form.rb
CHANGED
|
@@ -19,4 +19,80 @@ class Form
|
|
|
19
19
|
syllogism = self.syllogism
|
|
20
20
|
syllogism.validity
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
def name
|
|
23
|
+
case @figure.label
|
|
24
|
+
when 1
|
|
25
|
+
case @mood.label
|
|
26
|
+
when "AAA"
|
|
27
|
+
name = "Barbara"
|
|
28
|
+
when "EAE"
|
|
29
|
+
name = "Celarent"
|
|
30
|
+
when "AII"
|
|
31
|
+
name = "Darii"
|
|
32
|
+
when "EIO"
|
|
33
|
+
name = "Ferio"
|
|
34
|
+
when "AAI"
|
|
35
|
+
name = "Barbari"
|
|
36
|
+
when "EAO"
|
|
37
|
+
name = "Celaront"
|
|
38
|
+
else
|
|
39
|
+
name = nil
|
|
40
|
+
end
|
|
41
|
+
when 2
|
|
42
|
+
case @mood.label
|
|
43
|
+
when "EAE"
|
|
44
|
+
name = "Cesare"
|
|
45
|
+
when "AEE"
|
|
46
|
+
name = "Camestres"
|
|
47
|
+
when "EIO"
|
|
48
|
+
name = "Festino"
|
|
49
|
+
when "AOO"
|
|
50
|
+
name = "Baroco"
|
|
51
|
+
when "EAO"
|
|
52
|
+
name = "Cesaro"
|
|
53
|
+
when "AEO"
|
|
54
|
+
name = "Camestrop"
|
|
55
|
+
else
|
|
56
|
+
name = nil
|
|
57
|
+
end
|
|
58
|
+
when 3
|
|
59
|
+
case @mood.label
|
|
60
|
+
when "AAI"
|
|
61
|
+
name = "Darapti"
|
|
62
|
+
when "IAI"
|
|
63
|
+
name = "Disamis"
|
|
64
|
+
when "AII"
|
|
65
|
+
name = "Datisi"
|
|
66
|
+
when "EAO"
|
|
67
|
+
name = "Felapton"
|
|
68
|
+
when "OAO"
|
|
69
|
+
name = "Bocardo"
|
|
70
|
+
when "EIO"
|
|
71
|
+
name = "Ferison"
|
|
72
|
+
else
|
|
73
|
+
name = nil
|
|
74
|
+
end
|
|
75
|
+
when 4
|
|
76
|
+
case @mood.label
|
|
77
|
+
when "AAI"
|
|
78
|
+
name = "Bramantip"
|
|
79
|
+
when "AEE"
|
|
80
|
+
name = "Camenes"
|
|
81
|
+
when "IAI"
|
|
82
|
+
name = "Festino"
|
|
83
|
+
when "EAO"
|
|
84
|
+
name = "Fesapo"
|
|
85
|
+
when "EIO"
|
|
86
|
+
name = "Fresison"
|
|
87
|
+
when "AEO"
|
|
88
|
+
name = "Camenop"
|
|
89
|
+
else
|
|
90
|
+
name = nil
|
|
91
|
+
end
|
|
92
|
+
else
|
|
93
|
+
name = nil
|
|
94
|
+
end
|
|
95
|
+
return name
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
@@ -1,211 +1,38 @@
|
|
|
1
1
|
class PremiseCollection
|
|
2
2
|
def initialize(propositionarray)
|
|
3
|
-
@
|
|
3
|
+
@collection_array = propositionarray
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
puts "collection must include two or more propositions"
|
|
6
|
+
def at_least_two?
|
|
7
|
+
if @collection_array.count >= 2
|
|
8
|
+
true
|
|
10
9
|
else
|
|
11
|
-
|
|
12
|
-
validsyllogisms = []
|
|
13
|
-
pairs = []
|
|
14
|
-
|
|
15
|
-
@collection.each do |proposition|
|
|
16
|
-
|
|
17
|
-
@collection.each do |secondproposition|
|
|
18
|
-
unless proposition.equal? secondproposition
|
|
19
|
-
pairs << PremisePair.new(proposition, secondproposition)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
pairs.each do |pair|
|
|
24
|
-
if pair.isThreeTermPair?
|
|
25
|
-
conclusions = pair.getPossibleConclusions
|
|
26
|
-
conclusions.each do |conclusion|
|
|
27
|
-
syllogism = Syllogism.new(pair.getMajor, pair.getMinor, conclusion)
|
|
28
|
-
if syllogism.validity == "valid"
|
|
29
|
-
validsyllogisms << syllogism
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
10
|
+
false
|
|
34
11
|
end
|
|
35
|
-
return validsyllogisms
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def getUniqueValidSyllogisms
|
|
39
|
-
inputconclusions = @collection
|
|
40
|
-
validsyllogisms = self.getAllValidSyllogisms
|
|
41
|
-
uniquevalidsyllogisms = []
|
|
42
|
-
|
|
43
|
-
validsyllogisms.each do |syllogism|
|
|
44
|
-
validconclusion = syllogism.getConclusion
|
|
45
|
-
if (validconclusion.isUnique?(inputconclusions))
|
|
46
|
-
uniquevalidsyllogisms << syllogism
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
return uniquevalidsyllogisms
|
|
50
12
|
end
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def getUniqueInferredTruths
|
|
54
|
-
|
|
55
|
-
uniquevalidsyllogisms = self.getUniqueValidSyllogisms
|
|
56
|
-
uniqueinferredtruths = []
|
|
57
|
-
|
|
58
|
-
uniquevalidsyllogisms.each do |syllogism|
|
|
59
|
-
uniqueinferredtruths << syllogism.getConclusion
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
return uniqueinferredtruths
|
|
13
|
+
def size
|
|
14
|
+
@collection_array.count
|
|
63
15
|
end
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
validsyllogisms.each do |syllogism|
|
|
72
|
-
validconclusion = syllogism.getConclusion
|
|
73
|
-
|
|
74
|
-
if (validconclusion.isUnique?(inputconclusions))
|
|
75
|
-
inferredconclusions << validconclusion
|
|
16
|
+
def unique_set
|
|
17
|
+
unique_set = []
|
|
18
|
+
@collection_array.each do |conclusion|
|
|
19
|
+
if unique_set.count == 0
|
|
20
|
+
unique_set << conclusion
|
|
21
|
+
elsif conclusion.unique?(unique_set)
|
|
22
|
+
unique_set << conclusion
|
|
76
23
|
end
|
|
77
24
|
end
|
|
78
|
-
return
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def getUniqueInferredTruths
|
|
83
|
-
newset = PremiseCollection.new(self.getAllInferredTruths)
|
|
84
|
-
unique_inferredconclusions = newset.reduceToUniqueSet
|
|
85
|
-
return unique_inferredconclusions
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def displayLoopedInferredTruths
|
|
91
|
-
|
|
92
|
-
#get first set of inferences from initial collection set
|
|
93
|
-
inferredtruths = self.getUniqueInferredTruths
|
|
94
|
-
#combine with existing - on first interation will be comined with empty array
|
|
95
|
-
combinedset = self.combineSets(inferredtruths)
|
|
96
|
-
|
|
97
|
-
puts "======================="
|
|
98
|
-
puts "first set of inferences"
|
|
99
|
-
puts inferredtruths.count
|
|
100
|
-
puts "======================="
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
self.displayAllValidSyllogisms
|
|
104
|
-
self.displayUniqueSyllogisms
|
|
105
|
-
self.displayInferredTruths
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
while (inferredtruths.count != 0)
|
|
109
|
-
|
|
110
|
-
## create new collection object
|
|
111
|
-
newcollection = PremiseCollection.new(combinedset)
|
|
112
|
-
|
|
113
|
-
## get next set of inferences
|
|
114
|
-
|
|
115
|
-
#reset inferred truths
|
|
116
|
-
inferredtruths = newcollection.getUniqueInferredTruths
|
|
117
|
-
#rest combined set
|
|
118
|
-
combinedset = newcollection.combineSets(inferredtruths)
|
|
119
|
-
|
|
120
|
-
puts "======================="
|
|
121
|
-
puts "next set of inferences"
|
|
122
|
-
puts inferredtruths.count
|
|
123
|
-
puts "======================="
|
|
124
|
-
|
|
125
|
-
#display inferred set
|
|
126
|
-
newcollection.displayAllValidSyllogisms
|
|
127
|
-
newcollection.displayUniqueSyllogisms
|
|
128
|
-
newcollection.displayInferredTruths
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def combineSets(newset)
|
|
135
|
-
newcollection = []
|
|
136
|
-
|
|
137
|
-
newcollection << @collection
|
|
138
|
-
newcollection << newset
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return newcollection.flatten
|
|
25
|
+
return unique_set
|
|
142
26
|
end
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if unique_knownconclusions.count == 0
|
|
151
|
-
unique_knownconclusions << conclusion
|
|
152
|
-
elsif conclusion.isUnique?(unique_knownconclusions)
|
|
153
|
-
unique_knownconclusions << conclusion
|
|
27
|
+
def premise_pairs
|
|
28
|
+
pairs = []
|
|
29
|
+
@collection_array.each do |proposition|
|
|
30
|
+
@collection_array.each do |secondproposition|
|
|
31
|
+
unless proposition.same_as?(secondproposition)
|
|
32
|
+
pairs << PremisePair.new(proposition, secondproposition)
|
|
33
|
+
end
|
|
154
34
|
end
|
|
155
|
-
|
|
156
|
-
|
|
157
35
|
end
|
|
158
|
-
return unique_knownconclusions
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def displayInferredTruths
|
|
162
|
-
truths = self.getUniqueInferredTruths
|
|
163
|
-
puts
|
|
164
|
-
puts "==== Begin Display All Unique Inferred Truths ==="
|
|
165
|
-
truths.each do |truth|
|
|
166
|
-
truth.displayProposition
|
|
167
|
-
end
|
|
168
|
-
puts "==== End Display All Unique Inferred Truths ==="
|
|
169
|
-
puts
|
|
170
|
-
|
|
171
36
|
end
|
|
37
|
+
end
|
|
172
38
|
|
|
173
|
-
def displayAllValidSyllogisms
|
|
174
|
-
puts
|
|
175
|
-
puts "====== Begin Display All Valid Syllogisms==="
|
|
176
|
-
allvalidsyllogisms = self.getAllValidSyllogisms
|
|
177
|
-
allvalidsyllogisms.each do |syllogism|
|
|
178
|
-
syllogism.displayForm
|
|
179
|
-
syllogism.displaySyllogism
|
|
180
|
-
puts
|
|
181
|
-
end
|
|
182
|
-
puts "======End All Vallid Syllogisms==="
|
|
183
|
-
puts
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def displayUniqueSyllogisms
|
|
187
|
-
|
|
188
|
-
puts
|
|
189
|
-
puts "======Begin Display All Syllogism Producing new truths==="
|
|
190
|
-
uniquevalidsyllogisms = self.getUniqueValidSyllogisms
|
|
191
|
-
uniquevalidsyllogisms.each do |syllogism|
|
|
192
|
-
syllogism.displayForm
|
|
193
|
-
syllogism.displaySyllogism
|
|
194
|
-
puts
|
|
195
|
-
end
|
|
196
|
-
puts "======End Display All Syllogism Producing new truths==="
|
|
197
|
-
puts
|
|
198
|
-
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
def getNumberOfInferredTruths
|
|
203
|
-
self.getUniqueInferredTruths.count
|
|
204
|
-
end
|
|
205
|
-
def getNumberOfInputTruths
|
|
206
|
-
@collection.count
|
|
207
|
-
end
|
|
208
|
-
def getRatioInputToInferred
|
|
209
|
-
self.getNumberOfInferredTruths / self.getNumberOfInputTruths
|
|
210
|
-
end
|
|
211
|
-
end
|
data/lib/catlogic/proposition.rb
CHANGED
|
@@ -155,6 +155,18 @@ class Proposition
|
|
|
155
155
|
return distribution
|
|
156
156
|
end
|
|
157
157
|
|
|
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
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
158
170
|
def unique?(set)
|
|
159
171
|
numerofoccurences = self.number_of_occurences(set)
|
|
160
172
|
if numerofoccurences == 0
|
|
@@ -167,11 +179,7 @@ class Proposition
|
|
|
167
179
|
def number_of_occurences(set)
|
|
168
180
|
@occurences = 0
|
|
169
181
|
set.each do |proposition|
|
|
170
|
-
if (proposition
|
|
171
|
-
proposition.subject.label == self.subject.label &&
|
|
172
|
-
proposition.quality.label == self.quality.label &&
|
|
173
|
-
proposition.predicate.label == self.predicate.label &&
|
|
174
|
-
proposition.truthvalue == self.truthvalue)
|
|
182
|
+
if self.same_as?(proposition)
|
|
175
183
|
@occurences += 1
|
|
176
184
|
end
|
|
177
185
|
end
|
data/lib/catlogic/version.rb
CHANGED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
premises2 = [Proposition.new("universal", "Mammals", "affirmative", "Mortal Things", true),
|
|
11
|
+
Proposition.new("universal", "People", "affirmative", "Mammals", true)]
|
|
12
|
+
|
|
13
|
+
premises3 = [Proposition.new("universal", "Mammals", "affirmative", "Mortal Things", true),
|
|
14
|
+
Proposition.new("universal", "People", "affirmative", "Mammals", true),
|
|
15
|
+
Proposition.new("universal", "Ants", "negative", "Mammals", true)]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
premises4 = [Proposition.new("universal", "planes", "affirmative", "things with wings", true),
|
|
19
|
+
Proposition.new("particular", "planes", "affirmative", "things with propellors", true),
|
|
20
|
+
Proposition.new("universal", "pilots", "affirmative", "things that fly planes", true),
|
|
21
|
+
Proposition.new("universal", "things that fly planes", "affirmative", "tall things", true)]
|
|
22
|
+
|
|
23
|
+
premises5 = [Proposition.new("universal", "dogs", "affirmative", "animals", true),
|
|
24
|
+
Proposition.new("universal", "cats", "affirmative", "animals", true),
|
|
25
|
+
Proposition.new("universal", "animals", "affirmative", "mortals", true),
|
|
26
|
+
Proposition.new("universal", "mortals", "affirmative", "things that disintegrate", true),
|
|
27
|
+
Proposition.new("particular", "dogs", "affirmative", "brown", true)]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
collection = PremiseCollection.new(premises4)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
puts "==============="
|
|
39
|
+
puts "intial set"
|
|
40
|
+
puts premises4.count
|
|
41
|
+
puts
|
|
42
|
+
premises4.each do |proposition|
|
|
43
|
+
proposition.displayProposition
|
|
44
|
+
end
|
|
45
|
+
puts "==============="
|
|
46
|
+
|
|
47
|
+
collection.displayLoopedInferredTruths
|
|
48
|
+
#puts "#{collection.getNumberOfInferredTruths} / #{collection.getNumberOfInputTruths}: #{collection.getRatioInputToInferred}/1"
|
|
49
|
+
|
|
50
|
+
=begin
|
|
51
|
+
def getAllValidSyllogisms
|
|
52
|
+
|
|
53
|
+
if @collection.count < 2
|
|
54
|
+
puts "collection must include two or more propositions"
|
|
55
|
+
else
|
|
56
|
+
#inputconclusions = @collection
|
|
57
|
+
validsyllogisms = []
|
|
58
|
+
pairs = []
|
|
59
|
+
|
|
60
|
+
@collection.each do |proposition|
|
|
61
|
+
|
|
62
|
+
@collection.each do |secondproposition|
|
|
63
|
+
unless proposition.equal? secondproposition
|
|
64
|
+
pairs << PremisePair.new(proposition, secondproposition)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
pairs.each do |pair|
|
|
69
|
+
if pair.isThreeTermPair?
|
|
70
|
+
conclusions = pair.getPossibleConclusions
|
|
71
|
+
conclusions.each do |conclusion|
|
|
72
|
+
syllogism = Syllogism.new(pair.getMajor, pair.getMinor, conclusion)
|
|
73
|
+
if syllogism.validity == "valid"
|
|
74
|
+
validsyllogisms << syllogism
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
return validsyllogisms
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def getUniqueValidSyllogisms
|
|
84
|
+
inputconclusions = @collection
|
|
85
|
+
validsyllogisms = self.getAllValidSyllogisms
|
|
86
|
+
uniquevalidsyllogisms = []
|
|
87
|
+
|
|
88
|
+
validsyllogisms.each do |syllogism|
|
|
89
|
+
validconclusion = syllogism.getConclusion
|
|
90
|
+
if (validconclusion.isUnique?(inputconclusions))
|
|
91
|
+
uniquevalidsyllogisms << syllogism
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
return uniquevalidsyllogisms
|
|
95
|
+
end
|
|
96
|
+
=end
|
|
97
|
+
|
|
98
|
+
=begin
|
|
99
|
+
def getUniqueInferredTruths
|
|
100
|
+
|
|
101
|
+
uniquevalidsyllogisms = self.getUniqueValidSyllogisms
|
|
102
|
+
uniqueinferredtruths = []
|
|
103
|
+
|
|
104
|
+
uniquevalidsyllogisms.each do |syllogism|
|
|
105
|
+
uniqueinferredtruths << syllogism.getConclusion
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
return uniqueinferredtruths
|
|
109
|
+
end
|
|
110
|
+
=end
|
|
111
|
+
|
|
112
|
+
=begin
|
|
113
|
+
def getAllInferredTruths
|
|
114
|
+
inputconclusions = @collection
|
|
115
|
+
inferredconclusions = []
|
|
116
|
+
|
|
117
|
+
validsyllogisms = self.getAllValidSyllogisms
|
|
118
|
+
validsyllogisms.each do |syllogism|
|
|
119
|
+
validconclusion = syllogism.getConclusion
|
|
120
|
+
|
|
121
|
+
if (validconclusion.isUnique?(inputconclusions))
|
|
122
|
+
inferredconclusions << validconclusion
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
return inferredconclusions
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def getUniqueInferredTruths
|
|
130
|
+
newset = PremiseCollection.new(self.getAllInferredTruths)
|
|
131
|
+
unique_inferredconclusions = newset.reduceToUniqueSet
|
|
132
|
+
return unique_inferredconclusions
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def displayLoopedInferredTruths
|
|
138
|
+
|
|
139
|
+
#get first set of inferences from initial collection set
|
|
140
|
+
inferredtruths = self.getUniqueInferredTruths
|
|
141
|
+
#combine with existing - on first interation will be comined with empty array
|
|
142
|
+
combinedset = self.combineSets(inferredtruths)
|
|
143
|
+
|
|
144
|
+
puts "======================="
|
|
145
|
+
puts "first set of inferences"
|
|
146
|
+
puts inferredtruths.count
|
|
147
|
+
puts "======================="
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
self.displayAllValidSyllogisms
|
|
151
|
+
self.displayUniqueSyllogisms
|
|
152
|
+
self.displayInferredTruths
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
while (inferredtruths.count != 0)
|
|
156
|
+
|
|
157
|
+
## create new collection object
|
|
158
|
+
newcollection = PremiseCollection.new(combinedset)
|
|
159
|
+
|
|
160
|
+
## get next set of inferences
|
|
161
|
+
|
|
162
|
+
#reset inferred truths
|
|
163
|
+
inferredtruths = newcollection.getUniqueInferredTruths
|
|
164
|
+
#rest combined set
|
|
165
|
+
combinedset = newcollection.combineSets(inferredtruths)
|
|
166
|
+
|
|
167
|
+
puts "======================="
|
|
168
|
+
puts "next set of inferences"
|
|
169
|
+
puts inferredtruths.count
|
|
170
|
+
puts "======================="
|
|
171
|
+
|
|
172
|
+
#display inferred set
|
|
173
|
+
newcollection.displayAllValidSyllogisms
|
|
174
|
+
newcollection.displayUniqueSyllogisms
|
|
175
|
+
newcollection.displayInferredTruths
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def combineSets(newset)
|
|
182
|
+
newcollection = []
|
|
183
|
+
|
|
184
|
+
newcollection << @collection
|
|
185
|
+
newcollection << newset
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
return newcollection.flatten
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def reduceToUniqueSet
|
|
194
|
+
unique_knownconclusions = []
|
|
195
|
+
|
|
196
|
+
@collection.each do |conclusion|
|
|
197
|
+
if unique_knownconclusions.count == 0
|
|
198
|
+
unique_knownconclusions << conclusion
|
|
199
|
+
elsif conclusion.isUnique?(unique_knownconclusions)
|
|
200
|
+
unique_knownconclusions << conclusion
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
end
|
|
205
|
+
return unique_knownconclusions
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def displayInferredTruths
|
|
209
|
+
truths = self.getUniqueInferredTruths
|
|
210
|
+
puts
|
|
211
|
+
puts "==== Begin Display All Unique Inferred Truths ==="
|
|
212
|
+
truths.each do |truth|
|
|
213
|
+
truth.displayProposition
|
|
214
|
+
end
|
|
215
|
+
puts "==== End Display All Unique Inferred Truths ==="
|
|
216
|
+
puts
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def displayAllValidSyllogisms
|
|
221
|
+
puts
|
|
222
|
+
puts "====== Begin Display All Valid Syllogisms==="
|
|
223
|
+
allvalidsyllogisms = self.getAllValidSyllogisms
|
|
224
|
+
allvalidsyllogisms.each do |syllogism|
|
|
225
|
+
syllogism.displayForm
|
|
226
|
+
syllogism.displaySyllogism
|
|
227
|
+
puts
|
|
228
|
+
end
|
|
229
|
+
puts "======End All Vallid Syllogisms==="
|
|
230
|
+
puts
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def displayUniqueSyllogisms
|
|
234
|
+
|
|
235
|
+
puts
|
|
236
|
+
puts "======Begin Display All Syllogism Producing new truths==="
|
|
237
|
+
uniquevalidsyllogisms = self.getUniqueValidSyllogisms
|
|
238
|
+
uniquevalidsyllogisms.each do |syllogism|
|
|
239
|
+
syllogism.displayForm
|
|
240
|
+
syllogism.displaySyllogism
|
|
241
|
+
puts
|
|
242
|
+
end
|
|
243
|
+
puts "======End Display All Syllogism Producing new truths==="
|
|
244
|
+
puts
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def getNumberOfInferredTruths
|
|
250
|
+
self.getUniqueInferredTruths.count
|
|
251
|
+
end
|
|
252
|
+
def getNumberOfInputTruths
|
|
253
|
+
@collection.count
|
|
254
|
+
end
|
|
255
|
+
def getRatioInputToInferred
|
|
256
|
+
self.getNumberOfInferredTruths / self.getNumberOfInputTruths
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
=end
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
typeArray = ["A", "E", "I", "O"]
|
|
6
11
|
numberArray = [1,2,3,4]
|
|
@@ -16,7 +21,7 @@ numberArray.each do |i|
|
|
|
16
21
|
form = Form.new(mood, Figure.new(i))
|
|
17
22
|
|
|
18
23
|
if form.validity == true
|
|
19
|
-
puts form.label
|
|
24
|
+
puts form.label + " " + form.name
|
|
20
25
|
end
|
|
21
26
|
end
|
|
22
27
|
end
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
premises1 = [Proposition.new("universal", "dogs", "affirmative", "animals", true),
|
|
6
11
|
Proposition.new("universal", "cats", "affirmative", "animals", true),
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
premisesArray = [Proposition.new(Quantity.new("universal"), Term.new("Events"), Quality.new("affirmative"), Term.new("Caused Happenings"), true),
|
|
6
11
|
Proposition.new(Quantity.new("universal"), Term.new("Free Decisions"), Quality.new("negative"), Term.new("Caused Happenings"), true),
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
premise1 = Proposition.new("universal", "Mammals", "affirmative", "Dogs", true)
|
|
6
11
|
premise2 = Proposition.new("universal", "Mammals", "affirmative", "Mortal Things", true)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
premisesArray = [Proposition.new("universal", "Events", "affirmative", "Caused Happenings", true),
|
|
6
11
|
Proposition.new("universal", "Free Decisions", "negative", "Caused Happenings", true),
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
major = Proposition.new(Quantity.new("universal"), Term.new("pollution free"), Quality.new("negative"), Term.new("completely efficient"), true)
|
|
6
11
|
minor = Proposition.new(Quantity.new("universal"), Term.new("automobile"), Quality.new("negative"), Term.new("completely efficient"), true)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'catlogic'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'catlogic'
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
mood = Mood.new(PropositionType.new("A"), PropositionType.new("A"), PropositionType.new("A"))
|
|
6
11
|
figure = Figure.new(3)
|
data/spec/form_spec.rb
CHANGED
|
@@ -19,4 +19,9 @@ describe "form object" do
|
|
|
19
19
|
|
|
20
20
|
major.label == "All M are P" && minor.label == "All S are M" && conclusion.label == "All S are P"
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
it "should return the name 'Barbara' for a AAA1 syllogism" do
|
|
24
|
+
name = $form.name
|
|
25
|
+
name.should == "Barbara"
|
|
26
|
+
end
|
|
22
27
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'catlogic'
|
|
3
|
+
|
|
4
|
+
describe "premise collection object" do
|
|
5
|
+
|
|
6
|
+
$collection2 = PremiseCollection.new([Proposition.new(Quantity.new("universal"), Term.new("Mammals"), Quality.new("affirmative"), Term.new("Mortal Things"), true),
|
|
7
|
+
Proposition.new(Quantity.new("universal"), Term.new("People"), Quality.new("affirmative"), Term.new("Mammals"), true)])
|
|
8
|
+
|
|
9
|
+
$collection3 = PremiseCollection.new([Proposition.new(Quantity.new("universal"), Term.new("Mammals"), Quality.new("affirmative"), Term.new("Mortal Things"), true),
|
|
10
|
+
Proposition.new(Quantity.new("universal"), Term.new("People"), Quality.new("affirmative"), Term.new("Mammals"), true),
|
|
11
|
+
Proposition.new(Quantity.new("universal"), Term.new("Ants"), Quality.new("Negative"), Term.new("Mammals"), true)])
|
|
12
|
+
|
|
13
|
+
it "should confirm that there are two or more premises in the collection" do
|
|
14
|
+
result = $collection2.at_least_two?
|
|
15
|
+
result.should == true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should return the size of the collection3 as 3 (aka the number of propositions in the collection' do
|
|
19
|
+
result = $collection3.size
|
|
20
|
+
result.should == 3
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should reduce collection to unique propositions only and return count of 3' do
|
|
24
|
+
result = $collection3.unique_set
|
|
25
|
+
result.count.should == 3
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should reduce non-unique collection to unique propositions only and return count of 2' do
|
|
29
|
+
collection = PremiseCollection.new([Proposition.new(Quantity.new("universal"), Term.new("Mammals"), Quality.new("affirmative"), Term.new("Mortal Things"), true),
|
|
30
|
+
Proposition.new(Quantity.new("universal"), Term.new("Mammals"), Quality.new("affirmative"), Term.new("Mortal Things"), true),
|
|
31
|
+
Proposition.new(Quantity.new("universal"), Term.new("Ants"), Quality.new("Negative"), Term.new("Mammals"), true)])
|
|
32
|
+
result = collection.unique_set
|
|
33
|
+
result.count.should == 2
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should return a premise pair collection for two propositions whose set count is 2' do
|
|
38
|
+
result = $collection2.premise_pairs
|
|
39
|
+
result.count.should == 2
|
|
40
|
+
end
|
|
41
|
+
end
|
data/spec/proposition_spec.rb
CHANGED
|
@@ -212,4 +212,19 @@ describe 'proposition object' do
|
|
|
212
212
|
|
|
213
213
|
result.should == false
|
|
214
214
|
end
|
|
215
|
+
|
|
216
|
+
it 'can return answer false for two propositions that are not identical' do
|
|
217
|
+
prop1 = Proposition.new(Quantity.new("universal"), Term.new("Events"), Quality.new("affirmative"), Term.new("Caused Happenings"), true)
|
|
218
|
+
prop2 = Proposition.new(Quantity.new("universal"), Term.new("Free Decisions"), Quality.new("negative"), Term.new("Caused Happenings"), true)
|
|
219
|
+
result = prop1.same_as?(prop2)
|
|
220
|
+
result.should == false
|
|
221
|
+
end
|
|
222
|
+
it 'can return answer true for two propositions that are identical' do
|
|
223
|
+
prop1 = Proposition.new(Quantity.new("universal"), Term.new("Events"), Quality.new("affirmative"), Term.new("Caused Happenings"), true)
|
|
224
|
+
prop2 = Proposition.new(Quantity.new("universal"), Term.new("Events"), Quality.new("affirmative"), Term.new("Caused Happenings"), true)
|
|
225
|
+
result = prop1.same_as?(prop2)
|
|
226
|
+
result.should == true
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
|
|
215
230
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: catlogic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeffrey C. Witt
|
|
@@ -81,25 +81,6 @@ files:
|
|
|
81
81
|
- LICENSE.txt
|
|
82
82
|
- README.md
|
|
83
83
|
- Rakefile
|
|
84
|
-
- bin2/.idea/.name
|
|
85
|
-
- bin2/.idea/bin.iml
|
|
86
|
-
- bin2/.idea/encodings.xml
|
|
87
|
-
- bin2/.idea/misc.xml
|
|
88
|
-
- bin2/.idea/modules.xml
|
|
89
|
-
- bin2/.idea/scopes/scope_settings.xml
|
|
90
|
-
- bin2/.idea/vcs.xml
|
|
91
|
-
- bin2/.idea/workspace.xml
|
|
92
|
-
- bin2/displayInferredTruths.rb
|
|
93
|
-
- bin2/getAllValidPropositions.rb
|
|
94
|
-
- bin2/testCombineSets.rb
|
|
95
|
-
- bin2/testIfUnique.rb
|
|
96
|
-
- bin2/testPremisePair.rb
|
|
97
|
-
- bin2/testProposition.rb
|
|
98
|
-
- bin2/testPropositionType.rb
|
|
99
|
-
- bin2/testQuantity.rb
|
|
100
|
-
- bin2/testReduceToUniqueSet.rb
|
|
101
|
-
- bin2/testSyllogism.rb
|
|
102
|
-
- bin2/testSyllogismForm.rb
|
|
103
84
|
- catlogic.gemspec
|
|
104
85
|
- lib/catlogic.rb
|
|
105
86
|
- lib/catlogic/distribution.rb
|
|
@@ -115,10 +96,30 @@ files:
|
|
|
115
96
|
- lib/catlogic/syllogism.rb
|
|
116
97
|
- lib/catlogic/term.rb
|
|
117
98
|
- lib/catlogic/version.rb
|
|
99
|
+
- scripts/.idea/.name
|
|
100
|
+
- scripts/.idea/bin.iml
|
|
101
|
+
- scripts/.idea/encodings.xml
|
|
102
|
+
- scripts/.idea/misc.xml
|
|
103
|
+
- scripts/.idea/modules.xml
|
|
104
|
+
- scripts/.idea/scopes/scope_settings.xml
|
|
105
|
+
- scripts/.idea/vcs.xml
|
|
106
|
+
- scripts/.idea/workspace.xml
|
|
107
|
+
- scripts/displayInferredTruths.rb
|
|
108
|
+
- scripts/getAllValidPropositions.rb
|
|
109
|
+
- scripts/testCombineSets.rb
|
|
110
|
+
- scripts/testIfUnique.rb
|
|
111
|
+
- scripts/testPremisePair.rb
|
|
112
|
+
- scripts/testProposition.rb
|
|
113
|
+
- scripts/testPropositionType.rb
|
|
114
|
+
- scripts/testQuantity.rb
|
|
115
|
+
- scripts/testReduceToUniqueSet.rb
|
|
116
|
+
- scripts/testSyllogism.rb
|
|
117
|
+
- scripts/testSyllogismForm.rb
|
|
118
118
|
- spec/distribution_spec.rb
|
|
119
119
|
- spec/figure_spec.rb
|
|
120
120
|
- spec/form_spec.rb
|
|
121
121
|
- spec/mood_spec.rb
|
|
122
|
+
- spec/premise_collection_spec.rb
|
|
122
123
|
- spec/premise_pair_spec.rb
|
|
123
124
|
- spec/proposition_spec.rb
|
|
124
125
|
- spec/proposition_type_spec.rb
|
|
@@ -156,6 +157,7 @@ test_files:
|
|
|
156
157
|
- spec/figure_spec.rb
|
|
157
158
|
- spec/form_spec.rb
|
|
158
159
|
- spec/mood_spec.rb
|
|
160
|
+
- spec/premise_collection_spec.rb
|
|
159
161
|
- spec/premise_pair_spec.rb
|
|
160
162
|
- spec/proposition_spec.rb
|
|
161
163
|
- spec/proposition_type_spec.rb
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require_relative "../lib/catlog.rb"
|
|
4
|
-
|
|
5
|
-
premises2 = [Proposition.new("universal", "Mammals", "affirmative", "Mortal Things", true),
|
|
6
|
-
Proposition.new("universal", "People", "affirmative", "Mammals", true)]
|
|
7
|
-
|
|
8
|
-
premises3 = [Proposition.new("universal", "Mammals", "affirmative", "Mortal Things", true),
|
|
9
|
-
Proposition.new("universal", "People", "affirmative", "Mammals", true),
|
|
10
|
-
Proposition.new("universal", "Ants", "negative", "Mammals", true)]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
premises4 = [Proposition.new("universal", "planes", "affirmative", "things with wings", true),
|
|
14
|
-
Proposition.new("particular", "planes", "affirmative", "things with propellors", true),
|
|
15
|
-
Proposition.new("universal", "pilots", "affirmative", "things that fly planes", true),
|
|
16
|
-
Proposition.new("universal", "things that fly planes", "affirmative", "tall things", true)]
|
|
17
|
-
|
|
18
|
-
premises5 = [Proposition.new("universal", "dogs", "affirmative", "animals", true),
|
|
19
|
-
Proposition.new("universal", "cats", "affirmative", "animals", true),
|
|
20
|
-
Proposition.new("universal", "animals", "affirmative", "mortals", true),
|
|
21
|
-
Proposition.new("universal", "mortals", "affirmative", "things that disintegrate", true),
|
|
22
|
-
Proposition.new("particular", "dogs", "affirmative", "brown", true)]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
collection = PremiseCollection.new(premises4)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
puts "==============="
|
|
34
|
-
puts "intial set"
|
|
35
|
-
puts premises4.count
|
|
36
|
-
puts
|
|
37
|
-
premises4.each do |proposition|
|
|
38
|
-
proposition.displayProposition
|
|
39
|
-
end
|
|
40
|
-
puts "==============="
|
|
41
|
-
|
|
42
|
-
collection.displayLoopedInferredTruths
|
|
43
|
-
#puts "#{collection.getNumberOfInferredTruths} / #{collection.getNumberOfInputTruths}: #{collection.getRatioInputToInferred}/1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|