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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90a09a9e2399112e248c597e72c7c9d28849fe84
4
- data.tar.gz: ddc5fa27e7320b5f05ca279cf247c3daac25b876
3
+ metadata.gz: fcf6e7fcb655d416e5ab00d93212b490860e2632
4
+ data.tar.gz: b9b5d3856a9c181436aff598eb043589432c2cac
5
5
  SHA512:
6
- metadata.gz: daf7a9cb7f0409ad7dd4100dc787d43ea61f70d6798f872747c5554f4ee8a976d3e0706434b91ee8064dde15b16e9a85fc66582592343a768f7a07f1d01711a6
7
- data.tar.gz: 1109801b36ac153639a25dbd5b4ca7fca6673db3a2f65d530cc2a3d612c9002352c41f067cc962c2ed9a36b5036158a924ccc65e0253792138817e1cedab4e81
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
- class Distribution
2
- attr_reader :label
1
+ module Catlogic
2
+ class Distribution
3
+ attr_reader :label
3
4
 
4
- def initialize(distribution)
5
- @label = distribution
6
- end
5
+ def initialize(distribution)
6
+ @label = distribution
7
+ end
7
8
 
8
- def opposite
9
- if self.label == 'distributed'
10
- opposite = Distribution.new('undistributed')
11
- elsif self.label == 'undistributed'
12
- opposite = Distribution.new('distributed')
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
@@ -1,45 +1,48 @@
1
- class Figure
2
- attr_reader :label
1
+ module Catlogic
2
+ class Figure
3
+ attr_reader :label
3
4
 
4
- def initialize(figure)
5
- @label = figure
6
- end
7
-
8
-
9
- def major_subject
10
- if @label == 1 || @label == 3
11
- subject = Term.new('M')
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
- elsif @label == 2 || @label == 4
14
- subject = Term.new('P')
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
- def major_predicate
20
- if @label == 1 || @label == 3
21
- predicate = Term.new("P")
22
- elsif @label == 2 || @label == 4
23
- predicate = Term.new("M")
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
- return predicate
26
- end
27
- def minor_subject
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
- elsif @label == 3 || @label == 4
32
- subject = Term.new("M")
33
+ elsif @label == 3 || @label == 4
34
+ subject = Term.new("M")
33
35
 
36
+ end
37
+ return subject
34
38
  end
35
- return subject
36
- end
37
- def minor_predicate
38
- if @label == 1 || @label == 2
39
- predicate = Term.new("M")
40
- elsif @label == 3 || @label == 4
41
- predicate = Term.new("S")
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
- class Form
2
- attr_reader :mood, :figure, :label
3
- # takes three Mood Object and Figure Object
4
- def initialize(mood, figure)
5
- @mood = mood
6
- @figure = figure
7
- @label = "#{@mood.label}#{@figure.label}"
8
- end
9
- def syllogism
10
- majorproposition = Proposition.new(@mood.majortype.quantity, @figure.major_subject, @mood.majortype.quality, @figure.major_predicate, true)
11
- minorproposition = Proposition.new(@mood.minortype.quantity, @figure.minor_subject, @mood.minortype.quality, @figure.minor_predicate, true)
12
- conclusion = Proposition.new(@mood.conclusiontype.quantity, Term.new("S"), @mood.conclusiontype.quality, Term.new("P"), true)
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
- syllogism = Syllogism.new(majorproposition, minorproposition, conclusion)
15
+ syllogism = Syllogism.new(majorproposition, minorproposition, conclusion)
15
16
 
16
- return syllogism
17
- end
18
- def validity
19
- syllogism = self.syllogism
20
- syllogism.validity
21
- end
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
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
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def to_figure
3
+ Catlogic::Figure.new(self)
4
+ end
5
+ end
data/lib/catlogic/mood.rb CHANGED
@@ -1,14 +1,26 @@
1
- class Mood
2
- attr_reader :majortype, :minortype, :conclusiontype
3
-
4
- # takes three propositionType objects
5
- def initialize(majortype, minortype, conclusiontype)
6
- @majortype = majortype
7
- @minortype = minortype
8
- @conclusiontype = conclusiontype
9
- end
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
- class PremiseCollection
2
- def initialize(propositionarray)
3
- @collection_array = propositionarray
4
- end
1
+ module Catlogic
2
+ class PremiseCollection
3
+ attr_reader :initial_propositions, :unique_propositions
5
4
 
6
- def at_least_two?
7
- if @collection_array.count >= 2
8
- true
9
- else
10
- false
5
+ def initialize(propositionarray)
6
+ @initial_propositions = propositionarray
7
+ @unique_propositions = self.unique_set
11
8
  end
12
- end
13
- def size
14
- @collection_array.count
15
- end
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
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
- return unique_set
26
- end
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)
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
- class PremisePair
2
-
3
- attr_reader :major, :minor
4
-
5
- def initialize(major, minor)
6
- @major = major
7
- @minor = minor
8
- end
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
- def middle
11
- termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
12
- middle = nil
13
- if self.three_term_pair?
14
- termarray.detect do |term|
15
- if termarray.count(term) == 2
16
- middle = Term.new(term)
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
- else
20
- middle = "Error: this is not a three term syllogism"
23
+ return middle
21
24
  end
22
- return middle
23
- end
24
25
 
25
- def three_term_pair?
26
- termarray = [@major.subject.label, @major.predicate.label, @minor.subject.label, @minor.predicate.label]
27
- if termarray.uniq.size == 3
28
- answer = true
29
- else
30
- answer = false
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
- def majorterm
35
- if @major.subject.label == self.middle.label
36
- majorterm = @major.predicate
37
- else
38
- majorterm = @major.subject
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
- majorterm
41
- end
42
- def minorterm
43
- if @minor.subject.label == self.middle.label
44
- minorterm = @minor.predicate
45
- else
46
- minorterm = @minor.subject
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
- def possible_conclusions
53
- @possible_conclusions = [
54
- Proposition.new(Quantity.new("universal"), self.minor, Quality.new("affirmative"), self.minor, true),
55
- Proposition.new(Quantity.new("universal"), self.minor, Quality.new("negative"), self.minor, true),
56
- Proposition.new(Quantity.new("particular"), self.minor, Quality.new("affirmative"), self.minor, true),
57
- Proposition.new(Quantity.new("particular"), self.minor, Quality.new("negative"), self.minor, true)
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