activefacts 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cql CHANGED
@@ -26,10 +26,72 @@ class InteractiveCQL < ActiveFacts::CQL::Compiler
26
26
  self.root = :definition
27
27
  end
28
28
 
29
+ def list_instances name
30
+ if name.empty?
31
+ @vocabulary.constellation.Instance.values
32
+ else
33
+ if !@vocabulary.constellation.Concept[[[@vocabulary.name], name]]
34
+ puts "Object type '#{name}' does not exist in vocabulary '#{@vocabulary.name}'"
35
+ []
36
+ else
37
+ @vocabulary.constellation.Instance.values.select{|i| i.concept.supertypes_transitive.detect{|k| k.name == name}}
38
+ end
39
+ end.select do |instance|
40
+ instance.concept.vocabulary == @vocabulary
41
+ end.map do |instance|
42
+ instance.verbalise
43
+ end.sort.each do |verbalisation|
44
+ puts verbalisation
45
+ end
46
+ end
47
+
48
+ def toggle_trace words
49
+ words.each { |word|
50
+ puts "#{word} #{debug_toggle(word) ? "en" : "dis"}abled"
51
+ }
52
+ end
53
+
54
+ def list_object_types
55
+ concepts_by_vocabulary = {}
56
+ @constellation.Concept.keys.
57
+ each do |v,t|
58
+ (concepts_by_vocabulary[v[0]] ||= []) << t
59
+ end
60
+ concepts_by_vocabulary.keys.sort.each do |v|
61
+ puts "#{v}:\n\t" + concepts_by_vocabulary[v].sort*"\n\t"
62
+ end
63
+ end
64
+
65
+ def list_connotations word
66
+ concept = @constellation.Concept[[@vocabulary.identifying_role_values, word]]
67
+ unless concept
68
+ puts "Object type '#{word}' is unknown in #{@vocabulary.name}"
69
+ return
70
+ end
71
+ puts "Fact types in which '#{word}' plays a part:"
72
+ if concept.is_a?(ActiveFacts::Metamodel::ValueType)
73
+ puts "\t#{concept.name} is written as #{concept.supertype.name};" if concept.supertype
74
+ concept.all_value_type_as_supertype.each do |st|
75
+ puts "#{st.name} is written as #{concept.name};"
76
+ end
77
+ end
78
+ concept.all_role.map{|role| role.fact_type}.uniq.each do |fact_type|
79
+ puts "\t#{fact_type.default_reading}"
80
+ end
81
+ end
82
+
29
83
  def metacommand(line)
30
84
  # meta-commands start with /
31
85
  words = line.split
32
86
  case cmd = words.shift
87
+ when /(\w*)\?/
88
+ list_instances $1
89
+ when "/trace"
90
+ if words.empty?
91
+ puts debug_keys*", "
92
+ else
93
+ toggle_trace words
94
+ end
33
95
  when "/tree"
34
96
  @show_tree = !@show_tree
35
97
  puts "Will #{@show_tree ? "" : "not "}show the parse tree"
@@ -37,39 +99,13 @@ class InteractiveCQL < ActiveFacts::CQL::Compiler
37
99
  self.root = words[0] && words[0].to_sym || :definition
38
100
  puts "Looking for a #{self.root}"
39
101
  when "/list"
40
- concepts_by_vocabulary = {}
41
- @constellation.Concept.keys.
42
- each do |v,t|
43
- (concepts_by_vocabulary[v[0]] ||= []) << t
44
- end
45
- concepts_by_vocabulary.keys.sort.each do |v|
46
- puts "#{v}:\n\t" + concepts_by_vocabulary[v].sort*"\n\t"
47
- end
102
+ list_object_types
48
103
  when "/about"
49
- concept = @constellation.Concept[[@vocabulary.identifying_role_values, words[0]]]
50
- unless concept
51
- puts "Concept #{words[0]} is unknown in #{@vocabulary.name}"
52
- return
53
- end
54
- if concept.is_a?(ActiveFacts::Metamodel::ValueType)
55
- puts "\t#{concept.name} is written as #{concept.supertype.name};" if concept.supertype
56
- concept.all_value_type_as_supertype.each do |st|
57
- puts "#{st.name} is written as #{concept.name};"
58
- end
59
- end
60
- concept.all_role.map{|role| role.fact_type}.uniq.each do |fact_type|
61
- puts "\t#{fact_type.default_reading}"
104
+ words.each do |word|
105
+ list_connotations word
62
106
  end
63
107
  when "/load"
64
- begin
65
- vocabularies = @constellation.Vocabulary.keys
66
- @results = []
67
- compile_file words*' '
68
- new_vocabularies = @constellation.Vocabulary.keys-vocabularies
69
- puts "Loaded new vocabularies: #{new_vocabularies*', '}" unless new_vocabularies.empty?
70
- rescue Errno::ENOENT => e
71
- $stderr.puts e.message
72
- end
108
+ load_file(words*' ')
73
109
  else
74
110
  if cmd == "/help" or cmd == "/"
75
111
  help words
@@ -80,6 +116,21 @@ class InteractiveCQL < ActiveFacts::CQL::Compiler
80
116
  end
81
117
  end
82
118
 
119
+ def load_file filename
120
+ begin
121
+ vocabularies = @constellation.Vocabulary.keys
122
+ @results = []
123
+ compile_file filename
124
+ new_vocabularies = @constellation.Vocabulary.keys-vocabularies
125
+ puts "Loaded new vocabularies: #{new_vocabularies*', '}" unless new_vocabularies.empty?
126
+ rescue Errno::ENOENT => e
127
+ $stderr.puts e.message
128
+ rescue => e
129
+ puts e.message
130
+ puts "\t#{e.backtrace*"\n\t"}" if debug :exception
131
+ end
132
+ end
133
+
83
134
  def process(statement)
84
135
  begin
85
136
  @results = []
@@ -110,6 +161,7 @@ Meta-commands are:
110
161
  /load file.cql\tLoad a CQL file
111
162
  /root rule\t\tParse just a fragment of a CQL statement, matching syntax rule only
112
163
  /tree\t\t\tDisplay the abstract syntax tree from each statement parsed
164
+ /trace key\t\tToggle debug tracing key, or list available keys
113
165
  }
114
166
  else
115
167
  words.each do |word|
@@ -324,10 +376,17 @@ end
324
376
 
325
377
  compiler = InteractiveCQL.new
326
378
  statement = nil
379
+ ARGV.each do |arg|
380
+ compiler.load_file(arg)
381
+ end
327
382
  puts "Enter / for help on special commands"
383
+
328
384
  while line = Readline::readline(statement ? "CQL+ " : "CQL? ", [])
329
385
  statement = statement ? statement + "\n"+line : line
330
- if line =~ %r{\A/}
386
+ if statement =~ /\s*(.*?)\s*\?\s*$/
387
+ compiler.list_instances $1
388
+ statement = nil
389
+ elsif line =~ %r{\A/}
331
390
  compiler.metacommand(line)
332
391
  statement = nil
333
392
  elsif compiler.root != :definition or
data/download.html CHANGED
@@ -63,7 +63,8 @@
63
63
  PATH C:\Ruby187\bin;%PATH%
64
64
  </pre>
65
65
  <p>
66
- Or right-click "My Computer" -%gt; Properties -%gt; Advanced -%gt; Environment Variables -%gt; System Variables
66
+ Or right-click "My Computer" -&gt; Properties -&gt; Advanced -&gt; Environment Variables -&gt; System Variables
67
+ <br>
67
68
  Scroll down to find the entry for Path and double-click it. Click in the Variable value: text widget and move the cursor to the start of the value before typing <b>C:\Ruby187;</b> before the first entry. Hit Ok three times and start a new command prompt.
68
69
  </p>
69
70
  <p>
@@ -13,8 +13,8 @@ LanguageName is written as String;
13
13
  Country is identified by its Name;
14
14
 
15
15
  Diplomat is identified by its Name;
16
- Diplomat represents one Country;
17
- Diplomat serves in one Country;
16
+ Diplomat represents one Country (as Represented Country);
17
+ Diplomat serves in one Country (as Served Country);
18
18
 
19
19
  Language is identified by its Name;
20
20
 
@@ -29,8 +29,8 @@ Fluency is where
29
29
  Language is spoken by Diplomat;
30
30
 
31
31
  Representation is where
32
- Ambassador is from Country(1) to Country(2),
33
- Country(1) is represented in Country(2) by one Ambassador;
32
+ Ambassador is from Country (as Represented Country) to Country(2),
33
+ Represented Country(1) is represented in Country(2) by one Ambassador;
34
34
 
35
35
  /*
36
36
  * Constraints:
@@ -38,10 +38,10 @@ Representation is where
38
38
  for each Diplomat, Country at most one of these holds:
39
39
  Diplomat serves in Country,
40
40
  Diplomat represents Country;
41
- Ambassador is from Country(1) to Country(2)
42
- only if Ambassador is a kind of Diplomat that represents Country(1);
43
- Ambassador is from Country(2) to Country(1)
44
- only if Ambassador is a kind of Diplomat that serves in Country(1);
41
+ Diplomat is an Ambassador that is from Country(1) to Country(2)
42
+ only if Diplomat represents Country(1);
43
+ Diplomat is an Ambassador that is from Country(2) to Country(1)
44
+ only if Diplomat serves in Country(1);
45
45
  Diplomat serves in Country
46
46
  only if Diplomat speaks Language that is spoken in Country;
47
47
  each Ambassador occurs at least one time in
@@ -205,7 +205,7 @@ Vehicle was sold by at most one Dealer;
205
205
  Driver is a kind of Person;
206
206
 
207
207
  Driving is where
208
- Vehicle Incident involves at most one Driver,
208
+ Vehicle Incident involves one Driver,
209
209
  Driver drove covered vehicle in at least one Vehicle Incident;
210
210
  Driving followed at most one Intoxication;
211
211
  Driving resulted in at most one blood-Test Result;
@@ -215,7 +215,7 @@ Driving was without owners consent for at most one nonconsent-Reason;
215
215
  Driving was unlicenced for at most one unlicensed-Reason;
216
216
 
217
217
  Driving Charge is where
218
- Driving resulted in at most one Charge;
218
+ Driving resulted in one Charge;
219
219
  Driving Charge is a warning;
220
220
 
221
221
  Finance Institution is a kind of Company;
@@ -236,7 +236,7 @@ License was granted in at most one Year restricted to {1990..2100};
236
236
  License is international;
237
237
 
238
238
  Lodgement is where
239
- Claim was lodged by at most one Person;
239
+ Claim was lodged by one Person;
240
240
  Lodgement was made at at most one Date Time;
241
241
 
242
242
  Policy is identified by p_year and p_product and p_state and p_serial where
@@ -33,6 +33,7 @@ Role Sequence Id is written as Auto Counter;
33
33
  Rotation Setting is written as String restricted to {'left', 'right'};
34
34
  Scale is written as Unsigned Integer(32);
35
35
  Shape Id is written as Auto Counter;
36
+ Subscript is written as Unsigned Integer(16);
36
37
  Text is written as String(256);
37
38
  Unit Id is written as Auto Counter;
38
39
  X is written as Signed Integer(32);
@@ -86,13 +87,8 @@ Join Node is identified by Join and Ordinal where
86
87
  Join includes Join Node,
87
88
  Join Node is in one Join,
88
89
  Join Node has one Ordinal position;
89
-
90
- Join Step is identified by input-Join Node and output-Join Node where
91
- Join Step has one input-Join Node,
92
- Join Step has one output-Join Node;
93
- Join Step traverses one Fact Type;
94
- is anti Join Step;
95
- Join Step is outer;
90
+ Join Node has at most one Subscript,
91
+ Subscript is of Join Node;
96
92
 
97
93
  Position is identified by X and Y where
98
94
  Position is at one X,
@@ -127,7 +123,6 @@ Role has at most one role-Name,
127
123
  role-Name is name of at least one Role;
128
124
 
129
125
  Role Sequence is identified by its Id;
130
- Join projects one Role Sequence;
131
126
  Presence Constraint covers one Role Sequence;
132
127
  Reading is in one Role Sequence,
133
128
  Role Sequence is for Reading;
@@ -167,6 +162,7 @@ Value is identified by Literal and Value is a string and Unit where
167
162
  Value is in at most one Unit,
168
163
  Unit is of Value;
169
164
  Instance has at most one Value;
165
+ Join Node has at most one Value;
170
166
 
171
167
  Value Constraint is a kind of Constraint;
172
168
  Role has at most one role-Value Constraint,
@@ -238,6 +234,19 @@ Fact Type Shape is for one Fact Type,
238
234
  Fact Type has Fact Type Shape;
239
235
  Fact Type Shape has at most one Rotation Setting;
240
236
 
237
+ Join Role is where
238
+ Join Node includes at least one Role,
239
+ Role connects to Join Node;
240
+
241
+ Join Step is identified by input-Join Role and output-Join Role where
242
+ Join Step has one input-Join Role,
243
+ Join Step has one output-Join Role;
244
+ Join Step traverses one Fact Type,
245
+ Fact Type directs Join Step;
246
+ Join Step involves incidental-Join Role;
247
+ is anti Join Step;
248
+ Join Step is outer;
249
+
241
250
  Model Note Shape is a kind of Shape;
242
251
  Model Note Shape is for one Context Note;
243
252
 
@@ -273,29 +282,28 @@ Ring Constraint Shape is attached to one Fact Type;
273
282
 
274
283
  Role Display is where
275
284
  Fact Type Shape displays Role in Ordinal position,
276
- Fact Type Shape displays in Ordinal position at most one Role;
285
+ Fact Type Shape displays in Ordinal position one Role;
277
286
 
278
287
  Role Name Shape is a kind of Shape;
279
288
  Role Name Shape is for one Role Display,
280
289
  Role Display has at most one Role Name Shape;
281
290
 
282
291
  Role Ref is where
283
- Role Sequence in Ordinal position includes at most one Role,
284
- Role is in Role Sequence in at most one Ordinal place,
292
+ Role Sequence in Ordinal position includes one Role,
293
+ Role is in Role Sequence in one Ordinal place,
285
294
  Role Sequence includes Role in Ordinal place,
286
295
  Role has Ordinal place in Role Sequence;
287
- Role Ref connects to at most one Join Node,
288
- Join Node includes Role Ref;
296
+ Join Role projects at most one Role Ref;
289
297
  Role Ref has at most one leading-Adjective;
290
298
  Role Ref has at most one trailing-Adjective;
291
299
 
292
300
  Set Comparison Constraint is a kind of Set Constraint;
293
301
 
294
302
  Set Comparison Roles is where
295
- Set Comparison Constraint has in Ordinal position at most one Role Sequence,
303
+ Set Comparison Constraint has in Ordinal position one Role Sequence,
296
304
  Role Sequence is Ordinal in Set Comparison Constraint,
297
305
  in Ordinal position Set Comparison Constraint has Role Sequence,
298
- Set Comparison Constraint has Role Sequence in at most one Ordinal position;
306
+ Set Comparison Constraint has Role Sequence in one Ordinal position;
299
307
 
300
308
  Set Equality Constraint is a kind of Set Comparison Constraint;
301
309
 
@@ -341,7 +349,7 @@ Parameter is where
341
349
  Value Type has parameter called Name;
342
350
 
343
351
  Param Value is where
344
- Value for Parameter applies to at most one Value Type;
352
+ Value for Parameter applies to one Value Type;
345
353
 
346
354
  /*
347
355
  * Constraints:
@@ -364,6 +372,9 @@ either Value Constraint constrains Value Type or Value Constraint applies to Rol
364
372
  for each Instance at most one of these holds:
365
373
  Instance has Value,
366
374
  Instance objectifies Fact;
375
+ Join Node is for Concept that plays Role
376
+ if and only if
377
+ Join Node includes Role;
367
378
  Role Value is of Instance that is of Concept
368
379
  if and only if
369
380
  Role Value is of Role that is played by Concept;
@@ -381,10 +392,14 @@ each combination Diagram, Position occurs at most one time in
381
392
  each combination Entity Type, Type Inheritance occurs at most one time in
382
393
  Entity Type is subtype of super Entity Type,
383
394
  Type Inheritance provides identification;
395
+ each Join Role occurs at most one time in
396
+ Join Step involves incidental Join Role;
384
397
  each Presence Constraint occurs at least one time in
385
398
  Presence Constraint has min Frequency,
386
399
  Presence Constraint has max Frequency,
387
400
  Presence Constraint is mandatory;
401
+ each Role Ref occurs at most one time in
402
+ Join Role projects Role Ref;
388
403
  each Role Sequence occurs at least one time in
389
404
  Role Sequence in Ordinal position includes Role;
390
405
  each Set Comparison Constraint occurs at least 2 times in
@@ -32,6 +32,7 @@ Role Sequence Id is written as Auto Counter;
32
32
  Rotation Setting is written as String restricted to {'left', 'right'};
33
33
  Scale is written as Unsigned Integer(32);
34
34
  Shape Id is written as Auto Counter;
35
+ Subscript is written as String;
35
36
  Text is written as String(256);
36
37
  Unit Id is written as Auto Counter;
37
38
  X is written as Signed Integer(32);
@@ -87,13 +88,8 @@ Join Node is identified by Join and Ordinal where
87
88
  Join includes Join Node,
88
89
  Join Node is in one Join,
89
90
  Join Node has one Ordinal position;
90
-
91
- Join Step is identified by input-Join Node and output-Join Node where
92
- Join Step has one input-Join Node,
93
- Join Step has one output-Join Node;
94
- Join Step traverses one Fact Type;
95
- is anti Join Step;
96
- Join Step is outer;
91
+ Join Node has at most one Subscript,
92
+ Subscript is of Join Node;
97
93
 
98
94
  Object Type is a kind of Concept [partitioned];
99
95
  Instance is of one Object Type;
@@ -129,13 +125,12 @@ Implicit Fact Type is implied by one Role,
129
125
  Object Type plays Role,
130
126
  Role is played by one Object Type;
131
127
  Ring Constraint has at most one other-Role;
132
- Ring Constraint has other-Role,
128
+ Ring Constraint has at most one other-Role,
133
129
  other-Role is of Ring Constraint;
134
130
  Role is of Ring Constraint,
135
131
  Ring Constraint has at most one Role;
136
132
 
137
133
  Role Sequence is identified by its Id;
138
- Join projects one Role Sequence;
139
134
  Presence Constraint covers one Role Sequence;
140
135
  Reading is in one Role Sequence,
141
136
  Role Sequence is for Reading;
@@ -175,6 +170,7 @@ Value is identified by Literal and Value is a string and Unit where
175
170
  Value is in at most one Unit,
176
171
  Unit is of Value;
177
172
  Instance has at most one Value;
173
+ Join Node has at most one Value;
178
174
 
179
175
  Value Constraint is a kind of Constraint;
180
176
  Role has at most one role-Value Constraint,
@@ -245,6 +241,18 @@ Fact Type Shape has at most one Rotation Setting;
245
241
 
246
242
  ImplicitBooleanValueType is a kind of Value Type;
247
243
 
244
+ Join Role is where
245
+ Join Node includes Role,
246
+ Role connects to Join Node;
247
+
248
+ Join Step is identified by input-Join Role and output-Join Role where
249
+ Join Step has one input-Join Role,
250
+ Join Step has one output-Join Role;
251
+ Join Step traverses one Fact Type,
252
+ Fact Type directs Join Step;
253
+ is anti Join Step;
254
+ Join Step is outer;
255
+
248
256
  Model Note Shape is a kind of Shape;
249
257
  Model Note Shape is for one Context Note;
250
258
 
@@ -284,29 +292,28 @@ Ring Constraint Shape is attached to one Fact Type;
284
292
 
285
293
  Role Display is where
286
294
  Fact Type Shape displays Role in Ordinal position,
287
- Fact Type Shape displays in Ordinal position at most one Role;
295
+ Fact Type Shape displays in Ordinal position one Role;
288
296
 
289
297
  Role Name Shape is a kind of Shape;
290
298
  Role Name Shape is for one Role Display,
291
299
  Role Display has at most one Role Name Shape;
292
300
 
293
301
  Role Ref is where
294
- Role Sequence in Ordinal position includes at most one Role,
295
- Role is in Role Sequence in at most one Ordinal place,
302
+ Role Sequence in Ordinal position includes one Role,
303
+ Role is in Role Sequence in one Ordinal place,
296
304
  Role Sequence includes Role in Ordinal place,
297
305
  Role has Ordinal place in Role Sequence;
298
- Join Node includes Role Ref,
299
- Role Ref connects to at most one Join Node;
306
+ Join Role projects at most one Role Ref;
300
307
  Role Ref has at most one leading-Adjective;
301
308
  Role Ref has at most one trailing-Adjective;
302
309
 
303
310
  Set Comparison Constraint is a kind of Set Constraint;
304
311
 
305
312
  Set Comparison Roles is where
306
- Set Comparison Constraint has in Ordinal position at most one Role Sequence,
313
+ Set Comparison Constraint has in Ordinal position one Role Sequence,
307
314
  Role Sequence is Ordinal in Set Comparison Constraint,
308
315
  in Ordinal position Set Comparison Constraint has Role Sequence,
309
- Set Comparison Constraint has Role Sequence in at most one Ordinal position;
316
+ Set Comparison Constraint has Role Sequence in one Ordinal position;
310
317
 
311
318
  Set Equality Constraint is a kind of Set Comparison Constraint;
312
319
 
@@ -343,13 +350,13 @@ Allowed Range is where
343
350
  Value Constraint allows at least one Value Range;
344
351
 
345
352
  Param Value is where
346
- Value for Parameter applies to at most one Value Type;
353
+ Value for Parameter applies to one Value Type;
347
354
 
348
355
  /*
349
356
  * Constraints:
350
357
  */
351
358
  for each Concept exactly one of these holds:
352
- Concept is a Object Type,
359
+ Concept is an Object Type,
353
360
  Concept is a Fact Type,
354
361
  Concept is a Constraint,
355
362
  Concept is a Role;
@@ -382,6 +389,9 @@ for each Term at most one of these holds:
382
389
  for each Term at most one of these holds:
383
390
  Term is secondary for Object Type,
384
391
  Term is name of Role Ref;
392
+ Join Node is for Object Type that plays Role
393
+ if and only if
394
+ Join Node includes Role;
385
395
  Role Value is of Instance that is of Object Type
386
396
  if and only if
387
397
  Role Value is of Role that is played by Object Type;
@@ -403,6 +413,8 @@ each Presence Constraint occurs at least one time in
403
413
  Presence Constraint has min Frequency,
404
414
  Presence Constraint has max Frequency,
405
415
  Presence Constraint is mandatory;
416
+ each Role Ref occurs at most one time in
417
+ Join Role projects Role Ref;
406
418
  each Role Sequence occurs at least one time in
407
419
  Role Sequence in Ordinal position includes Role;
408
420
  each Set Comparison Constraint occurs at least 2 times in