activefacts 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/cql +137 -91
- data/css/style.css +3 -3
- data/examples/CQL/Insurance.cql +1 -1
- data/examples/CQL/SeparateSubtype.cql +2 -2
- data/lib/activefacts/cql/Language/English.treetop +9 -0
- data/lib/activefacts/cql/ObjectTypes.treetop +1 -1
- data/lib/activefacts/cql/Terms.treetop +3 -1
- data/lib/activefacts/cql/ValueTypes.treetop +10 -4
- data/lib/activefacts/cql/compiler.rb +1 -0
- data/lib/activefacts/cql/compiler/clause.rb +53 -23
- data/lib/activefacts/cql/compiler/entity_type.rb +0 -4
- data/lib/activefacts/cql/compiler/expression.rb +9 -13
- data/lib/activefacts/cql/compiler/fact.rb +49 -48
- data/lib/activefacts/cql/compiler/fact_type.rb +23 -20
- data/lib/activefacts/cql/compiler/query.rb +49 -121
- data/lib/activefacts/cql/compiler/shared.rb +5 -1
- data/lib/activefacts/cql/compiler/value_type.rb +4 -2
- data/lib/activefacts/generate/rails/schema.rb +138 -108
- data/lib/activefacts/generate/transform/surrogate.rb +1 -2
- data/lib/activefacts/mapping/rails.rb +52 -45
- data/lib/activefacts/persistence/columns.rb +5 -5
- data/lib/activefacts/persistence/tables.rb +6 -4
- data/lib/activefacts/support.rb +0 -2
- data/lib/activefacts/version.rb +1 -1
- data/lib/activefacts/vocabulary/extensions.rb +64 -42
- data/lib/activefacts/vocabulary/metamodel.rb +14 -12
- data/lib/activefacts/vocabulary/verbaliser.rb +98 -92
- data/spec/cql/expressions_spec.rb +8 -3
- data/spec/cql/parser/entity_types_spec.rb +1 -1
- data/spec/cql/parser/expressions_spec.rb +66 -52
- data/spec/cql/parser/fact_types_spec.rb +1 -1
- data/spec/cql/parser/literals_spec.rb +10 -10
- data/spec/cql/parser/pragmas_spec.rb +3 -3
- data/spec/cql/parser/value_types_spec.rb +1 -1
- metadata +2 -2
@@ -42,7 +42,7 @@ describe "When compiling expressions" do
|
|
42
42
|
new_fact_types.size.should == 3
|
43
43
|
end
|
44
44
|
|
45
|
-
it "should create derived fact
|
45
|
+
it "should create derived fact types and project the roles" do
|
46
46
|
compile %q{Person is old where Person is of Age >= 3*(9+11); }
|
47
47
|
|
48
48
|
new_fact_types = fact_types
|
@@ -52,8 +52,13 @@ describe "When compiling expressions" do
|
|
52
52
|
is_old_ft = new_fact_types.detect{|ft| ft.all_reading.detect{|r| r.text =~ /is old/} }
|
53
53
|
(is_old_ft.all_reading.map{ |r| r.expand }*', ').should == "Person is old"
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
new_readings = new_fact_types.
|
56
|
+
reject{|ft| ft == is_old_ft}.
|
57
|
+
map{|ft| ft.all_reading.map{|r| r.expand}*", "}
|
58
|
+
|
59
|
+
new_readings.should include("Boolean = Age >= PRODUCT_OF<Integer SUM_OF<Integer, Integer>>")
|
60
|
+
new_readings.should include("PRODUCT_OF<Integer SUM_OF<Integer, Integer>> = Integer * SUM_OF<Integer, Integer>")
|
61
|
+
new_readings.should include("SUM_OF<Integer, Integer> = Integer + Integer")
|
57
62
|
|
58
63
|
# one_query_with_value 60, 'year'
|
59
64
|
end
|
@@ -50,7 +50,7 @@ describe "Entity Types" do
|
|
50
50
|
|
51
51
|
EntityTypes_Objectified = [
|
52
52
|
[ "Director is where b directs c, c is directed by b;",
|
53
|
-
["FactType:
|
53
|
+
["FactType: [{b} \"directs\" {c}, {c} \"is directed by\" {b}]"]
|
54
54
|
],
|
55
55
|
]
|
56
56
|
|
@@ -15,9 +15,12 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
15
15
|
%q{
|
16
16
|
Director is old: Person directs Company, Person is of Age, Age > 60;
|
17
17
|
}.should parse_to_ast \
|
18
|
-
%q{
|
19
|
-
|
20
|
-
|
18
|
+
%q{
|
19
|
+
FactType: Query: where {Person} "directs" {Company} ,
|
20
|
+
{Person} "is of" {Age} ,
|
21
|
+
COMPARE>({Age} WITH 60)
|
22
|
+
[{Director} "is old"]
|
23
|
+
}
|
21
24
|
end
|
22
25
|
|
23
26
|
it "should parse a comparison clause with subscripts" do
|
@@ -25,11 +28,11 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
25
28
|
Director is old: Person directs Company, Person has Salary(2), Person is of Age(1), Age(1) > Salary(2);
|
26
29
|
}.should parse_to_ast \
|
27
30
|
%q{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
FactType: Query: where {Person} "directs" {Company} ,
|
32
|
+
{Person} "has" {Salary(2)} ,
|
33
|
+
{Person} "is of" {Age(1)} ,
|
34
|
+
COMPARE>({Age(1)} WITH {Salary(2)})
|
35
|
+
[{Director} "is old"]
|
33
36
|
}
|
34
37
|
end
|
35
38
|
|
@@ -37,43 +40,44 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
37
40
|
%q{
|
38
41
|
Person is independent: Person has taxable- Income and taxable Income >= 20000 dollars or Person has sugar-Daddy;
|
39
42
|
}.should parse_to_ast \
|
40
|
-
%q{
|
41
|
-
|
43
|
+
%q{
|
44
|
+
FactType: Query: where {Person} "has" {taxable- Income} and
|
45
|
+
COMPARE>=({taxable- Income} WITH (20000 in dollars)) or
|
46
|
+
{Person} "has" {sugar- Daddy}
|
47
|
+
[{Person} "is independent"]
|
48
|
+
}
|
42
49
|
end
|
43
50
|
|
44
51
|
it "should parse a reading with a contracted comparison expression" do
|
45
52
|
%q{
|
46
53
|
Director is old: Person directs company, Person is of Age > 20+2*20;
|
47
54
|
}.should parse_to_ast \
|
48
|
-
%q{
|
49
|
-
|
50
|
-
|
55
|
+
%q{
|
56
|
+
FactType: Query: where {Person} "directs company" ,
|
57
|
+
{Person} "is of" {Age} > COMPARE>({Age} WITH SUM(20 PLUS PRODUCT(2 TIMES 20)))
|
58
|
+
[{Director} "is old"]
|
59
|
+
}
|
51
60
|
end
|
52
61
|
|
53
62
|
it "should parse a right-contracted comparison clause after a right-contracted clause" do
|
54
63
|
%q{
|
55
64
|
Director is old: Company is directed by Person who is of Age > 60;
|
56
65
|
}.should parse_to_ast \
|
57
|
-
%q{FactType:
|
58
|
-
{Person} "is of" {Age} >
|
59
|
-
compare>({Age} 60)}
|
66
|
+
%q{FactType: Query: where {Company} "is directed by" {Person} who {Person} "is of" {Age} > COMPARE>({Age} WITH 60) [{Director} "is old"]}
|
60
67
|
end
|
61
68
|
|
62
69
|
it "should parse a simple reading with qualifiers" do
|
63
70
|
%q{
|
64
71
|
Person(1) is ancestor of Person(2): maybe Person(1) is parent of Person(2) [transitive];
|
65
72
|
}.should parse_to_ast \
|
66
|
-
%q{FactType: [{Person(1)} "is ancestor of" {Person(2)}]
|
67
|
-
["transitive"] maybe {Person(1)} "is parent of" {Person(2)}}
|
73
|
+
%q{FactType: Query: where ["transitive"] maybe {Person(1)} "is parent of" {Person(2)} [{Person(1)} "is ancestor of" {Person(2)}]}
|
68
74
|
end
|
69
75
|
|
70
76
|
it "should parse a contracted reading with qualifiers" do
|
71
77
|
%q{
|
72
78
|
Person(1) provides lineage of Person(2): maybe Person(2) is child of Person(1) [transitive] who is male;
|
73
79
|
}.should parse_to_ast \
|
74
|
-
%q{FactType: [{Person(1)} "provides lineage of" {Person(2)}]
|
75
|
-
["transitive"] maybe {Person(2)} "is child of" {Person(1)}
|
76
|
-
who {Person(1)} "is male"}
|
80
|
+
%q{FactType: Query: where ["transitive"] maybe {Person(2)} "is child of" {Person(1)} who {Person(1)} "is male" [{Person(1)} "provides lineage of" {Person(2)}]}
|
77
81
|
end
|
78
82
|
|
79
83
|
it "should parse a contracted readings and comparisons with qualifiers" do
|
@@ -83,29 +87,37 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
83
87
|
who maybe is of Age [static]
|
84
88
|
definitely >= 21;
|
85
89
|
}.should parse_to_ast \
|
86
|
-
|
87
|
-
["transitive"] maybe {Person(1)} "is parent of" {Person(2)}
|
88
|
-
|
89
|
-
>=
|
90
|
+
%q{
|
91
|
+
FactType: Query: where ["transitive"] maybe {Person(1)} "is parent of" {Person(2)} who
|
92
|
+
["static"] maybe {Person(2)} "is of" {Age} >=
|
93
|
+
COMPARE>=({Age} WITH 21)
|
94
|
+
[{Person(1)} "is ancestor of adult" {Person(2)}]
|
95
|
+
}
|
90
96
|
end
|
91
97
|
|
92
98
|
it "should parse a comparison expression with a contracted reading" do
|
93
99
|
%q{
|
94
100
|
Director is old: Person directs company, 3*30 >= Age that is of Person;
|
95
101
|
}.should parse_to_ast \
|
96
|
-
%q{
|
97
|
-
|
98
|
-
|
102
|
+
%q{
|
103
|
+
FactType: Query: where {Person} "directs company" ,
|
104
|
+
COMPARE>=(PRODUCT(3 TIMES 30) WITH {Age}) that
|
105
|
+
{Age} "is of" {Person}
|
106
|
+
[{Director} "is old"]
|
107
|
+
}
|
99
108
|
end
|
100
109
|
|
101
110
|
it "should parse a comparison expression with a contracted comparison" do
|
102
111
|
%q{
|
103
112
|
Director is old: Person directs company, Person is of Age, maybe 20 <= Age definitely < 60;
|
104
113
|
}.should parse_to_ast \
|
105
|
-
|
114
|
+
%q{
|
115
|
+
FactType: Query: where {Person} "directs company" ,
|
106
116
|
{Person} "is of" {Age} ,
|
107
|
-
|
108
|
-
<
|
117
|
+
COMPARE<=(maybe 20 WITH {Age}) <
|
118
|
+
COMPARE<({Age} WITH 60)
|
119
|
+
[{Director} "is old"]
|
120
|
+
}
|
109
121
|
end
|
110
122
|
|
111
123
|
it "should parse a comparison expression with right-contracted then left-contracted comparisons"
|
@@ -122,24 +134,30 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
122
134
|
%q{
|
123
135
|
A is a farce: maybe A has completely- B [transitive, acyclic] < 5, B -c = 2;
|
124
136
|
}.should parse_to_ast \
|
125
|
-
|
126
|
-
|
127
|
-
|
137
|
+
%q{
|
138
|
+
FactType: Query: where ["acyclic", "transitive"] maybe {A} "has" {completely- B} <
|
139
|
+
COMPARE<({completely- B} WITH 5) ,
|
140
|
+
COMPARE=({B -c} WITH 2)
|
141
|
+
[{A} "is a farce"]
|
142
|
+
}
|
128
143
|
end
|
129
144
|
|
130
145
|
it "should parse multiple leading and trailing adjectives with contracted comparisons" do
|
131
146
|
%q{
|
132
147
|
A is a farce: maybe A has completely- green B [transitive, acyclic] < 9, B c -d = 2;
|
133
148
|
}.should parse_to_ast \
|
134
|
-
|
135
|
-
|
136
|
-
|
149
|
+
%q{
|
150
|
+
FactType: Query: where ["acyclic", "transitive"] maybe {A} "has" {completely- green B} <
|
151
|
+
COMPARE<({completely- green B} WITH 9) ,
|
152
|
+
COMPARE=({B c -d} WITH 2)
|
153
|
+
[{A} "is a farce"]
|
154
|
+
}
|
137
155
|
end
|
138
156
|
|
139
157
|
it "should parse a comparison clause containing units" do
|
140
158
|
%q{
|
141
159
|
254 mm converts to foot/feet;
|
142
|
-
Width is written as Integer mm;
|
160
|
+
Width is written as Integer in mm;
|
143
161
|
Window requires toughening where
|
144
162
|
Window has Width,
|
145
163
|
Window has Height,
|
@@ -147,9 +165,11 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
147
165
|
}.should parse_to_ast \
|
148
166
|
%q{Unit(foot/feet) is 254/1+0 mm^1},
|
149
167
|
%q{ValueType: Width is written as Integer in [["mm", 1]];},
|
150
|
-
%q{FactType:
|
151
|
-
|
152
|
-
|
168
|
+
%q{FactType: Query: where {Window} "has" {Width} ,
|
169
|
+
{Window} "has" {Height} ,
|
170
|
+
COMPARE>=(PRODUCT({Width} TIMES {Height}) WITH (10 in feet^2))
|
171
|
+
[{Window} "requires toughening"]
|
172
|
+
}
|
153
173
|
end
|
154
174
|
|
155
175
|
it "should parse nested expressions" do
|
@@ -158,7 +178,7 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
158
178
|
A > B+3*(4+5)?
|
159
179
|
}.should parse_to_ast \
|
160
180
|
%q{ValueType: A is written as B;},
|
161
|
-
%q{FactType:
|
181
|
+
%q{FactType: Query: where COMPARE>({A} WITH SUM({B} PLUS PRODUCT(3 TIMES SUM(4 PLUS 5)))) []}
|
162
182
|
end
|
163
183
|
|
164
184
|
it "should parse a fact type containing an expression with subscripts"
|
@@ -168,17 +188,11 @@ describe "ASTs from Derived Fact Types with expressions" do
|
|
168
188
|
Driving was negligent where
|
169
189
|
Driving (where maybe Driver drove in Incident [acyclic] that definitely is of Claim [intransitive]) followed Intoxication [static];
|
170
190
|
}.should parse_to_ast \
|
171
|
-
%q{
|
172
|
-
FactType: [{Driving} "was negligent"] where ["static"] {Driving}
|
173
|
-
(where ["acyclic"] maybe {Driver} "drove in" {Incident}
|
174
|
-
that ["intransitive"] {Incident} "is of" {Claim})
|
175
|
-
"followed" {Intoxication}
|
176
|
-
}
|
177
191
|
%q{
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
192
|
+
FactType: Query: where ["static"] {Driving} (in which where
|
193
|
+
["acyclic"] maybe {Driver} "drove in" {Incident}
|
194
|
+
that ["intransitive"] {Incident} "is of" {Claim}) "followed" {Intoxication}
|
195
|
+
[{Driving} "was negligent"]
|
182
196
|
}
|
183
197
|
end
|
184
198
|
|
@@ -23,7 +23,7 @@ describe "Fact Types" do
|
|
23
23
|
# [%q{FactType: AnnualIncome [{Person} "has" {total- Income} "in" {Year}] where {Person} "has" {total- Income}.sum() , {Income} "was earned in" {current- Time (as Year)}.Year()}]
|
24
24
|
# ],
|
25
25
|
[ "A is interesting : b- C has F -g;",
|
26
|
-
[
|
26
|
+
[%q{FactType: Query: where {b- C} "has" {F -g} [{A} "is interesting"]}]
|
27
27
|
],
|
28
28
|
[ "A has one pre-- bound B;",
|
29
29
|
[%q{FactType: [{A} "has" {[1..1] pre-bound- B}]}]
|
@@ -114,31 +114,31 @@ describe "Valid Numbers, Strings and Ranges" do
|
|
114
114
|
],
|
115
115
|
|
116
116
|
# Value types with units
|
117
|
-
[ "a is written as b inch;", # Value type declaration with unit
|
117
|
+
[ "a is written as b in inch;", # Value type declaration with unit
|
118
118
|
['ValueType: a is written as b in [["inch", 1]];']
|
119
119
|
],
|
120
|
-
[ "a is written as b() inch ; ", # Value type declaration with unit and whitespace
|
120
|
+
[ "a is written as b() in inch ; ", # Value type declaration with unit and whitespace
|
121
121
|
['ValueType: a is written as b in [["inch", 1]];']
|
122
122
|
],
|
123
|
-
[ "a is written as b() inch;", # Value type declaration with unit
|
123
|
+
[ "a is written as b() in inch;", # Value type declaration with unit
|
124
124
|
['ValueType: a is written as b in [["inch", 1]];']
|
125
125
|
],
|
126
|
-
[ "a is written as b inch^2;", # Value type declaration with unit and exponent
|
126
|
+
[ "a is written as b in inch^2;", # Value type declaration with unit and exponent
|
127
127
|
['ValueType: a is written as b in [["inch", 2]];']
|
128
128
|
],
|
129
|
-
[ "a is written as b() inch^2 ; ", # Value type declaration with unit and exponent with maximum whitespace
|
129
|
+
[ "a is written as b() in inch^2 ; ", # Value type declaration with unit and exponent with maximum whitespace
|
130
130
|
['ValueType: a is written as b in [["inch", 2]];']
|
131
131
|
],
|
132
|
-
[ "a is written as b second^-1;", # Value type declaration with unit and negative exponent
|
132
|
+
[ "a is written as b in second^-1;", # Value type declaration with unit and negative exponent
|
133
133
|
['ValueType: a is written as b in [["second", -1]];']
|
134
134
|
],
|
135
|
-
[ "a is written as b inch inch;", # Value type declaration with repeated unit
|
135
|
+
[ "a is written as b in inch inch;", # Value type declaration with repeated unit
|
136
136
|
['ValueType: a is written as b in [["inch", 1], ["inch", 1]];']
|
137
137
|
],
|
138
|
-
[ "a is written as b inch^2/minute^-1;", # Value type declaration with unit and divided unit with exponents
|
138
|
+
[ "a is written as b in inch^2/minute^-1;", # Value type declaration with unit and divided unit with exponents
|
139
139
|
['ValueType: a is written as b in [["inch", 2], ["minute", 1]];']
|
140
140
|
],
|
141
|
-
[ "a is written as b() second^-1/mm^-1 mm^-1;", # Value type declaration with repeated divided unit
|
141
|
+
[ "a is written as b() in second^-1/mm^-1 mm^-1;", # Value type declaration with repeated divided unit
|
142
142
|
['ValueType: a is written as b in [["second", -1], ["mm", 1], ["mm", 1]];']
|
143
143
|
],
|
144
144
|
|
@@ -281,7 +281,7 @@ describe "Valid Numbers, Strings and Ranges" do
|
|
281
281
|
[ "a is written as b() restricted to {1} inches^2/second;", # constraint with units and exponent
|
282
282
|
['ValueType: a is written as b ValueConstraint to ([1]) in [["inches", 2], ["second", -1]];']
|
283
283
|
],
|
284
|
-
[ "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
|
284
|
+
[ "a is written as b() in second^-1/mm^-1 mm^-1 restricted to {1} inches^2/second;", # type with unit and constraint with units and exponent
|
285
285
|
#['a is written as b ValueConstraint to ([1]) in [["inches", 2], ["second", -1]];']
|
286
286
|
["ValueType: a is written as b in [[\"second\", -1], [\"mm\", 1], [\"mm\", 1]] ValueConstraint to ([1]) in [[\"inches\", 2], [\"second\", -1]];"]
|
287
287
|
],
|
@@ -51,13 +51,13 @@ describe "Entity Types" do
|
|
51
51
|
|
52
52
|
# Fact Types
|
53
53
|
[ "Director is where c relates to b;",
|
54
|
-
["FactType:
|
54
|
+
["FactType: [{c} \"relates to\" {b}]"]
|
55
55
|
],
|
56
56
|
[ "Director [independent] is where c relates to b;",
|
57
|
-
["FactType:
|
57
|
+
["FactType: [{c} \"relates to\" {b}], pragmas [independent]"]
|
58
58
|
],
|
59
59
|
[ "Director is independent where c relates to b;",
|
60
|
-
|
60
|
+
["FactType: [{c} \"relates to\" {b}], pragmas [independent]"]
|
61
61
|
],
|
62
62
|
]
|
63
63
|
|
@@ -10,7 +10,7 @@ require 'helpers/test_parser'
|
|
10
10
|
|
11
11
|
describe "Value Types" do
|
12
12
|
ValueTypes = [
|
13
|
-
[ "a is written as b(1, 2) inch restricted to { 3 .. 4 } inch ;",
|
13
|
+
[ "a is written as b(1, 2) in inch restricted to { 3 .. 4 } inch ;",
|
14
14
|
['ValueType: a is written as b(1, 2) in [["inch", 1]] ValueConstraint to ([3..4]) in [["inch", 1]];']
|
15
15
|
],
|
16
16
|
# [ "a c is written as b(1, 2) inch restricted to { 3 .. 4 } inch ;",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activefacts-api
|