catlogic 0.0.2 → 0.0.3
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/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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcf6e7fcb655d416e5ab00d93212b490860e2632
|
4
|
+
data.tar.gz: b9b5d3856a9c181436aff598eb043589432c2cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06e48a30aa87c2ddd027040ea4d08d7f97edf336b5bb9c81213c21729ac2a1928d4363131a2a48b25755d0e8d74c2b1fa9534cde1eb55b5a19c201e7ba79ea8b
|
7
|
+
data.tar.gz: 4bef72f6ee5103edd20c0e59b4024515cb321a381620563d08a4a04426ff030a2539b923549f89e41761ad06397610793aaa4cb30ee3fda7d64c1b643072c27e
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
require 'catlogic'
|
10
10
|
|
11
11
|
# create a categorical proposition
|
12
|
-
proposition = Proposition.new(Quantity.new("Universal"), Term.new("Dogs), Quality.new("Affirmative"), Term.new("Mortal"), true)
|
12
|
+
proposition = Proposition.new(Quantity.new("Universal"), Term.new("Dogs), Catlogic::Quality.new("Affirmative"), Term.new("Mortal"), true)
|
13
13
|
|
14
14
|
# get the type of the proposition
|
15
15
|
proposition.type
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Distribution
|
3
|
+
attr_reader :label
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(distribution)
|
6
|
+
@label = distribution
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def opposite
|
10
|
+
if self.label == 'distributed'
|
11
|
+
opposite = Distribution.new('undistributed')
|
12
|
+
elsif self.label == 'undistributed'
|
13
|
+
opposite = Distribution.new('distributed')
|
14
|
+
end
|
15
|
+
return opposite
|
13
16
|
end
|
14
|
-
return opposite
|
15
17
|
end
|
16
|
-
end
|
18
|
+
end
|
data/lib/catlogic/figure.rb
CHANGED
@@ -1,45 +1,48 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Figure
|
3
|
+
attr_reader :label
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def initialize(figure)
|
6
|
+
@label = figure
|
7
|
+
end
|
8
|
+
def to_figure
|
9
|
+
self
|
10
|
+
end
|
11
|
+
def major_subject
|
12
|
+
if @label == 1 || @label == 3
|
13
|
+
subject = Term.new('M')
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
elsif @label == 2 || @label == 4
|
16
|
+
subject = Term.new('P')
|
17
|
+
end
|
18
|
+
return subject
|
15
19
|
end
|
16
|
-
return subject
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def major_predicate
|
22
|
+
if @label == 1 || @label == 3
|
23
|
+
predicate = Term.new("P")
|
24
|
+
elsif @label == 2 || @label == 4
|
25
|
+
predicate = Term.new("M")
|
26
|
+
end
|
27
|
+
return predicate
|
24
28
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if @label == 1 || @label == 2
|
29
|
-
subject = Term.new("S")
|
29
|
+
def minor_subject
|
30
|
+
if @label == 1 || @label == 2
|
31
|
+
subject = Term.new("S")
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
elsif @label == 3 || @label == 4
|
34
|
+
subject = Term.new("M")
|
33
35
|
|
36
|
+
end
|
37
|
+
return subject
|
34
38
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
predicate
|
39
|
+
def minor_predicate
|
40
|
+
if @label == 1 || @label == 2
|
41
|
+
predicate = Term.new("M")
|
42
|
+
elsif @label == 3 || @label == 4
|
43
|
+
predicate = Term.new("S")
|
44
|
+
end
|
45
|
+
return predicate
|
42
46
|
end
|
43
|
-
return predicate
|
44
47
|
end
|
45
48
|
end
|
data/lib/catlogic/form.rb
CHANGED
@@ -1,98 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Form
|
3
|
+
attr_reader :mood, :figure, :label
|
4
|
+
# takes three Mood Object and Figure Object
|
5
|
+
def initialize(mood, figure)
|
6
|
+
@mood = mood.to_mood
|
7
|
+
@figure = figure.to_figure
|
8
|
+
@label = "#{@mood.label}#{@figure.label}"
|
9
|
+
end
|
10
|
+
def syllogism
|
11
|
+
majorproposition = Proposition.new(@mood.majortype.quantity, @figure.major_subject, @mood.majortype.quality, @figure.major_predicate, true)
|
12
|
+
minorproposition = Proposition.new(@mood.minortype.quantity, @figure.minor_subject, @mood.minortype.quality, @figure.minor_predicate, true)
|
13
|
+
conclusion = Proposition.new(@mood.conclusiontype.quantity, Term.new("S"), @mood.conclusiontype.quality, Term.new("P"), true)
|
13
14
|
|
14
|
-
|
15
|
+
syllogism = Syllogism.new(majorproposition, minorproposition, conclusion)
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
17
|
+
return syllogism
|
18
|
+
end
|
19
|
+
def validity
|
20
|
+
syllogism = self.syllogism
|
21
|
+
syllogism.validity
|
22
|
+
end
|
23
|
+
def name
|
24
|
+
case @figure.label
|
25
|
+
when 1
|
26
|
+
case @mood.label
|
27
|
+
when "AAA"
|
28
|
+
name = "Barbara"
|
29
|
+
when "EAE"
|
30
|
+
name = "Celarent"
|
31
|
+
when "AII"
|
32
|
+
name = "Darii"
|
33
|
+
when "EIO"
|
34
|
+
name = "Ferio"
|
35
|
+
when "AAI"
|
36
|
+
name = "Barbari"
|
37
|
+
when "EAO"
|
38
|
+
name = "Celaront"
|
39
|
+
else
|
40
|
+
name = nil
|
41
|
+
end
|
42
|
+
when 2
|
43
|
+
case @mood.label
|
44
|
+
when "EAE"
|
45
|
+
name = "Cesare"
|
46
|
+
when "AEE"
|
47
|
+
name = "Camestres"
|
48
|
+
when "EIO"
|
49
|
+
name = "Festino"
|
50
|
+
when "AOO"
|
51
|
+
name = "Baroco"
|
52
|
+
when "EAO"
|
53
|
+
name = "Cesaro"
|
54
|
+
when "AEO"
|
55
|
+
name = "Camestrop"
|
56
|
+
else
|
57
|
+
name = nil
|
58
|
+
end
|
59
|
+
when 3
|
60
|
+
case @mood.label
|
61
|
+
when "AAI"
|
62
|
+
name = "Darapti"
|
63
|
+
when "IAI"
|
64
|
+
name = "Disamis"
|
65
|
+
when "AII"
|
66
|
+
name = "Datisi"
|
67
|
+
when "EAO"
|
68
|
+
name = "Felapton"
|
69
|
+
when "OAO"
|
70
|
+
name = "Bocardo"
|
71
|
+
when "EIO"
|
72
|
+
name = "Ferison"
|
73
|
+
else
|
74
|
+
name = nil
|
75
|
+
end
|
76
|
+
when 4
|
77
|
+
case @mood.label
|
78
|
+
when "AAI"
|
79
|
+
name = "Bramantip"
|
80
|
+
when "AEE"
|
81
|
+
name = "Camenes"
|
82
|
+
when "IAI"
|
83
|
+
name = "Festino"
|
84
|
+
when "EAO"
|
85
|
+
name = "Fesapo"
|
86
|
+
when "EIO"
|
87
|
+
name = "Fresison"
|
88
|
+
when "AEO"
|
89
|
+
name = "Camenop"
|
90
|
+
else
|
91
|
+
name = nil
|
92
|
+
end
|
93
|
+
else
|
94
|
+
name = nil
|
95
|
+
end
|
96
|
+
return name
|
94
97
|
end
|
95
|
-
return name
|
96
98
|
end
|
97
|
-
|
98
99
|
end
|
data/lib/catlogic/mood.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Catlogic
|
2
|
+
class Mood
|
3
|
+
attr_reader :majortype, :minortype, :conclusiontype
|
4
|
+
|
5
|
+
# takes three propositionType objects
|
6
|
+
def initialize(majortype, minortype, conclusiontype)
|
7
|
+
@majortype = majortype.to_proposition_type
|
8
|
+
@minortype = minortype.to_proposition_type
|
9
|
+
@conclusiontype = conclusiontype.to_proposition_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_mood
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def label
|
17
|
+
"#{@majortype.label}#{@minortype.label}#{@conclusiontype.label}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
self.label
|
22
|
+
end
|
10
23
|
|
11
|
-
def label
|
12
|
-
"#{@majortype.label}#{@minortype.label}#{@conclusiontype.label}"
|
13
24
|
end
|
14
|
-
end
|
25
|
+
end
|
26
|
+
|
@@ -1,38 +1,101 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
module Catlogic
|
2
|
+
class PremiseCollection
|
3
|
+
attr_reader :initial_propositions, :unique_propositions
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
false
|
5
|
+
def initialize(propositionarray)
|
6
|
+
@initial_propositions = propositionarray
|
7
|
+
@unique_propositions = self.unique_set
|
11
8
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if unique_set.count == 0
|
20
|
-
unique_set << conclusion
|
21
|
-
elsif conclusion.unique?(unique_set)
|
22
|
-
unique_set << conclusion
|
9
|
+
|
10
|
+
def at_least_two?
|
11
|
+
|
12
|
+
if @unique_propositions.count >= 2
|
13
|
+
true
|
14
|
+
else
|
15
|
+
false
|
23
16
|
end
|
24
17
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
def size
|
19
|
+
@unique_propositions.count
|
20
|
+
end
|
21
|
+
def initial_size
|
22
|
+
@initial_propositions.count
|
23
|
+
end
|
24
|
+
def unique_set
|
25
|
+
unique_set = []
|
26
|
+
@initial_propositions.each do |conclusion|
|
27
|
+
if unique_set.count == 0
|
28
|
+
unique_set << conclusion
|
29
|
+
elsif conclusion.unique?(unique_set)
|
30
|
+
unique_set << conclusion
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return unique_set
|
34
|
+
end
|
35
|
+
def premise_pairs
|
36
|
+
pairs = []
|
37
|
+
@unique_propositions.each do |proposition|
|
38
|
+
@unique_propositions.each do |secondproposition|
|
39
|
+
unless proposition.same_as?(secondproposition)
|
40
|
+
pairs << PremisePair.new(proposition, secondproposition)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return pairs
|
45
|
+
end
|
46
|
+
def three_term_premise_pairs
|
47
|
+
total_pairs = self.premise_pairs
|
48
|
+
three_term_pairs = []
|
49
|
+
total_pairs.each do |pair|
|
50
|
+
if pair.three_term_pair?
|
51
|
+
three_term_pairs << pair
|
33
52
|
end
|
34
53
|
end
|
54
|
+
return three_term_pairs
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_syllogisms
|
58
|
+
validsyllogisms = []
|
59
|
+
three_term_pairs = self.three_term_premise_pairs
|
60
|
+
three_term_pairs.each do |pair|
|
61
|
+
conclusions = pair.possible_conclusions
|
62
|
+
conclusions.each do |conclusion|
|
63
|
+
syllogism = Syllogism.new(pair.major, pair.minor, conclusion)
|
64
|
+
if syllogism.validity == true
|
65
|
+
validsyllogisms << syllogism
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
return validsyllogisms
|
70
|
+
end
|
71
|
+
|
72
|
+
# next three functions work together
|
73
|
+
# first gets all new truths
|
74
|
+
def inferred_truths_all
|
75
|
+
inferred_truths_all = []
|
76
|
+
validsyllogisms = self.valid_syllogisms
|
77
|
+
validsyllogisms.each do |syllogism|
|
78
|
+
inferred_truths_all << syllogism.conclusion
|
79
|
+
end
|
80
|
+
return inferred_truths_all
|
81
|
+
end
|
82
|
+
# next it reduces the inferred set to unique propositions and removes duplicates
|
83
|
+
def inferred_truths_unique
|
84
|
+
inferred_truths_all = self.inferred_truths_all
|
85
|
+
inferredcollection = PremiseCollection.new(inferred_truths_all)
|
86
|
+
inferred_truths_unique = inferredcollection.unique_propositions
|
87
|
+
return inferred_truths_unique
|
88
|
+
end
|
89
|
+
#finally it checks the new set against the initial set and removes already know truths
|
90
|
+
def inferred_truths_new
|
91
|
+
inferred_truths_new = []
|
92
|
+
inferred_truths_unique = self.inferred_truths_unique
|
93
|
+
inferred_truths_unique.each do |proposition|
|
94
|
+
if proposition.unique?(@unique_propositions)
|
95
|
+
inferred_truths_new << proposition
|
96
|
+
end
|
97
|
+
end
|
98
|
+
return inferred_truths_new
|
35
99
|
end
|
36
100
|
end
|
37
101
|
end
|
38
|
-
|
@@ -1,61 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Catlogic
|
2
|
+
class PremisePair
|
3
|
+
|
4
|
+
attr_reader :major, :minor
|
5
|
+
|
6
|
+
def initialize(major, minor)
|
7
|
+
@major = major
|
8
|
+
@minor = minor
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def middle
|
12
|
+
termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
|
13
|
+
middle = nil
|
14
|
+
if self.three_term_pair?
|
15
|
+
termarray.detect do |term|
|
16
|
+
if termarray.count(term) == 2
|
17
|
+
middle = Term.new(term)
|
18
|
+
end
|
17
19
|
end
|
20
|
+
else
|
21
|
+
middle = "Error: this is not a three term syllogism"
|
18
22
|
end
|
19
|
-
|
20
|
-
middle = "Error: this is not a three term syllogism"
|
23
|
+
return middle
|
21
24
|
end
|
22
|
-
return middle
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def three_term_pair?
|
27
|
+
termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
|
28
|
+
if termarray.uniq.size == 3
|
29
|
+
answer = true
|
30
|
+
else
|
31
|
+
answer = false
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def majorterm
|
36
|
+
if @major.subject.label == self.middle.label
|
37
|
+
majorterm = @major.predicate
|
38
|
+
else
|
39
|
+
majorterm = @major.subject
|
40
|
+
end
|
41
|
+
majorterm
|
39
42
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
minorterm
|
43
|
+
def minorterm
|
44
|
+
if @minor.subject.label == self.middle.label
|
45
|
+
minorterm = @minor.predicate
|
46
|
+
else
|
47
|
+
minorterm = @minor.subject
|
48
|
+
end
|
49
|
+
minorterm
|
47
50
|
end
|
48
|
-
minorterm
|
49
|
-
end
|
50
51
|
|
51
|
-
# still need a test for this
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
# still need a test for this
|
53
|
+
def possible_conclusions
|
54
|
+
possible_conclusions = [
|
55
|
+
Proposition.new(Quantity.new("universal"), self.minorterm, Quality.new("affirmative"), self.majorterm, true),
|
56
|
+
Proposition.new(Quantity.new("universal"), self.minorterm, Quality.new("negative"), self.majorterm, true),
|
57
|
+
Proposition.new(Quantity.new("particular"), self.minorterm, Quality.new("affirmative"), self.majorterm, true),
|
58
|
+
Proposition.new(Quantity.new("particular"), self.minorterm, Quality.new("negative"), self.majorterm, true)
|
59
|
+
]
|
60
|
+
return possible_conclusions
|
61
|
+
end
|
59
62
|
end
|
60
|
-
|
61
|
-
end
|
63
|
+
end
|