activefacts-cql 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +6 -5
  4. data/activefacts-cql.gemspec +4 -3
  5. data/lib/activefacts/cql/compiler.rb +29 -22
  6. data/lib/activefacts/cql/compiler/clause.rb +86 -84
  7. data/lib/activefacts/cql/compiler/constraint.rb +53 -53
  8. data/lib/activefacts/cql/compiler/entity_type.rb +28 -28
  9. data/lib/activefacts/cql/compiler/expression.rb +27 -27
  10. data/lib/activefacts/cql/compiler/fact.rb +37 -37
  11. data/lib/activefacts/cql/compiler/fact_type.rb +91 -85
  12. data/lib/activefacts/cql/compiler/informal.rb +48 -0
  13. data/lib/activefacts/cql/compiler/query.rb +52 -52
  14. data/lib/activefacts/cql/compiler/shared.rb +17 -17
  15. data/lib/activefacts/cql/compiler/value_type.rb +11 -11
  16. data/lib/activefacts/cql/parser/CQLParser.treetop +76 -56
  17. data/lib/activefacts/cql/parser/Context.treetop +15 -17
  18. data/lib/activefacts/cql/parser/Expressions.treetop +21 -21
  19. data/lib/activefacts/cql/parser/FactTypes.treetop +216 -216
  20. data/lib/activefacts/cql/parser/Language/English.treetop +136 -131
  21. data/lib/activefacts/cql/parser/Language/French.treetop +118 -118
  22. data/lib/activefacts/cql/parser/Language/Mandarin.treetop +111 -111
  23. data/lib/activefacts/cql/parser/LexicalRules.treetop +45 -45
  24. data/lib/activefacts/cql/parser/ObjectTypes.treetop +120 -120
  25. data/lib/activefacts/cql/parser/Terms.treetop +63 -63
  26. data/lib/activefacts/cql/parser/ValueTypes.treetop +71 -71
  27. data/lib/activefacts/cql/require.rb +8 -8
  28. data/lib/activefacts/cql/verbaliser.rb +88 -88
  29. data/lib/activefacts/cql/version.rb +1 -1
  30. data/lib/activefacts/input/cql.rb +7 -7
  31. metadata +12 -16
@@ -16,7 +16,7 @@ module ActiveFacts
16
16
 
17
17
  # The pattern to introduce an Entity Type
18
18
  rule identified_by
19
- 'identifié' s 'par' s
19
+ 'identifié' s 'par' s
20
20
  end
21
21
 
22
22
  rule basetype_expression
@@ -34,147 +34,147 @@ module ActiveFacts
34
34
 
35
35
  # The pattern to introduce an objectified fact type with implicit identification
36
36
  rule is_where
37
- existe s i:(independent s)? si
38
- { def independent; !i.empty?; end }
37
+ existe s i:(independent s)? si
38
+ { def independent; !i.empty?; end }
39
39
  end
40
40
 
41
- rule in_which # Introduce an objectification step
42
- where / # Old syntax
43
- dans s laquel # preferred syntax
41
+ rule in_which # Introduce an objectification step
42
+ where / # Old syntax
43
+ dans s laquel # preferred syntax
44
44
  end
45
45
 
46
46
  # Units conversion keyword
47
47
  rule conversion
48
- converts s a:(approximately s)? to s
49
- {
50
- def approximate?
51
- !a.empty?
52
- end
53
- }
48
+ converts s a:(approximately s)? to s
49
+ {
50
+ def approximate?
51
+ !a.empty?
52
+ end
53
+ }
54
54
  end
55
55
 
56
56
  # >>>>>>>>>>>>>>>>>>>> Constraints <<<<<<<<<<<<<<<<<<<<
57
57
  # External presence constraint syntax:
58
58
  rule each_occurs_in_clauses
59
- s chaque s ('combinaison' S)? role_list s existe s quantifier 'fois' S
60
- 'parmis' S ce S 'qui' S 'suit' s ':' s
61
- clauses_list s c:context_note? ';'
62
- {
63
- def role_list_ast
64
- role_list.ast
65
- end
66
- def quantifier_ast
67
- quantifier.ast
68
- end
69
- def clauses_ast
70
- clauses_list.ast
71
- end
72
- }
59
+ s chaque s ('combinaison' S)? role_list s existe s quantifier 'fois' S
60
+ 'parmis' S ce S 'qui' S 'suit' s ':' s
61
+ clauses_list s c:context_note? ';'
62
+ {
63
+ def role_list_ast
64
+ role_list.ast
65
+ end
66
+ def quantifier_ast
67
+ quantifier.ast
68
+ end
69
+ def clauses_ast
70
+ clauses_list.ast
71
+ end
72
+ }
73
73
  end
74
74
 
75
75
  rule either_or
76
76
  s soit s r1:clauses s 'ou' S r2:clauses
77
- s c:context_note? enforcement ';'
77
+ s c:context_note? enforcement ';'
78
78
  {
79
- def role_list_ast
80
- nil
81
- end
82
- def quantifier_ast
83
- Compiler::Quantifier.new(1, nil)
84
- end
85
- def clauses_ast
86
- [r1.ast, r2.ast]
87
- end
88
- }
79
+ def role_list_ast
80
+ nil
81
+ end
82
+ def quantifier_ast
83
+ Compiler::Quantifier.new(1, nil)
84
+ end
85
+ def clauses_ast
86
+ [r1.ast, r2.ast]
87
+ end
88
+ }
89
89
  end
90
90
 
91
91
  # Used for exclusion (at most one) and mandatory exclusion (exactly one)
92
92
  rule for_each_how_many
93
- 'pour' S 'chaque' S role_list s
94
- quantifier s 'des' S 'suivants' S 's\'applique' s ':' s
95
- clauses_list s c:context_note? ';'
96
- {
97
- def role_list_ast
98
- role_list.ast
99
- end
100
- def quantifier_ast
101
- quantifier.ast
102
- end
103
- def clauses_ast
104
- clauses_list.ast
105
- end
106
- }
93
+ 'pour' S 'chaque' S role_list s
94
+ quantifier s 'des' S 'suivants' S 's\'applique' s ':' s
95
+ clauses_list s c:context_note? ';'
96
+ {
97
+ def role_list_ast
98
+ role_list.ast
99
+ end
100
+ def quantifier_ast
101
+ quantifier.ast
102
+ end
103
+ def clauses_ast
104
+ clauses_list.ast
105
+ end
106
+ }
107
107
  end
108
108
 
109
109
  rule either_or_not_both
110
- s soit s r1:clauses s 'ou' S r2:clauses 'mais' S 'pas' S 'les' S 'deux'
111
- s c:context_note? enforcement ';'
112
- {
113
- def role_list_ast
114
- nil
115
- end
116
- def quantifier_ast
117
- Compiler::Quantifier.new(1, 1)
118
- end
119
- def clauses_ast
120
- [r1.ast, r2.ast]
121
- end
122
- }
110
+ s soit s r1:clauses s 'ou' S r2:clauses 'mais' S 'pas' S 'les' S 'deux'
111
+ s c:context_note? enforcement ';'
112
+ {
113
+ def role_list_ast
114
+ nil
115
+ end
116
+ def quantifier_ast
117
+ Compiler::Quantifier.new(1, 1)
118
+ end
119
+ def clauses_ast
120
+ [r1.ast, r2.ast]
121
+ end
122
+ }
123
123
  end
124
124
 
125
125
  rule a_only_if_b
126
- s clauses s only_if r2:clauses s c:context_note? enforcement ';'
126
+ s clauses s only_if r2:clauses s c:context_note? enforcement ';'
127
127
  end
128
128
 
129
129
  rule only_if
130
- que s si s
130
+ que s si s
131
131
  end
132
132
 
133
133
  rule if_b_then_a
134
- s 'si' S clauses s 'puis' S r2:clauses s c:context_note? enforcement ';'
134
+ s 'si' S clauses s 'puis' S r2:clauses s c:context_note? enforcement ';'
135
135
  end
136
136
 
137
137
  rule if_and_only_if
138
138
  s clauses s tail:( 'si' S 'et' S ('seulement'/'uniquement'/'que') S 'si' S clauses s)+
139
- c:context_note? enforcement ';'
139
+ c:context_note? enforcement ';'
140
140
  end
141
141
 
142
142
  # During the prescan we need to know where terms in a role list finish.
143
143
  # This rule matches any non-term expressions that may follow a role list.
144
144
  rule role_list_constraint_followers
145
- existe
145
+ existe
146
146
  end
147
147
 
148
148
  # >>>>>>>>>>>>>>>>>>>> Quantifiers <<<<<<<<<<<<<<<<<<<<
149
149
  rule quantifier
150
- (
151
- ( chaque s # "each"
152
- { def value; [1, nil]; end }
153
- / un s 'certain' 'e'? ) s # "some"
154
- { def value; nil; end }
155
- / ce s # "that"
156
- { def value; nil; end }
157
- / un s # "one"; masculine or feminine
158
- { def value; [1, 1]; end }
159
- / 'pas' s 'de' s # REVISIT: Example: "Personne n'a pas de Casier-judiciaire"
160
- { def value; [0, 0]; end }
161
- / exactement s quantity
162
- { def value; q = quantity.value; [q, q]; end }
163
- / au s moins s quantity most:( et s au s plus q:quantity )? # At least (or at most)
164
- { def value; [ quantity.value, most.empty? ? nil : most.q.value ]; end }
165
- / au s plus s quantity # At most
166
- { def value; [ nil, quantity.value ]; end }
167
- / entre s numeric_range s # within numeric_range
168
- { def value; numeric_range.value; end }
169
- / soit s tous s soit s aucun # either all or none
170
- { def value; [ -1, 1 ]; end }
171
- )
172
- {
173
- def ast
174
- v = value
175
- Compiler::Quantifier.new(v[0], v[1])
176
- end
177
- }
150
+ (
151
+ ( chaque s # "each"
152
+ { def value; [1, nil]; end }
153
+ / un s 'certain' 'e'? ) s # "some"
154
+ { def value; nil; end }
155
+ / ce s # "that"
156
+ { def value; nil; end }
157
+ / un s # "one"; masculine or feminine
158
+ { def value; [1, 1]; end }
159
+ / 'pas' s 'de' s # REVISIT: Example: "Personne n'a pas de Casier-judiciaire"
160
+ { def value; [0, 0]; end }
161
+ / exactement s quantity
162
+ { def value; q = quantity.value; [q, q]; end }
163
+ / au s moins s quantity most:( et s au s plus q:quantity )? # At least (or at most)
164
+ { def value; [ quantity.value, most.empty? ? nil : most.q.value ]; end }
165
+ / au s plus s quantity # At most
166
+ { def value; [ nil, quantity.value ]; end }
167
+ / entre s numeric_range s # within numeric_range
168
+ { def value; numeric_range.value; end }
169
+ / soit s tous s soit s aucun # either all or none
170
+ { def value; [ -1, 1 ]; end }
171
+ )
172
+ {
173
+ def ast
174
+ v = value
175
+ Compiler::Quantifier.new(v[0], v[1])
176
+ end
177
+ }
178
178
  end
179
179
 
180
180
  rule quantity
@@ -184,7 +184,7 @@ module ActiveFacts
184
184
 
185
185
  # >>>>>>>>>>>>>>>>>>>> Context Notes <<<<<<<<<<<<<<<<<<<<
186
186
  rule as_agreed_by
187
- s 'comme' S 'convenu' S d:('le' s date s)? 'par' S agents
187
+ s 'comme' S 'convenu' S d:('le' s date s)? 'par' S agents
188
188
  { def value; [ d.empty? ? nil : d.date.value, agents.value ]; end }
189
189
  end
190
190
 
@@ -196,9 +196,9 @@ module ActiveFacts
196
196
  rule agents
197
197
  s h:agent s t:(',' s !context_type agent s)*
198
198
  {
199
- def value; [h.text_value] + t.elements.map{|e| e.agent.text_value }; end
200
- def node_type; :linking; end
201
- }
199
+ def value; [h.text_value] + t.elements.map{|e| e.agent.text_value }; end
200
+ def node_type; :linking; end
201
+ }
202
202
  end
203
203
 
204
204
  rule agent
@@ -206,7 +206,7 @@ module ActiveFacts
206
206
  end
207
207
 
208
208
  rule negative_prefix
209
- s 'ce' S "n'est" s 'pas' s 'le' s 'cas' s 'que'
209
+ s 'ce' S "n'est" s 'pas' s 'le' s 'cas' s 'que'
210
210
  end
211
211
 
212
212
  rule agg_of de end
@@ -218,7 +218,7 @@ module ActiveFacts
218
218
  rule all 'tous' !alphanumeric end
219
219
  rule at 'a' !alphanumeric end
220
220
  rule both 'les deux' !alphanumeric end
221
- rule ce ('cette'/'cet'/'ce') !alphanumeric end # ce is masculine, cette feminine, cet is ce before a noun
221
+ rule ce ('cette'/'cet'/'ce') !alphanumeric end # ce is masculine, cette feminine, cet is ce before a noun
222
222
  rule chaque 'chaque' !alphanumeric end
223
223
  rule converts 'convertit' !alphanumeric end
224
224
  rule de 'de' !alphanumeric end
@@ -231,15 +231,15 @@ module ActiveFacts
231
231
  rule est 'est' !alphanumeric end
232
232
  rule exactement 'exactement' !alphanumeric end
233
233
  rule existe 'existe' !alphanumeric end
234
- rule from 'à partir de' !alphanumeric end # REVISIT: google translate
234
+ rule from 'à partir de' !alphanumeric end # REVISIT: google translate
235
235
  rule includes 'comprend' !alphanumeric end
236
236
  rule matches 'matches' !alphanumeric end
237
237
  rule moins 'moins' !alphanumeric end
238
238
  rule none 'aucun' !alphanumeric end
239
- rule not 'not' !alphanumeric end # REVISIT: Used in constraints
239
+ rule not 'not' !alphanumeric end # REVISIT: Used in constraints
240
240
  rule plus 'plus' !alphanumeric end
241
241
  rule some 'quelques' !alphanumeric end
242
- rule un 'un' 'e'? !alphanumeric end # un is masculine, une is feminine
242
+ rule un 'un' 'e'? !alphanumeric end # un is masculine, une is feminine
243
243
  rule que 'que' !alphanumeric end
244
244
 
245
245
  # >>>>>>>>>>>>>>>>>>>> External vocabulary <<<<<<<<<<<<<<<<<<<<
@@ -248,7 +248,7 @@ module ActiveFacts
248
248
  rule alias 'alias' !alphanumeric end
249
249
  rule and 'et' !alphanumeric end
250
250
  rule antisymmetric 'antisymmetric' !alphanumeric end
251
- rule approximately 'environ' !alphanumeric end # REVISIT: google translate
251
+ rule approximately 'environ' !alphanumeric end # REVISIT: google translate
252
252
  rule as 'comme' !alphanumeric end
253
253
  rule as_opposed_to 'au' S 'lieu' S 'de' !alphanumeric end
254
254
  rule asymmetric 'asymétrique' !alphanumeric end
@@ -264,16 +264,16 @@ module ActiveFacts
264
264
  rule feminine 'féminin' !alphanumeric end
265
265
  rule identified ('identifié') !alphanumeric end
266
266
  rule if 'si' !alphanumeric end
267
- rule import 'import' !alphanumeric end # REVISIT: translation?
267
+ rule import 'import' !alphanumeric end # REVISIT: translation?
268
268
  rule independent 'indépendant' !alphanumeric end
269
269
  rule stronglyintransitive 'stronglyintransitif' !alphanumeric end
270
270
  rule intransitive 'intransitif' !alphanumeric end
271
271
  rule irreflexive 'irréflexive' !alphanumeric end
272
- rule is est end # Called from ObjectTypes.treetop in "is identified by"
272
+ rule is est end # Called from ObjectTypes.treetop in "is identified by"
273
273
  rule its ('sa' / 'son') !alphanumeric end
274
274
  rule masculine 'masculin' !alphanumeric end
275
- rule maybe 'peut-être' !alphanumeric end # REVISIT: eventuellement = possibly?
276
- rule only 'que' !alphanumeric end # REVISIT: Used in constraints
275
+ rule maybe 'peut-être' !alphanumeric end # REVISIT: eventuellement = possibly?
276
+ rule only 'que' !alphanumeric end # REVISIT: Used in constraints
277
277
  rule or 'ou' !alphanumeric end
278
278
  rule ordering_prefix by s (ascending/descending)? s end
279
279
  rule otherwise 'sinon' !alphanumeric end
@@ -10,9 +10,9 @@ module ActiveFacts
10
10
 
11
11
  rule range
12
12
  (numeric_range / string_range)
13
- {
14
- def node_type; :literal; end
15
- }
13
+ {
14
+ def node_type; :literal; end
15
+ }
16
16
  end
17
17
 
18
18
  rule numeric_range
@@ -58,11 +58,11 @@ module ActiveFacts
58
58
  end
59
59
 
60
60
  rule url
61
- # url_scheme ':' (user ( ':' !(port '/') password )? '@' )? hostname ( ':' port )? '/' path query? fragment?
62
- ( !(white / ';') .)+
63
- {
64
- def node_type; :literal; end
65
- }
61
+ # url_scheme ':' (user ( ':' !(port '/') password )? '@' )? hostname ( ':' port )? '/' path query? fragment?
62
+ ( !(white / ';') .)+
63
+ {
64
+ def node_type; :literal; end
65
+ }
66
66
  end
67
67
 
68
68
  rule literal
@@ -74,7 +74,7 @@ module ActiveFacts
74
74
  def value
75
75
  elements[0].value
76
76
  end
77
- def node_type; :literal; end
77
+ def node_type; :literal; end
78
78
  }
79
79
  end
80
80
 
@@ -107,7 +107,7 @@ module ActiveFacts
107
107
  def value
108
108
  eval(text_value)
109
109
  end
110
- def node_type; :literal; end
110
+ def node_type; :literal; end
111
111
  }
112
112
  end
113
113
 
@@ -116,7 +116,7 @@ module ActiveFacts
116
116
  rule string_char
117
117
  ( '\\' [befntr\\']
118
118
  / '\\' [0-7] [0-7] [0-7]
119
- / '\\' [\r]* [\n] [\r]*
119
+ / '\\' [\r]* [\n] [\r]*
120
120
  / '\\0'
121
121
  / '\\x' [0-9A-Fa-f] [0-9A-Fa-f]
122
122
  / '\\u' [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f]
@@ -158,7 +158,7 @@ module ActiveFacts
158
158
  end
159
159
 
160
160
  rule alpha
161
- [[:alpha:]_]
161
+ [[:alpha:]_]
162
162
  end
163
163
 
164
164
  rule alphanumeric
@@ -179,73 +179,73 @@ module ActiveFacts
179
179
 
180
180
  rule comment_to_eol
181
181
  '//' (!"\n" .)*
182
- {
183
- def node_type; :comment; end
184
- }
182
+ {
183
+ def node_type; :comment; end
184
+ }
185
185
  end
186
186
 
187
187
  rule comment_c_style
188
188
  '/*' (!'*/' . )* '*/'
189
- {
190
- def node_type; :comment; end
191
- }
189
+ {
190
+ def node_type; :comment; end
191
+ }
192
192
  end
193
193
 
194
194
  rule regular_expression
195
- '/' !'/' regular_expression_contents '/'
196
- {
197
- def contents
198
- regular_expression_contents.text_value
199
- end
200
- }
195
+ '/' !'/' regular_expression_contents '/'
196
+ {
197
+ def contents
198
+ regular_expression_contents.text_value
199
+ end
200
+ }
201
201
  end
202
202
 
203
203
  rule regular_expression_contents
204
- regular_expression_alternate ( '|' regular_expression_alternate )*
204
+ regular_expression_alternate ( '|' regular_expression_alternate )*
205
205
  end
206
206
 
207
207
  rule regular_expression_alternate
208
- regular_expression_sequence
208
+ regular_expression_sequence
209
209
  end
210
210
 
211
211
  rule regular_expression_sequence
212
- regular_expression_atom*
212
+ regular_expression_atom*
213
213
  end
214
214
 
215
215
  rule regular_expression_atom
216
- (
217
- '[' character_classes ']'
218
- / regular_expression_group
219
- / ![*+?()|/] string_char
220
- ) regular_expression_multiplicity?
216
+ (
217
+ '[' character_classes ']'
218
+ / regular_expression_group
219
+ / ![*+?()|/] string_char
220
+ ) regular_expression_multiplicity?
221
221
  end
222
222
 
223
223
  rule character_classes
224
- character_class+
224
+ character_class+
225
225
  end
226
226
 
227
227
  rule character_class
228
- !']' string_char '-' !']' string_char
229
- / '-'
230
- / !']' string_char
228
+ !']' string_char '-' !']' string_char
229
+ / '-'
230
+ / !']' string_char
231
231
  end
232
232
 
233
233
  rule regular_expression_multiplicity
234
- '*' / '+' / '?'
234
+ '*' / '+' / '?'
235
235
  end
236
236
 
237
237
  rule regular_expression_group
238
- '('
239
- regular_expression_group_extension?
240
- regular_expression_contents
241
- ')'
238
+ '('
239
+ regular_expression_group_extension?
240
+ regular_expression_contents
241
+ ')'
242
242
  end
243
243
 
244
244
  rule regular_expression_group_extension
245
- '?' (
246
- '<' ( !'>' .)+ '>' # A tag for a regular expression group
247
- # REVISIT: Add more group extensions as needed
248
- )
245
+ '?' (
246
+ '<' ( !'>' .)+ '>' # A tag for a regular expression group
247
+ # REVISIT: Add more group extensions as needed
248
+ )
249
249
  end
250
250
 
251
251
  end