activefacts 0.8.9 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gemtest +0 -0
  2. data/Manifest.txt +28 -33
  3. data/Rakefile +11 -12
  4. data/bin/cql +90 -46
  5. data/examples/CQL/Blog.cql +2 -1
  6. data/examples/CQL/CompanyDirectorEmployee.cql +2 -2
  7. data/examples/CQL/Death.cql +1 -1
  8. data/examples/CQL/Diplomacy.cql +9 -9
  9. data/examples/CQL/Genealogy.cql +3 -2
  10. data/examples/CQL/Insurance.cql +10 -7
  11. data/examples/CQL/JoinEquality.cql +2 -2
  12. data/examples/CQL/Marriage.cql +1 -1
  13. data/examples/CQL/Metamodel.cql +73 -53
  14. data/examples/CQL/MetamodelNext.cql +89 -67
  15. data/examples/CQL/OneToOnes.cql +2 -2
  16. data/examples/CQL/ServiceDirector.cql +10 -5
  17. data/examples/CQL/Supervision.cql +3 -3
  18. data/examples/CQL/Tests.Test5.Load.cql +1 -1
  19. data/examples/CQL/Warehousing.cql +4 -2
  20. data/lib/activefacts/cql/CQLParser.treetop +26 -60
  21. data/lib/activefacts/cql/Context.treetop +12 -2
  22. data/lib/activefacts/cql/Expressions.treetop +14 -30
  23. data/lib/activefacts/cql/FactTypes.treetop +165 -110
  24. data/lib/activefacts/cql/Language/English.treetop +167 -54
  25. data/lib/activefacts/cql/LexicalRules.treetop +16 -2
  26. data/lib/activefacts/cql/{Concepts.treetop → ObjectTypes.treetop} +36 -37
  27. data/lib/activefacts/cql/Terms.treetop +57 -27
  28. data/lib/activefacts/cql/ValueTypes.treetop +39 -13
  29. data/lib/activefacts/cql/compiler.rb +5 -3
  30. data/lib/activefacts/cql/compiler/{reading.rb → clause.rb} +407 -285
  31. data/lib/activefacts/cql/compiler/constraint.rb +178 -275
  32. data/lib/activefacts/cql/compiler/entity_type.rb +73 -64
  33. data/lib/activefacts/cql/compiler/expression.rb +418 -0
  34. data/lib/activefacts/cql/compiler/fact.rb +146 -145
  35. data/lib/activefacts/cql/compiler/fact_type.rb +197 -80
  36. data/lib/activefacts/cql/compiler/join.rb +159 -0
  37. data/lib/activefacts/cql/compiler/shared.rb +51 -23
  38. data/lib/activefacts/cql/compiler/value_type.rb +56 -2
  39. data/lib/activefacts/cql/parser.rb +15 -4
  40. data/lib/activefacts/generate/absorption.rb +7 -7
  41. data/lib/activefacts/generate/cql.rb +100 -37
  42. data/lib/activefacts/generate/oo.rb +28 -51
  43. data/lib/activefacts/generate/ordered.rb +60 -36
  44. data/lib/activefacts/generate/ruby.rb +6 -6
  45. data/lib/activefacts/generate/sql/server.rb +4 -4
  46. data/lib/activefacts/input/orm.rb +71 -53
  47. data/lib/activefacts/persistence.rb +1 -1
  48. data/lib/activefacts/persistence/columns.rb +27 -23
  49. data/lib/activefacts/persistence/foreignkey.rb +6 -6
  50. data/lib/activefacts/persistence/index.rb +17 -17
  51. data/lib/activefacts/persistence/{concept.rb → object_type.rb} +9 -9
  52. data/lib/activefacts/persistence/reference.rb +61 -36
  53. data/lib/activefacts/persistence/tables.rb +61 -59
  54. data/lib/activefacts/support.rb +54 -29
  55. data/lib/activefacts/version.rb +1 -1
  56. data/lib/activefacts/vocabulary/extensions.rb +99 -54
  57. data/lib/activefacts/vocabulary/metamodel.rb +43 -37
  58. data/lib/activefacts/vocabulary/verbaliser.rb +134 -109
  59. data/spec/absorption_spec.rb +8 -8
  60. data/spec/cql/comparison_spec.rb +91 -0
  61. data/spec/cql/contractions_spec.rb +251 -0
  62. data/spec/cql/entity_type_spec.rb +319 -0
  63. data/spec/cql/expressions_spec.rb +63 -0
  64. data/spec/cql/fact_type_matching_spec.rb +283 -0
  65. data/spec/cql/french_spec.rb +21 -0
  66. data/spec/cql/parser/bad_literals_spec.rb +86 -0
  67. data/spec/cql/parser/constraints_spec.rb +19 -0
  68. data/spec/cql/parser/entity_types_spec.rb +106 -0
  69. data/spec/cql/parser/expressions_spec.rb +179 -0
  70. data/spec/cql/parser/fact_types_spec.rb +41 -0
  71. data/spec/cql/parser/literals_spec.rb +312 -0
  72. data/spec/cql/parser/pragmas_spec.rb +89 -0
  73. data/spec/cql/parser/value_types_spec.rb +42 -0
  74. data/spec/cql/role_matching_spec.rb +147 -0
  75. data/spec/cql/samples_spec.rb +9 -9
  76. data/spec/cql_cql_spec.rb +1 -1
  77. data/spec/cql_dm_spec.rb +116 -0
  78. data/spec/cql_mysql_spec.rb +1 -1
  79. data/spec/cql_ruby_spec.rb +1 -1
  80. data/spec/cql_sql_spec.rb +3 -3
  81. data/spec/cql_symbol_tables_spec.rb +30 -30
  82. data/spec/cqldump_spec.rb +4 -4
  83. data/spec/helpers/array_matcher.rb +32 -27
  84. data/spec/helpers/diff_matcher.rb +6 -26
  85. data/spec/helpers/file_matcher.rb +41 -32
  86. data/spec/helpers/parse_to_ast_matcher.rb +76 -0
  87. data/spec/helpers/string_matcher.rb +32 -31
  88. data/spec/norma_cql_spec.rb +1 -1
  89. data/spec/norma_ruby_spec.rb +1 -1
  90. data/spec/norma_ruby_sql_spec.rb +1 -1
  91. data/spec/norma_sql_spec.rb +3 -1
  92. data/spec/norma_tables_spec.rb +1 -1
  93. data/spec/ruby_api_spec.rb +23 -0
  94. data/spec/spec_helper.rb +5 -4
  95. metadata +66 -66
  96. data/examples/CQL/OrienteeringER.cql +0 -58
  97. data/lib/activefacts/api.rb +0 -44
  98. data/lib/activefacts/api/concept.rb +0 -410
  99. data/lib/activefacts/api/constellation.rb +0 -128
  100. data/lib/activefacts/api/entity.rb +0 -256
  101. data/lib/activefacts/api/instance.rb +0 -60
  102. data/lib/activefacts/api/instance_index.rb +0 -80
  103. data/lib/activefacts/api/numeric.rb +0 -167
  104. data/lib/activefacts/api/role.rb +0 -80
  105. data/lib/activefacts/api/role_proxy.rb +0 -70
  106. data/lib/activefacts/api/role_values.rb +0 -117
  107. data/lib/activefacts/api/standard_types.rb +0 -87
  108. data/lib/activefacts/api/support.rb +0 -65
  109. data/lib/activefacts/api/value.rb +0 -135
  110. data/lib/activefacts/api/vocabulary.rb +0 -82
  111. data/spec/api/autocounter.rb +0 -82
  112. data/spec/api/constellation.rb +0 -130
  113. data/spec/api/entity_type.rb +0 -103
  114. data/spec/api/instance.rb +0 -461
  115. data/spec/api/roles.rb +0 -124
  116. data/spec/api/value_type.rb +0 -112
  117. data/spec/api_spec.rb +0 -13
  118. data/spec/cql/matching_spec.rb +0 -517
  119. data/spec/cql/unit_spec.rb +0 -394
  120. data/spec/spec.opts +0 -1
@@ -1,394 +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
- =begin
7
- REVISIT: These tests are important, but the intermediate layer they test no longer exists. Find another solution!
8
-
9
- require 'spec/helpers/test_parser'
10
- require 'activefacts/support'
11
- require 'activefacts/api/support'
12
- require 'activefacts/cql/parser'
13
- require File.dirname(__FILE__) + '/../helpers/test_parser'
14
-
15
- describe "Valid Numbers, Strings and Ranges" do
16
- ValidNumbersEtc = [
17
- "a is written as b;", # Value type declaration, no params, minimal whitespace
18
- "a is written as B;", # Value type declaration, no params, minimal whitespace
19
- "a is written as b();", # Value type declaration, minimal whitespace
20
- "a is written as b ;", # Value type declaration, no params, trailing whitespace
21
- "a is written as b ( ) ; ", # Value type declaration, maximal whitespace
22
-
23
- # Comments and newlines, etc as whitespace
24
- "\na\nis written as \nb\n(\n)\n;\n", # Basic value type declaration, newlines for whitespace
25
- "\ra\ris written as\rb\r(\r)\r;\r", # Basic value type declaration, returns for whitespace
26
- "\ta\tis written as\tb\t(\t)\t;\t", # Basic value type declaration, tabs for whitespace
27
- " /* Plugh */ a /* Plugh */ is written as\n b /* *Plugh* / */ ( /* *Plugh* / */ ) /* *Plugh* / */ ; /* *Plugh* / */ ",
28
- "//Plugh\na // Plugh\n is written as // Plugh\n b // Plugh\n ( // Plugh\n ) // Plugh\n ; // Plugh\n ",
29
-
30
- # Integers
31
- "a is written as b(0);", # Integer zero
32
- "a is written as b( 0 ) ; ", # Integer zero, maximal whitespace
33
- "a is written as b(1);", # Integer one
34
- "a is written as b(-1);", # Integer negative one
35
- "a is written as b(+1);", # Positive integer
36
- "a is written as b(1e4);", # Integer with exponent
37
- "a is written as b(1e-4);", # Integer with negative exponent
38
- "a is written as b(-1e-4);", # Negative integer with negative exponent
39
- "a is written as b(077);", # Octal integer
40
- "a is written as b(0xFace8);", # Hexadecimal integer
41
- "a is written as b(0,1);", # Two parameters
42
- "a is written as b( 0 , 1 );",
43
- "a is written as b(0,1,2) ;", # Three parameters now allowed
44
-
45
- # Reals
46
- "a is written as b(1.0);",
47
- "a is written as b(-1.0);",
48
- "a is written as b(+1.0);",
49
- "a is written as b(0.1);",
50
- "a is written as b(-0.1);",
51
- "a is written as b(+0.1);",
52
- "a is written as b(0.0);",
53
- "a is written as b(-0.0);",
54
- "a is written as b(+0.0);",
55
-
56
- # Value types with units
57
- "a is written as b inch;", # Value type declaration with unit
58
- "a is written as b() inch ; ", # Value type declaration with unit and whitespace
59
- "a is written as b() inch;", # Value type declaration with unit
60
- "a is written as b inch^2;", # Value type declaration with unit and exponent
61
- "a is written as b() inch^2 ; ", # Value type declaration with unit and exponent with maximum whitespace
62
- "a is written as b second^-1;", # Value type declaration with unit and negative exponent
63
- "a is written as b inch inch;", # Value type declaration with repeated unit
64
- "a is written as b inch^2/minute^-1;", # Value type declaration with unit and divided unit with exponents
65
- "a is written as b() second^-1/mm^-1 mm^-1;", # Value type declaration with repeated divided unit
66
-
67
- # Integer value constraints
68
- "a is written as b()restricted to{1};", # Integer, minimal whitespace
69
- "a is written as b() restricted to { 1 } ;", # Integer, maximal whitespace
70
- "a is written as b() restricted to {1..2};", # Integer range, minimal whitespace
71
- "a is written as b() restricted to { 1 .. 2 };", # Integer range, maximal whitespace
72
- "a is written as b() restricted to {..2};", # Integer range with open start, minimal whitespace
73
- "a is written as b() restricted to { .. 2 };", # Integer range with open start, maximal whitespace
74
- "a is written as b() restricted to { ..2,3};", # Range followed by integer, minimal whitespace
75
- "a is written as b() restricted to { 1,..2,3};", # Integer, open-start range, integer, minimal whitespace
76
- "a is written as b() restricted to { .. 2 , 3 };", # Range followed by integer, maximal whitespace
77
- "a is written as b() restricted to { ..2 , 3..4 };",# Range followed by range
78
- "a is written as b() restricted to { ..2, 3..};", # Range followed by range with open end, minimal whitespace
79
- "a is written as b() restricted to { ..2, 3 .. };", # Range followed by range with open end, maximal whitespace
80
- "a is written as b() restricted to { 1e4 } ;", # Integer with exponent
81
- "a is written as b() restricted to { -1e4 } ;", # Negative integer with exponent
82
- "a is written as b() restricted to { 1e-4 } ;", # Integer with negative exponent
83
- "a is written as b() restricted to { -1e-4 } ;", # Negative integer with negative exponent
84
-
85
- # Real value constraints
86
- "a is written as b() restricted to {1.0};", # Real, minimal whitespace
87
- "a is written as b() restricted to { 1.0 } ;", # Real, maximal whitespace
88
- "a is written as b() restricted to { 1.0e4 } ;", # Real with exponent
89
- "a is written as b() restricted to { 1.0e-4 } ;", # Real with negative exponent
90
- "a is written as b() restricted to { -1.0e-4 } ;", # Negative real with negative exponent
91
- "a is written as b() restricted to { 1.1 .. 2.2 } ;", # Real range, maximal whitespace
92
- "a is written as b() restricted to { -1.1 .. 2.2 } ;", # Real range, maximal whitespace
93
- "a is written as b() restricted to { 1.1..2.2};", # Real range, minimal whitespace
94
- "a is written as b() restricted to { 1.1..2 } ;", # Real-integer range
95
- "a is written as b() restricted to { 1..2.2 } ;", # Integer-real range
96
- "a is written as b() restricted to { ..2.2};", # Real range with open start
97
- "a is written as b() restricted to { 1.1.. };", # Real range with open end
98
- "a is written as b() restricted to { 1.1.., 2 };", # Real range with open end and following integer
99
-
100
- # Strings and string value constraints
101
- "a is written as b() restricted to {''};", # String, empty, minimal whitespace
102
- "a is written as b() restricted to {'A'};", # String, minimal whitespace
103
- "a is written as b() restricted to { 'A' };", # String, maximal whitespace
104
- "a is written as b() restricted to { '\\b\\t\\f\\n\\r\\e\\\\' };", # String with special escapes
105
- "a is written as b() restricted to { ' ' };", # String with space
106
- "a is written as b() restricted to { '\t' };", # String with literal tab
107
- "a is written as b() restricted to { '\\0' };", # String with nul character
108
- "a is written as b() restricted to { '\\077' };", # String with octal escape
109
- "a is written as b() restricted to { '\\0xA9' };", # String with hexadecimal escape
110
- "a is written as b() restricted to { '\\0uBabe' };",# String with unicode escape
111
- "a is written as b() restricted to {'A'..'F'};", # String range, minimal whitespace
112
- "a is written as b() restricted to { 'A' .. 'F' };",# String range, maximal whitespace
113
- "a is written as b() restricted to { ..'F' };", # String range, open start
114
- "a is written as b() restricted to { 'A'.. };", # String range, open end
115
-
116
- # Value constraints with units
117
- "a is written as b() restricted to {1} inches^2/second;", # constraint with units and exponent
118
- "a is written as b() second^-1/mm^-1 mm^-1 restricted to {1} inches^2/second;", # type with unit and constraint with units and exponent
119
- ]
120
-
121
- before :each do
122
- @parser = TestParser.new
123
- end
124
-
125
- ValidNumbersEtc.each do |c|
126
- source, ast = *[c].flatten
127
- it "should parse #{source.inspect}" do
128
- result = @parser.parse_all(source, :definition)
129
-
130
- puts @parser.failure_reason unless result
131
- result.should_not be_nil
132
- result.map{|d| d.value}.should == ast if ast
133
- # puts result.map{|d| d.value}.inspect unless ast
134
- end
135
- end
136
- end
137
-
138
- describe "Invalid Numbers and Strings" do
139
- InvalidValueTypes = [
140
- "a is written as b(08);", # Invalid octalnumber
141
- "a is written as b(0xDice);", # Invalid hexadecimal
142
- "a is written as b(- 1);", # Invalid negative
143
- "a is written as b(+ 1);", # Invalid positive
144
- "b(- 1e-4);", # Negative integer with negative exponent
145
- "a is written as b(-077);", # Invalid negative octal
146
- "a is written as b(-0xFace);", # Invalid negative hexadecimal
147
- "a is written as b(.0);", # Invalid real
148
- "a is written as b(0.);", # Invalid real
149
- "b() inch ^2 ; ", # Illegal whitespace around unit exponent
150
- "b() inch^ 2 ; ", # Illegal whitespace around unit exponent
151
- "b() restricted to { '\\7a' };", # String with bad octal escape
152
- "b() restricted to { '\001' };", # String with control char
153
- "b() restricted to { '\n' };", # String with literal newline
154
- "b() restricted to { 0..'A' };", # Cross-typed range
155
- "b() restricted to { 'a'..27 };", # Cross-typed range
156
- ]
157
-
158
- before :each do
159
- @parser = TestParser.new
160
- end
161
-
162
- InvalidValueTypes.each do |c|
163
- source, ast = *c
164
- it "should not parse #{source.inspect}" do
165
- result = @parser.parse_all(source, :definition)
166
-
167
- # puts @parser.failure_reason unless result.success?
168
- result.should be_nil
169
- end
170
- end
171
- end
172
-
173
- describe "Value Types" do
174
- ValueTypes = [
175
- [ "a is written as b(1, 2) inch restricted to { 3 .. 4 } inch ;",
176
- [["a", [:value_type, "b", [1, 2], [["inch", 1]], [[3, 4]], [], []]]]
177
- ],
178
- # [ "a c is written as b(1, 2) inch restricted to { 3 .. 4 } inch ;",
179
- # [["a c", [:value_type, "b", [1, 2], "inch", [[3, 4]]]]]
180
- # ],
181
- ]
182
-
183
- before :each do
184
- @parser = TestParser.new
185
- end
186
-
187
- ValueTypes.each do |c|
188
- source, ast = *c
189
- it "should parse #{source.inspect}" do
190
- result = @parser.parse_all(source, :definition)
191
-
192
- puts @parser.failure_reason unless result
193
- result.should_not be_nil
194
-
195
- result.map{|d| d.value}.should == ast if ast
196
- puts result.map{|d| d.value}.inspect unless ast
197
- end
198
- end
199
- end
200
-
201
- describe "Entity Types" do
202
- EntityTypes_RefMode = [
203
- [ "a is identified by its id;", # Entity type declaration with reference mode
204
- [["a", [:entity_type, [], {:enforcement=>nil, :mode=>"id", :parameters=>[], :value_constraint=>nil}, [], nil]]]
205
- ],
206
- [ "a is identified by its number(12);", # Entity type declaration with reference mode
207
- [["a", [:entity_type, [], {:enforcement=>nil, :mode=>"number", :parameters=>[12], :value_constraint=>nil}, [], nil]]]
208
- ],
209
- [ "a is identified by its id:c;", # Entity type declaration with reference mode and fact type(s)
210
- [["a", [:entity_type, [], {:enforcement=>nil, :mode=>"id", :parameters=>[], :value_constraint=>nil}, [], [[:fact_clause, [], ["c"], nil]]]]]
211
- ],
212
- [ "a is identified by its id where c;", # Entity type declaration with reference mode and where
213
- [["a", [:entity_type, [], {:enforcement=>nil, :mode=>"id", :parameters=>[], :value_constraint=>nil}, [], [[:fact_clause, [], ["c"], nil]]]]]
214
- ],
215
- ]
216
-
217
- EntityTypes_Simple = [
218
- [ "a is identified by b: c;", # Entity type declaration
219
- [["a", [:entity_type, [], {:roles=>[["b"]]}, [], [[:fact_clause, [], ["c"], nil]]]]]
220
- ],
221
- [ "a is identified by b where c;", # Entity type declaration with where
222
- [["a", [:entity_type, [], {:roles=>[["b"]]}, [], [[:fact_clause, [], ["c"], nil]]]]]
223
- ],
224
- [ "a is identified by b and c: d;", # Entity type declaration with two-part identifier
225
- [["a", [:entity_type, [], {:roles=>[["b"], ["c"]]}, [], [[:fact_clause, [], ["d"], nil]]]]]
226
- ],
227
- [ "a is identified by b, c: d;", # Entity type declaration with two-part identifier
228
- [["a", [:entity_type, [], {:roles=>[["b"], ["c"]]}, [], [[:fact_clause, [], ["d"], nil]]]]]
229
- ],
230
- [ "a is written as b(); c is identified by a:d;",
231
- [["a", [:value_type, "b", [], [], [], [], nil]], ["c", [:entity_type, [], {:roles=>[["a"]]}, [], [[:fact_clause, [], ["d"], nil]]]]]
232
- ],
233
- [ " a is written as b ( ) ; c is identified by a : d ; ",
234
- [["a", [:value_type, "b", [], [], [], [], nil]], ["c", [:entity_type, [], {:roles=>[["a"]]}, [], [[:fact_clause, [], ["d"], nil]]]]]
235
- ],
236
- [ "a is identified by c:maybe d;",
237
- [["a", [:entity_type, [], {:roles=>[["c"]]}, [], [[:fact_clause, ["maybe"], ["d"], nil]]]]]
238
- ],
239
- ]
240
-
241
- EntityTypes_Objectified = [
242
- [ "Director is where Person directs Company, Company is directed by Person;",
243
- [["Director", [:fact_type, [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "directs", {:word=>"Company", :term=>"Company"}], nil], [:fact_clause, [], [{:word=>"Company", :term=>"Company"}, "is", "directed", "by", {:word=>"Person", :term=>"Person"}], nil]], []]]]
244
- ],
245
- [ "Director: Person directs company;",
246
- [[nil, [:fact_type, [[:fact_clause, [], [{:word=>"Director", :term=>"Director"}], nil]], [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "directs", "company"], nil]]]]]
247
- ],
248
- ]
249
-
250
- EntityTypes_Subtypes = [
251
- [ "Employee is a kind of Person;",
252
- [["Employee", [:entity_type, ["Person"], nil, [], nil]]]
253
- ],
254
- [ "Employee is a subtype of Person;",
255
- [["Employee", [:entity_type, ["Person"], nil, [], nil]]]
256
- ],
257
- [ "AustralianEmployee is a subtype of Employee, Australian;",
258
- [["AustralianEmployee", [:entity_type, ["Employee", "Australian"], nil, [], nil]]]
259
- ],
260
- [ "Employee is a kind of Person identified by EmployeeNumber;",
261
- [["Employee", [:entity_type, ["Person"], {:roles=>[["EmployeeNumber"]]}, [], nil]]]
262
- ],
263
- [ "Employee is a subtype of Person identified by EmployeeNumber;",
264
- [["Employee", [:entity_type, ["Person"], {:roles=>[["EmployeeNumber"]]}, [], nil]]]
265
- ],
266
- [ "AustralianEmployee is a subtype of Employee, Australian identified by TaxFileNumber;",
267
- [["AustralianEmployee", [:entity_type, ["Employee", "Australian"], {:roles=>[["TaxFileNumber"]]}, [], nil]]]
268
- ],
269
- ]
270
-
271
- EntityTypes =
272
- EntityTypes_RefMode +
273
- EntityTypes_Simple +
274
- EntityTypes_Objectified +
275
- EntityTypes_Subtypes
276
-
277
- before :each do
278
- @parser = TestParser.new
279
- end
280
-
281
- EntityTypes.each do |c|
282
- source, ast = *c
283
- it "should parse #{source.inspect}" do
284
- result = @parser.parse_all(source, :definition)
285
-
286
- puts @parser.failure_reason unless result
287
-
288
- result.should_not be_nil
289
- if ast
290
- result.map{|d| d.value}.should == ast
291
- else
292
- puts "\n"+result.map{|d| d.value}.inspect
293
- end
294
- end
295
- end
296
- end
297
-
298
- describe "Fact Types" do
299
- FactTypes = [
300
- [ "Foo has at most one Bar, Bar is of one Foo restricted to {1..10};",
301
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"Foo", :term=>"Foo"}, "has", {:quantifier_restriction=>[], :word=>"Bar", :term=>"Bar", :quantifier=>[nil, 1]}], nil], [:fact_clause, [], [{:word=>"Bar", :term=>"Bar"}, "is", "of", {:value_constraint=>[[1, 10]], :quantifier_restriction=>[], :word=>"Foo", :term=>"Foo", :quantifier=>[1, 1], :value_constraint_enforcement=>[]}], nil]], []]]
302
- ],
303
- [ "Bar(1) is related to Bar(2), primary-Bar(1) has secondary-Bar(2);",
304
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"Bar", :term=>"Bar", :role_name=>1}, "is", "related", "to", {:word=>"Bar", :term=>"Bar", :role_name=>2}], nil], [:fact_clause, [], [{:leading_adjective=>"primary", :word=>"primary Bar", :term=>"Bar", :role_name=>1}, "has", {:leading_adjective=>"secondary", :word=>"secondary Bar", :term=>"Bar", :role_name=>2}], nil]], []]]
305
- ],
306
- [ "Director is old: Person directs company, Person is of Age, Age > 60;",
307
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"Director", :term=>"Director"}, "is", "old"], nil]], [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "directs", "company"], nil], [:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "is", "of", {:word=>"Age", :term=>"Age"}], nil], [">", [:variable, "Age"], 60]]]]
308
- ],
309
- [ "A is a farce: maybe A has completely- B [transitive, acyclic], B -c = 2;",
310
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"A", :term=>"A"}, "is", "a", "farce"], nil]], [[:fact_clause, ["maybe", "transitive", "acyclic"], [{:word=>"A", :term=>"A"}, "has", {:leading_adjective=>"completely", :word=>"completely B", :term=>"B"}], nil], ["=", [:variable, "B c"], 2]]]]
311
- ],
312
- [ "A is a farce: maybe A has completely- green B [transitive, acyclic], B -c = 2;",
313
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"A", :term=>"A"}, "is", "a", "farce"], nil]], [[:fact_clause, ["maybe", "transitive", "acyclic"], [{:word=>"A", :term=>"A"}, "has", {:leading_adjective=>"completely green", :word=>"completely green B", :term=>"B"}], nil], ["=", [:variable, "B c"], 2]]]]
314
- ],
315
- [ "A is a farce: maybe A has B green -totally [transitive, acyclic], B -c = 2;",
316
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"A", :term=>"A"}, "is", "a", "farce"], nil]], [[:fact_clause, ["maybe", "transitive", "acyclic"], [{:word=>"A", :term=>"A"}, "has", {:trailing_adjective=>"green totally", :word=>"B green totally", :term=>"B"}], nil], ["=", [:variable, "B c"], 2]]]]
317
- ],
318
- [ "Person is independent: Person has taxable- Income, taxable Income >= 20000 dollars;",
319
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "is", "independent"], nil]], [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "has", {:leading_adjective=>"taxable", :word=>"taxable Income", :term=>"Income"}], nil], [">=", [:variable, "taxable Income"], [20000, "dollars"]]]]]
320
- ],
321
- [ "Window requires toughening: Window has Width -mm, Window has Height -mm, Width mm * Height mm >= 10 foot^2;",
322
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"Window", :term=>"Window"}, "requires", "toughening"], nil]], [[:fact_clause, [], [{:word=>"Window", :term=>"Window"}, "has", {:trailing_adjective=>"mm", :word=>"Width mm", :term=>"Width"}], nil], [:fact_clause, [], [{:word=>"Window", :term=>"Window"}, "has", {:trailing_adjective=>"mm", :word=>"Height mm", :term=>"Height"}], nil], [">=", [:*, [:variable, "Width mm"], [:variable, "Height mm"]], [10, "foot^2"]]]]]
323
- ],
324
- # REVISIT: Test all quantifiers
325
- # REVISIT: Test all post-qualifiers
326
- # REVISIT: Test functions
327
- [ "AnnualIncome is where Person has total- Income in Year: Person has total- Income.sum(), Income was earned in current- Time.Year() (as Year);",
328
- ["AnnualIncome", [:fact_type, [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "has", {:leading_adjective=>"total", :word=>"total Income", :term=>"Income"}, "in", {:word=>"Year", :term=>"Year"}], nil]], [[:fact_clause, [], [{:word=>"Person", :term=>"Person"}, "has", {:leading_adjective=>"total", :function=>[:"(", "sum"], :word=>"total Income", :term=>"Income"}], nil], [:fact_clause, [], [{:word=>"Income", :term=>"Income"}, "was", "earned", "in", {:leading_adjective=>"current", :function=>[:"(", "Year"], :role_name=>"Year", :word=>"current Time", :term=>"Time"}], nil]]]]
329
- ],
330
- [ "A is interesting : b- C has F -g;",
331
- [nil, [:fact_type, [[:fact_clause, [], [{:word=>"A", :term=>"A"}, "is", "interesting"], nil]], [[:fact_clause, [], [{:leading_adjective=>"b", :word=>"b C", :term=>"C"}, "has", {:trailing_adjective=>"g", :word=>"F g", :term=>"F"}], nil]]]]
332
- ]
333
- ]
334
-
335
- before :each do
336
- @parser = TestParser.new
337
- end
338
-
339
- FactTypes.each do |c|
340
- source, ast, definition = *c
341
- it "should parse #{source.inspect}" do
342
- definitions = @parser.parse_all(source, :definition)
343
-
344
- puts @parser.failure_reason unless definitions
345
-
346
- definitions.should_not be_nil
347
- result = definitions[-1]
348
-
349
- if (definition)
350
- result.definition.should == definition
351
- else
352
- #p @parser.definition(result)
353
- end
354
-
355
- result.value.should == ast if ast
356
- puts result.map{|d| d.value}.inspect unless ast
357
- end
358
- end
359
- end
360
-
361
- describe "Constraint" do
362
- Constraints = [
363
- [ "each combination FamilyName, GivenName occurs at most one time in Competitor has FamilyName, Competitor has GivenName;",
364
- [nil, [:constraint, :presence, [["FamilyName"], ["GivenName"]], [nil, 1], [[[{:word=>"Competitor", :term=>"Competitor"}, "has", {:word=>"FamilyName", :term=>"FamilyName"}]], [[{:word=>"Competitor", :term=>"Competitor"}, "has", {:word=>"GivenName", :term=>"GivenName"}]]], nil, []]]
365
- ],
366
- ]
367
-
368
- before :each do
369
- @parser = TestParser.new
370
- end
371
-
372
- Constraints.each do |c|
373
- source, ast, definition = *c
374
- it "should parse #{source.inspect}" do
375
- definitions = @parser.parse_all(source, :definition)
376
-
377
- puts @parser.failure_reason unless definitions
378
-
379
- definitions.should_not be_nil
380
- result = definitions[-1]
381
-
382
- if (definition)
383
- result.definition.should == definition
384
- else
385
- #p @parser.definition(result)
386
- end
387
-
388
- result.value.should == ast if ast
389
-
390
- result.value.inspect unless ast
391
- end
392
- end
393
- end
394
- =end
@@ -1 +0,0 @@
1
- --colour