activefacts 1.6.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +3 -80
  9. data/activefacts.gemspec +36 -0
  10. data/bin/afgen +4 -2
  11. data/bin/cql +5 -1
  12. data/lib/activefacts.rb +3 -12
  13. data/lib/activefacts/{vocabulary/query_evaluator.rb → query/evaluator.rb} +0 -0
  14. data/lib/activefacts/version.rb +2 -2
  15. metadata +48 -296
  16. data/History.txt +0 -4
  17. data/LICENSE +0 -19
  18. data/Manifest.txt +0 -165
  19. data/README.rdoc +0 -81
  20. data/css/offline.css +0 -3
  21. data/css/orm2.css +0 -124
  22. data/css/print.css +0 -8
  23. data/css/style-print.css +0 -357
  24. data/css/style.css +0 -387
  25. data/download.html +0 -110
  26. data/examples/CQL/Address.cql +0 -44
  27. data/examples/CQL/Blog.cql +0 -54
  28. data/examples/CQL/CompanyDirectorEmployee.cql +0 -56
  29. data/examples/CQL/Death.cql +0 -17
  30. data/examples/CQL/Diplomacy.cql +0 -48
  31. data/examples/CQL/Genealogy.cql +0 -98
  32. data/examples/CQL/Insurance.cql +0 -320
  33. data/examples/CQL/Marriage.cql +0 -18
  34. data/examples/CQL/Metamodel.cql +0 -493
  35. data/examples/CQL/Monogamy.cql +0 -24
  36. data/examples/CQL/MultiInheritance.cql +0 -22
  37. data/examples/CQL/NonRoleId.cql +0 -14
  38. data/examples/CQL/OddIdentifier.cql +0 -18
  39. data/examples/CQL/OilSupply.cql +0 -53
  40. data/examples/CQL/OneToOnes.cql +0 -17
  41. data/examples/CQL/Orienteering.cql +0 -111
  42. data/examples/CQL/PersonPlaysGame.cql +0 -18
  43. data/examples/CQL/RedundantDependency.cql +0 -34
  44. data/examples/CQL/SchoolActivities.cql +0 -33
  45. data/examples/CQL/SeparateSubtype.cql +0 -30
  46. data/examples/CQL/ServiceDirector.cql +0 -276
  47. data/examples/CQL/SimplestUnary.cql +0 -12
  48. data/examples/CQL/Supervision.cql +0 -34
  49. data/examples/CQL/WaiterTips.cql +0 -33
  50. data/examples/CQL/Warehousing.cql +0 -101
  51. data/examples/CQL/WindowInRoomInBldg.cql +0 -28
  52. data/examples/CQL/unit.cql +0 -474
  53. data/examples/index.html +0 -420
  54. data/examples/intro.html +0 -327
  55. data/examples/local.css +0 -24
  56. data/index.html +0 -111
  57. data/lib/activefacts/cql.rb +0 -35
  58. data/lib/activefacts/cql/CQLParser.treetop +0 -158
  59. data/lib/activefacts/cql/Context.treetop +0 -48
  60. data/lib/activefacts/cql/Expressions.treetop +0 -67
  61. data/lib/activefacts/cql/FactTypes.treetop +0 -358
  62. data/lib/activefacts/cql/Language/English.treetop +0 -315
  63. data/lib/activefacts/cql/LexicalRules.treetop +0 -253
  64. data/lib/activefacts/cql/ObjectTypes.treetop +0 -210
  65. data/lib/activefacts/cql/Rakefile +0 -14
  66. data/lib/activefacts/cql/Terms.treetop +0 -183
  67. data/lib/activefacts/cql/ValueTypes.treetop +0 -202
  68. data/lib/activefacts/cql/compiler.rb +0 -156
  69. data/lib/activefacts/cql/compiler/clause.rb +0 -1137
  70. data/lib/activefacts/cql/compiler/constraint.rb +0 -581
  71. data/lib/activefacts/cql/compiler/entity_type.rb +0 -457
  72. data/lib/activefacts/cql/compiler/expression.rb +0 -443
  73. data/lib/activefacts/cql/compiler/fact.rb +0 -390
  74. data/lib/activefacts/cql/compiler/fact_type.rb +0 -421
  75. data/lib/activefacts/cql/compiler/query.rb +0 -106
  76. data/lib/activefacts/cql/compiler/shared.rb +0 -161
  77. data/lib/activefacts/cql/compiler/value_type.rb +0 -174
  78. data/lib/activefacts/cql/nodes.rb +0 -49
  79. data/lib/activefacts/cql/parser.rb +0 -241
  80. data/lib/activefacts/dependency_analyser.rb +0 -182
  81. data/lib/activefacts/generate/absorption.rb +0 -70
  82. data/lib/activefacts/generate/composition.rb +0 -118
  83. data/lib/activefacts/generate/cql.rb +0 -714
  84. data/lib/activefacts/generate/dm.rb +0 -279
  85. data/lib/activefacts/generate/help.rb +0 -64
  86. data/lib/activefacts/generate/helpers/inject.rb +0 -16
  87. data/lib/activefacts/generate/helpers/oo.rb +0 -162
  88. data/lib/activefacts/generate/helpers/ordered.rb +0 -605
  89. data/lib/activefacts/generate/helpers/rails.rb +0 -57
  90. data/lib/activefacts/generate/html/glossary.rb +0 -461
  91. data/lib/activefacts/generate/json.rb +0 -337
  92. data/lib/activefacts/generate/null.rb +0 -32
  93. data/lib/activefacts/generate/rails/models.rb +0 -246
  94. data/lib/activefacts/generate/rails/schema.rb +0 -216
  95. data/lib/activefacts/generate/records.rb +0 -46
  96. data/lib/activefacts/generate/ruby.rb +0 -133
  97. data/lib/activefacts/generate/sql/mysql.rb +0 -280
  98. data/lib/activefacts/generate/sql/server.rb +0 -273
  99. data/lib/activefacts/generate/stats.rb +0 -69
  100. data/lib/activefacts/generate/text.rb +0 -27
  101. data/lib/activefacts/generate/topics.rb +0 -265
  102. data/lib/activefacts/generate/traits/datavault.rb +0 -241
  103. data/lib/activefacts/generate/traits/oo.rb +0 -73
  104. data/lib/activefacts/generate/traits/ordered.rb +0 -33
  105. data/lib/activefacts/generate/traits/ruby.rb +0 -210
  106. data/lib/activefacts/generate/transform/datavault.rb +0 -266
  107. data/lib/activefacts/generate/transform/surrogate.rb +0 -214
  108. data/lib/activefacts/generate/version.rb +0 -26
  109. data/lib/activefacts/input/cql.rb +0 -43
  110. data/lib/activefacts/input/orm.rb +0 -1636
  111. data/lib/activefacts/mapping/rails.rb +0 -132
  112. data/lib/activefacts/persistence.rb +0 -15
  113. data/lib/activefacts/persistence/columns.rb +0 -446
  114. data/lib/activefacts/persistence/foreignkey.rb +0 -187
  115. data/lib/activefacts/persistence/index.rb +0 -240
  116. data/lib/activefacts/persistence/object_type.rb +0 -198
  117. data/lib/activefacts/persistence/reference.rb +0 -434
  118. data/lib/activefacts/persistence/tables.rb +0 -380
  119. data/lib/activefacts/registry.rb +0 -11
  120. data/lib/activefacts/support.rb +0 -132
  121. data/lib/activefacts/vocabulary.rb +0 -9
  122. data/lib/activefacts/vocabulary/extensions.rb +0 -1348
  123. data/lib/activefacts/vocabulary/metamodel.rb +0 -570
  124. data/lib/activefacts/vocabulary/verbaliser.rb +0 -804
  125. data/script/txt2html +0 -71
  126. data/spec/absorption_spec.rb +0 -95
  127. data/spec/cql/comparison_spec.rb +0 -89
  128. data/spec/cql/context_spec.rb +0 -94
  129. data/spec/cql/contractions_spec.rb +0 -224
  130. data/spec/cql/deontic_spec.rb +0 -88
  131. data/spec/cql/entity_type_spec.rb +0 -320
  132. data/spec/cql/expressions_spec.rb +0 -66
  133. data/spec/cql/fact_type_matching_spec.rb +0 -338
  134. data/spec/cql/french_spec.rb +0 -21
  135. data/spec/cql/parser/bad_literals_spec.rb +0 -86
  136. data/spec/cql/parser/constraints_spec.rb +0 -19
  137. data/spec/cql/parser/entity_types_spec.rb +0 -106
  138. data/spec/cql/parser/expressions_spec.rb +0 -199
  139. data/spec/cql/parser/fact_types_spec.rb +0 -44
  140. data/spec/cql/parser/literals_spec.rb +0 -312
  141. data/spec/cql/parser/pragmas_spec.rb +0 -89
  142. data/spec/cql/parser/value_types_spec.rb +0 -42
  143. data/spec/cql/role_matching_spec.rb +0 -148
  144. data/spec/cql/samples_spec.rb +0 -244
  145. data/spec/cql_cql_spec.rb +0 -73
  146. data/spec/cql_dm_spec.rb +0 -136
  147. data/spec/cql_mysql_spec.rb +0 -69
  148. data/spec/cql_parse_spec.rb +0 -34
  149. data/spec/cql_ruby_spec.rb +0 -73
  150. data/spec/cql_sql_spec.rb +0 -72
  151. data/spec/cql_symbol_tables_spec.rb +0 -261
  152. data/spec/cqldump_spec.rb +0 -170
  153. data/spec/helpers/array_matcher.rb +0 -23
  154. data/spec/helpers/ctrl_c_support.rb +0 -52
  155. data/spec/helpers/diff_matcher.rb +0 -39
  156. data/spec/helpers/file_matcher.rb +0 -34
  157. data/spec/helpers/parse_to_ast_matcher.rb +0 -80
  158. data/spec/helpers/string_matcher.rb +0 -30
  159. data/spec/helpers/test_parser.rb +0 -15
  160. data/spec/norma_cql_spec.rb +0 -66
  161. data/spec/norma_ruby_spec.rb +0 -62
  162. data/spec/norma_ruby_sql_spec.rb +0 -107
  163. data/spec/norma_sql_spec.rb +0 -57
  164. data/spec/norma_tables_spec.rb +0 -95
  165. data/spec/ruby_api_spec.rb +0 -23
  166. data/spec/spec_helper.rb +0 -35
  167. data/spec/transform_surrogate_spec.rb +0 -59
  168. data/status.html +0 -138
  169. data/why.html +0 -60
@@ -1,89 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'helpers/test_parser'
10
-
11
- describe "Entity Types" do
12
- IndependentObjectTypes = [
13
- # Value types
14
- [ "a is written as b [independent];",
15
- ['ValueType: a is written as b, pragmas [independent];'],
16
- ],
17
- [ "a [independent] is written as b;",
18
- ['ValueType: a is written as b, pragmas [independent];'],
19
- ],
20
-
21
- # Entity types
22
- [ "a is identified by its id [independent];",
23
- ['EntityType: a identified by its id, pragmas [independent];']
24
- ],
25
- [ "a [independent] is identified by its id;",
26
- ['EntityType: a identified by its id, pragmas [independent];']
27
- ],
28
- [ "a is independent identified by its id;",
29
- ['EntityType: a identified by its id, pragmas [independent];']
30
- ],
31
- [ "a is identified by b [independent] where a has one b;",
32
- ['EntityType: a [{b}] where [{a} "has" {[1..1] b}], pragmas [independent];']
33
- ],
34
- [ "a is independent identified by b where a has one b;",
35
- ['EntityType: a [{b}] where [{a} "has" {[1..1] b}], pragmas [independent];']
36
- ],
37
-
38
- # Subtypes
39
- [ "Employee [independent] is a kind of Person;",
40
- ['EntityType: Employee < Person nil, pragmas [independent];']
41
- ],
42
- [ "Employee is a kind of Person [independent];",
43
- ['EntityType: Employee < Person nil, pragmas [independent];']
44
- ],
45
- [ "Employee is a kind of independent Person;",
46
- ['EntityType: Employee < Person nil, pragmas [independent];']
47
- ],
48
- [ "Employee is a kind of Person identified by its id [independent];",
49
- ["EntityType: Employee < Person identified by its id, pragmas [independent];"]
50
- ],
51
-
52
- # Fact Types
53
- [ "Director is where c relates to b;",
54
- ["FactType: [{c} \"relates to\" {b}]"]
55
- ],
56
- [ "Director [independent] is where c relates to b;",
57
- ["FactType: [{c} \"relates to\" {b}], pragmas [independent]"]
58
- ],
59
- [ "Director is independent where c relates to b;",
60
- ["FactType: [{c} \"relates to\" {b}], pragmas [independent]"]
61
- ],
62
- ]
63
-
64
- PragmaObjectTypes =
65
- IndependentObjectTypes
66
-
67
- before :each do
68
- @parser = TestParser.new
69
- @parser.parse_all("c is written as b;", :definition)
70
- end
71
-
72
- PragmaObjectTypes.each do |c|
73
- source, ast = *c
74
- it "should parse #{source.inspect}" do
75
- result = @parser.parse_all(source, :definition)
76
-
77
- puts @parser.failure_reason unless result
78
- result.should_not be_nil
79
-
80
- canonical_form = result.map{|d| d.ast.to_s}
81
- if ast
82
- canonical_form.should == ast
83
- else
84
- pending "#{source.inspect} should compile to\n" +
85
- "\t#{canonical_form}"
86
- end
87
- end
88
- end
89
- end
@@ -1,42 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/cql'
7
- require 'activefacts/support'
8
- require 'activefacts/api/support'
9
- require 'helpers/test_parser'
10
-
11
- describe "Value Types" do
12
- ValueTypes = [
13
- [ "a is written as b(1, 2) in inch restricted to { 3 .. 4 } inch ;",
14
- ['ValueType: a is written as b(1, 2) in [["inch", 1]] ValueConstraint to ([3..4]) in [["inch", 1]];']
15
- ],
16
- # [ "a c is written as b(1, 2) inch restricted to { 3 .. 4 } inch ;",
17
- # [["a c", [:value_type, "b", [1, 2], "inch", [[3, 4]]]]]
18
- # ],
19
- ]
20
-
21
- before :each do
22
- @parser = TestParser.new
23
- end
24
-
25
- ValueTypes.each do |c|
26
- source, ast = *c
27
- it "should parse #{source.inspect}" do
28
- result = @parser.parse_all(source, :definition)
29
-
30
- puts @parser.failure_reason unless result
31
- result.should_not be_nil
32
-
33
- canonical_form = result.map{|d| d.ast.to_s}
34
- if ast
35
- canonical_form.should == ast
36
- else
37
- puts "#{source.inspect} should compile to"
38
- puts "\t#{canonical_form}"
39
- end
40
- end
41
- end
42
- end
@@ -1,148 +0,0 @@
1
- #
2
- # ActiveFacts CQL Fact Type matching tests
3
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
4
- #
5
- $: << Dir::getwd
6
-
7
- require 'rspec/expectations'
8
-
9
- require 'activefacts/support'
10
- require 'activefacts/api/support'
11
- require 'activefacts/cql/compiler'
12
- require File.dirname(__FILE__) + '/../helpers/compile_helpers'
13
-
14
- describe "When comparing roles of a reading with an existing reading" do
15
- before :each do
16
- extend CompileHelpers
17
-
18
- prefix = %q{
19
- vocabulary Tests;
20
- Boy is written as String;
21
- Girl is written as Integer;
22
- }
23
- @compiler = ActiveFacts::CQL::Compiler.new('Test')
24
- @compiler.compile(prefix)
25
- @constellation = @compiler.vocabulary.constellation
26
-
27
- baseline
28
- end
29
-
30
- describe "producing correct side effects" do
31
- before :each do
32
- @compiler.compile %q{ Boy is going out with Girl; }
33
- @simple_ft = fact_types[0]
34
- baseline
35
- @compiler.compile %q{ Boy dislikes ugly-Girl; }
36
- @ugly_ft = fact_types[0]
37
- baseline
38
- @compiler.compile %q{ Boy -monster hurts Girl; }
39
- @hurts_ft = fact_types[0]
40
- baseline
41
- #debug_enable("matching"); debug_enable("matching_fails"); debug_enable("parse")
42
- end
43
- after :each do
44
- # debug_disable("matching"); debug_disable("matching_fails"); debug_disable("parse")
45
- end
46
-
47
- it "should match exact reading" do
48
- parse %q{Boy is going out with Girl;}
49
- @asts.size.should == 1
50
- side_effects = match_readings_to_existing(@asts[0], @simple_ft.all_reading.single)
51
- side_effects[0].should_not be_nil
52
- side_effects.to_s.should == '[side-effects are [{Boy} absorbs 0/0 at 0, {Girl} absorbs 0/0 at 5]]'
53
- end
54
-
55
- it "should match with explicit leading adjective" do
56
- parse %q{Boy dislikes ugly-Girl;}
57
- @asts.size.should == 1
58
- side_effects = match_readings_to_existing(@asts[0], @ugly_ft.all_reading.single)
59
- side_effects[0].should_not be_nil
60
- side_effects.to_s.should == '[side-effects are [{Boy} absorbs 0/0 at 0, {ugly- Girl} absorbs 0/0 at 2]]'
61
- end
62
-
63
- it "should match with implicit leading adjective" do
64
- parse %q{Boy dislikes ugly Girl;}
65
- @asts.size.should == 1
66
- side_effects = match_readings_to_existing(@asts[0], @ugly_ft.all_reading.single)
67
- side_effects[0].should_not be_nil
68
- side_effects.to_s.should == '[side-effects are [{Boy} absorbs 0/0 at 0, {Girl} absorbs 1/0 at 3]]'
69
- end
70
-
71
- it "should match with local leading adjective" do
72
- parse %q{
73
- bad-Boy is going out with Girl,
74
- Girl likes bad-Boy; // New reading, no match expected, but must use residual adjective
75
- }
76
- @asts.size.should == 1
77
- side_effects = match_readings_to_existing(@asts[0], @simple_ft.all_reading.single)
78
- side_effects.size.should == 2
79
- side_effects[0].should_not be_nil
80
- side_effects[1].should be_nil
81
- skip side_effects[0].to_s
82
- side_effects[0].to_s.should == '[{bad- Boy} absorbs 0/0 at 0 with residual adjectives, {Girl} absorbs 0/0 at 5] with residual adjectives'
83
- #side_effects[1].to_s.should == ''
84
- end
85
-
86
- it "should match with explicit and local leading adjective" do
87
- parse %q{
88
- Boy dislikes nasty- ugly Girl,
89
- nasty- Girl likes Boy; // New reading, no match expected, but must use residual adjective
90
- }
91
- @asts.size.should == 1
92
- side_effects = match_readings_to_existing(@asts[0], @ugly_ft.all_reading.single)
93
- side_effects.size.should == 2
94
- skip "Matched adjectives must be removed and the role rebound before deciding whether residual adjectives have a purpose" do
95
- side_effects[0].should_not be_nil
96
- puts side_effects[0].to_s
97
- #side_effects.to_s.should == ''
98
- end
99
- end
100
-
101
- # Trailing adjectives
102
- it "should match with explicit trailing adjective" do
103
- parse %q{Boy-monster hurts Girl;}
104
- @asts.size.should == 1
105
- side_effects = match_readings_to_existing(@asts[0], @hurts_ft.all_reading.single)
106
- skip "Thinks trailing adjectives are always residual"
107
- side_effects[0].should_not be_nil
108
- side_effects[0].to_s.should == ''
109
- end
110
-
111
- it "should match with implicit trailing adjective" do
112
- parse %q{Boy monster hurts Girl;}
113
- @asts.size.should == 1
114
- side_effects = match_readings_to_existing(@asts[0], @hurts_ft.all_reading.single)
115
- side_effects[0].should_not be_nil
116
- side_effects.to_s.should == '[side-effects are [{Boy} absorbs 0/1 at 0, {Girl} absorbs 0/0 at 3]]'
117
- end
118
-
119
- it "should match with local trailing adjective" do
120
- parse %q{
121
- Boy is going out with Girl-troublemaker,
122
- Girl troublemaker likes Boy;
123
- }
124
- @asts.size.should == 1
125
- side_effects = match_readings_to_existing(@asts[0], @simple_ft.all_reading.single)
126
- side_effects.size.should == 2
127
- side_effects[0].should_not be_nil
128
- side_effects.to_s.should == '[side-effects are [{Boy} absorbs 0/0 at 0, {Girl -troublemaker} absorbs 0/0 at 5 with residual adjectives] with residual adjectives, nil]'
129
- end
130
-
131
- it "should match with explicit and local trailing adjective" do
132
- parse %q{
133
- Boy monster -foo hurts Girl,
134
- Girl likes Boy foo;
135
- }
136
- @asts.size.should == 1
137
- side_effects = match_readings_to_existing(@asts[0], @hurts_ft.all_reading.single)
138
- side_effects.size.should == 2
139
-
140
- skip "Matched adjectives must be removed and the role rebound before deciding whether residual adjectives have a purpose" do
141
- side_effects[0].should_not be_nil
142
- puts side_effects.to_s
143
- # side_effects.to_s.should == ''
144
- end
145
- end
146
-
147
- end
148
- end
@@ -1,244 +0,0 @@
1
- #
2
- # ActiveFacts tests: Test the CQL parser by looking at its parse trees.
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- require 'activefacts/support'
7
- require 'activefacts/api/support'
8
- require 'activefacts/input/cql'
9
-
10
- require 'set'
11
-
12
- describe "Sample data" do
13
- SamplePrefix = %q{
14
- vocabulary V;
15
-
16
- Company Name is written as String;
17
- Date is written as Date;
18
- Company is identified by its Name;
19
- Person is identified by its Name where Person is called Person Name;
20
- Directorship is where
21
- Company is directed by Person;
22
- Directorship began on appointment-Date;
23
- }
24
-
25
- GoodSamples = [
26
- [ # A simple ValueType instance
27
- "Company Name 'Microsoft';",
28
- [{:facts=>Set[], :instances=>Set["Company Name 'Microsoft'"]}]
29
- ],
30
- [ # Re-assert the same instance
31
- "Company Name 'Microsoft'; Company Name 'Microsoft';",
32
- [{:facts=>Set[], :instances=>Set["Company Name 'Microsoft'"]}]
33
- ],
34
- [ # The same instance, but in a named population
35
- "example: Company Name 'Microsoft';",
36
- [{:facts=>Set[], :instances=>Set["Company Name 'Microsoft'"]}]
37
- ],
38
- [ # A simply-identified EntityType instance
39
- "Company 'Microsoft';",
40
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
41
- ],
42
- [ # Re-assert the same instance
43
- "Company 'Microsoft'; Company 'Microsoft';",
44
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
45
- ],
46
- [ # The same instance in a named population
47
- "example: Company 'Microsoft';",
48
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
49
- ],
50
- [ # The Company instance asserted with an explicit identifying fact
51
- "Company has Company Name 'Microsoft';",
52
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
53
- ],
54
- [ # The Company instance asserted with a related identifying instance
55
- "Company has Company Name, Company Name 'Microsoft';",
56
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
57
- ],
58
- [ # The same, with an explicit identifying value step
59
- "Company Name 'Microsoft', Company has Company Name;",
60
- [{:facts=>Set["Company has Company Name 'Microsoft'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'"]}]
61
- ],
62
- [ # A simple fact instance with two simply-identified entities
63
- "Company 'Microsoft' is directed by Person 'Gates';",
64
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Person is called Person Name 'Gates'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person is identified by Person Name where Person is called Person Name 'Gates'", "Person Name 'Gates'"]}]
65
- ],
66
- [ # Same with an explicit joined fact
67
- "Company 'Microsoft' is directed by Person, Person is called Person Name 'Gates';",
68
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Person is called Person Name 'Gates'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person is identified by Person Name where Person is called Person Name 'Gates'", "Person Name 'Gates'"]}]
69
- ],
70
- [ # Same with explicitly joined facts and instances
71
- "Company is directed by Person, Person is called Person Name, Person Name 'Gates', Company has Company Name, Company Name 'Microsoft';",
72
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Person is called Person Name 'Gates'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person is identified by Person Name where Person is called Person Name 'Gates'", "Person Name 'Gates'"]}]
73
- ],
74
- [ # Same in a named population
75
- "example: Company is directed by Person, Person is called Person Name, Person Name 'Gates', Company has Company Name, Company Name 'Microsoft';",
76
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Person is called Person Name 'Gates'"], :instances=>Set["Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person is identified by Person Name where Person is called Person Name 'Gates'", "Person Name 'Gates'"]}]
77
- ],
78
-
79
- # Objectification examples
80
- [
81
- "Directorship (where Company 'Microsoft' is directed by Person 'Gates');",
82
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Person is called Person Name 'Gates'"], :instances=>Set["Person is identified by Person Name where Person is called Person Name 'Gates'", "Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person Name 'Gates'"]}]
83
- ],
84
- [
85
- "Directorship (where Company 'Microsoft' is directed by Person 'Gates') began on appointment Date '20/02/1981';",
86
- [{:facts=>Set["Company has Company Name 'Microsoft'", "Company is directed by Person", "Directorship began on appointment-Date '20/02/1981'", "Person is called Person Name 'Gates'"], :instances=>Set["Person is identified by Person Name where Person is called Person Name 'Gates'", "Company is identified by Company Name where Company has Company Name 'Microsoft'", "Company Name 'Microsoft'", "Directorship where Company is directed by Person", "Person Name 'Gates'", "Date '20/02/1981'"]}]
87
- ],
88
- ]
89
-
90
- BadSamples =
91
- [
92
- [
93
- "Company Name",
94
- "Company Name",
95
- ],
96
- [
97
- "foo: Company Name",
98
- "Company Name",
99
- ],
100
- [ # Omit the company name:
101
- "example: Company is directed by Person, Person is called Person Name, Person Name 'Gates', Company has Company Name;",
102
- [ "Company (lacking Company Name)", "Company Name (needs a value)" ]
103
- ],
104
- ]
105
-
106
- def render_value v
107
- if v.to_s !~ /[^-+0-9.]/ and (n = eval(v.to_s) rescue nil)
108
- n
109
- else
110
- v.to_s
111
- end
112
- end
113
-
114
- # REVISIT: This code does a better job than verbalise. Consider incorporating it?
115
- def instance_name(i)
116
- if i.is_a?(ActiveFacts::Metamodel::Fact)
117
- fact = i
118
- reading = fact.fact_type.preferred_reading
119
- reading_roles = reading.role_sequence.all_role_ref.sort_by{|rr| rr.ordinal}.map{|rr| rr.role }
120
- role_values_in_reading_order = fact.all_role_value.sort_by{|rv| reading_roles.index(rv.role) }
121
- instance_verbalisations = role_values_in_reading_order.map do |rv|
122
- next nil unless v = rv.instance.value
123
- render_value(v)
124
- end
125
- return reading.expand([], false, instance_verbalisations)
126
- # REVISIT: Include the instance_names of all role players
127
- end
128
-
129
- if i.object_type.is_a?(ActiveFacts::Metamodel::ValueType)
130
- return "#{i.object_type.name} #{render_value(i.value)}"
131
- end
132
-
133
- if i.object_type.fact_type # An instance of an objectified fact type
134
- return "#{i.object_type.name} where #{instance_name(i.fact)}"
135
- end
136
-
137
- # It's an entity that's not an objectified fact type
138
- # REVISIT: If it has a simple identifier, there's no need to fully verbalise the identifying facts
139
- pi = i.object_type.preferred_identifier
140
- identifying_role_refs = pi.role_sequence.all_role_ref.sort_by{|rr| rr.ordinal}
141
- return "#{i.object_type.name}" +
142
- " is identified by " +
143
- identifying_role_refs.map do |rr|
144
- [ (l = rr.leading_adjective) ? l+"-" : nil,
145
- rr.role.role_name || rr.role.object_type.name,
146
- (t = rr.trailing_adjective) ? l+"-" : nil
147
- ].compact*""
148
- end * " and " +
149
- " where " +
150
- identifying_role_refs.map do |rr| # Go through the identifying roles and emit the facts that define them
151
- instance_role = i.object_type.all_role.detect{|r| r.fact_type == rr.role.fact_type}
152
- identifying_fact = i.all_role_value.detect{|rv| rv.fact.fact_type == rr.role.fact_type}.fact
153
- #counterpart_role = (rr.role.fact_type.all_role.to_a-[instance_role])[0]
154
- #identifying_instance = counterpart_role.all_role_value.detect{|rv| rv.fact == identifying_fact}.instance
155
- instance_name(identifying_fact)
156
- end*", "
157
- end
158
-
159
- def instance_data(populations)
160
- populations = @vocabulary.constellation.Population
161
- populations.keys.sort.map do |popname|
162
- popvalue = populations[popname]
163
- {
164
- :instances => Set[*popvalue.all_instance.map { |i| instance_name(i) }],
165
- :facts => Set[*popvalue.all_fact.map { |fact| instance_name(fact) }]
166
- }
167
- end
168
- end
169
-
170
- # [].
171
- GoodSamples.
172
- each do |c|
173
- source, expected = *Array(c)
174
-
175
- it "should handle #{source.inspect}" do
176
- @text = SamplePrefix+source
177
- #pending if expected == [:pending]
178
- exception = nil
179
- lambda do
180
- begin
181
- @vocabulary = ActiveFacts::Input::CQL.readstring(@text)
182
- @vocabulary.finalise
183
- rescue => exception
184
- if trace :exception
185
- puts "#{exception.message}"
186
- puts "\t#{exception.backtrace*"\n\t"}"
187
- end
188
- raise
189
- end
190
- end.should_not raise_error
191
- result = instance_data(@vocabulary)
192
-
193
- if expected
194
- result[0].should == expected[0]
195
- else
196
- pending "#{source}:\n\t#{result.inspect}"
197
- end
198
- end
199
-
200
- it "should de-duplicate #{source.inspect}" do
201
- # Make sure you don't get anything duplicated
202
- @text = SamplePrefix+source+source
203
- #pending if expected == [:pending]
204
- exception = nil
205
- lambda do
206
- begin
207
- @vocabulary = ActiveFacts::Input::CQL.readstring(@text)
208
- rescue => exception
209
- if trace :exception
210
- puts "#{exception.message}"
211
- puts "\t#{exception.backtrace*"\n\t"}"
212
- end
213
- raise
214
- end
215
- end.should_not raise_error
216
- result = instance_data(@vocabulary)
217
- result[0].should == expected[0]
218
- end
219
-
220
- end
221
-
222
- BadSamples.each do |c|
223
- source, missing = *Array(c)
224
- it "should detect missing queries in #{source.inspect}" do
225
- @text = SamplePrefix+source
226
- lambda do
227
- begin
228
- @vocabulary = ActiveFacts::Input::CQL.readstring(@text)
229
- rescue => @exception
230
- raise
231
- end
232
- end.should raise_error
233
-
234
- if missing
235
- Array(missing).each do |m|
236
- @exception.message.should =~ (m.is_a?(Regexp) ? m : Regexp.new(Regexp.escape(m)))
237
- end
238
- else
239
- pending "raised #{@exception}"
240
- end
241
- end
242
- end
243
-
244
- end