line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
%{ |
2
|
2
|
|
|
2
|
|
24
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
160
|
|
3
|
2
|
|
|
2
|
|
1060
|
use TM; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
96
|
|
4
|
2
|
|
|
2
|
|
3529
|
use TM::Literal; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use constant LEFT => 'http://psi.tm.bond.edu.au/astma/1.0/#psi-left'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
7
|
2
|
|
|
2
|
|
11
|
use constant RIGHT => 'http://psi.tm.bond.edu.au/astma/1.0/#psi-right'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1887
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $tracing = 0; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
%} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
%token ISA |
14
|
294
|
|
|
294
|
0
|
3241
|
%token BN |
15
|
294
|
|
|
|
|
1134
|
%token OC |
16
|
294
|
|
66
|
|
|
2462
|
%token IN |
17
|
|
|
|
|
|
|
%token SIN |
18
|
294
|
50
|
|
|
|
1064
|
%token COMMENT |
19
|
|
|
|
|
|
|
%token STRING |
20
|
|
|
|
|
|
|
%token EOL |
21
|
|
|
|
|
|
|
%token ID |
22
|
|
|
|
|
|
|
%token REIFIES |
23
|
|
|
|
|
|
|
%token ISREIFIED |
24
|
|
|
|
|
|
|
%token ISINDICATEDBY |
25
|
|
|
|
|
|
|
%token LOG |
26
|
|
|
|
|
|
|
%token CANCEL |
27
|
|
|
|
|
|
|
%token TRACE |
28
|
|
|
|
|
|
|
%token ENCODING |
29
|
|
|
|
|
|
|
%token COLON |
30
|
|
|
|
|
|
|
%token LPAREN |
31
|
|
|
|
|
|
|
%token RPAREN |
32
|
|
|
|
|
|
|
%token LBRACKET |
33
|
|
|
|
|
|
|
%token RBRACKET |
34
|
|
|
|
|
|
|
%token AT |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
%% |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
maplet_definitions : #empty |
39
|
|
|
|
|
|
|
| maplet_definitions maplet_definition |
40
|
|
|
|
|
|
|
| maplet_definitions template_definition EOL |
41
|
|
|
|
|
|
|
| maplet_definitions COMMENT EOL |
42
|
1
|
|
|
1
|
|
57
|
| maplet_definitions LOG EOL { warn "Logging $_[2]"; } |
43
|
2
|
|
|
2
|
|
76
|
| maplet_definitions CANCEL EOL { die "Cancelled"; } |
44
|
2
|
|
|
2
|
|
55
|
| maplet_definitions TRACE EOL { $tracing = $_[2]; warn "# start tracing: level $tracing"; } |
|
2
|
|
|
|
|
39
|
|
45
|
|
|
|
|
|
|
| maplet_definitions ENCODING EOL { |
46
|
2
|
|
|
2
|
|
2562
|
use Encode; |
|
2
|
|
|
|
|
26868
|
|
|
2
|
|
|
|
|
6447
|
|
47
|
2
|
|
|
2
|
|
64
|
Encode::from_to ($_[0]->YYData->{INPUT}, "iso-8859-1", $_[2]); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
maplet_definition : topic_definition |
52
|
|
|
|
|
|
|
| association_definition |
53
|
|
|
|
|
|
|
| EOL |
54
|
|
|
|
|
|
|
; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
topic_definition : ID types reification_indication inline_assocs EOL |
57
|
|
|
|
|
|
|
{ |
58
|
1088
|
|
|
1088
|
|
99200
|
$_[1] = $_[0]->{USER}->{store}->internalize ($_[1]); |
59
|
|
|
|
|
|
|
|
60
|
1088
|
100
|
|
|
|
3593
|
if (ref $_[3]) { # we have reification info |
61
|
279
|
50
|
|
|
|
1139
|
if ( $_[3]->[0] == 1) { # 1 = REIFIES, means current ID is a shorthand for the other |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
62
|
279
|
|
|
|
|
2137
|
$_[0]->{USER}->{store}->internalize ($_[1] => $_[3]->[1]); |
63
|
|
|
|
|
|
|
} elsif ($_[3]->[0] == 0) { # 0 = IS-REIFIED, this must be the other way round |
64
|
0
|
|
|
|
|
0
|
$_[0]->{USER}->{store}->internalize ($_[3]->[1] => $_[1]); |
65
|
|
|
|
|
|
|
} elsif ($_[3]->[0] == 2) { # 2 = ISINDICATEDBY, add the subject indicators |
66
|
0
|
|
|
|
|
0
|
$_[0]->{USER}->{store}->internalize ($_[1] => \ $_[3]->[1]); |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
0
|
die "internal fu**up"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
# assert instance/class |
72
|
1088
|
100
|
|
|
|
1664
|
if (@{$_[2]}) { |
|
1088
|
|
|
|
|
3750
|
|
73
|
767
|
|
|
|
|
9343
|
$_[0]->{USER}->{store}->assert ( map { bless |
|
393
|
|
|
|
|
1190
|
|
74
|
|
|
|
|
|
|
[ undef, |
75
|
|
|
|
|
|
|
undef, |
76
|
|
|
|
|
|
|
'isa', |
77
|
|
|
|
|
|
|
undef, |
78
|
|
|
|
|
|
|
[ 'class', 'instance' ], |
79
|
|
|
|
|
|
|
[ $_, $_[1] ], |
80
|
|
|
|
|
|
|
], 'Assertion' } |
81
|
393
|
|
|
|
|
1257
|
@{$_[2]} ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
{ # memorize the types should be a 'topic' |
84
|
|
|
|
|
|
|
# at the end (see end of parse) |
85
|
1088
|
|
|
|
|
2486
|
my $implicits = $_[0]->{USER}->{implicits}; |
|
1088
|
|
|
|
|
3121
|
|
86
|
1855
|
|
|
|
|
5892
|
map { $implicits->{'isa-thing'}->{$_}++ } |
|
1088
|
|
|
|
|
2179
|
|
87
|
1088
|
|
|
|
|
1420
|
(@{$_[2]}, $_[1]); # the types and the ID are declared implicitely |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1088
|
100
|
|
|
|
3433
|
if (ref $_[4]) { # there are inline assocs |
91
|
10
|
|
|
|
|
13
|
foreach (@{$_[4]}) { |
|
10
|
|
|
|
|
22
|
|
92
|
12
|
|
|
|
|
17
|
my $type = $_->[0]; |
93
|
12
|
|
|
|
|
17
|
my $player = $_->[1]; |
94
|
12
|
|
|
|
|
27
|
my $store = $_[0]->{USER}->{store}; |
95
|
12
|
|
|
|
|
19
|
my $templates = $_[0]->{USER}->{templates}; |
96
|
12
|
100
|
100
|
|
|
80
|
if ($type eq 'is-subclass-of' || $type eq 'subclasses') { |
|
|
50
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
97
|
5
|
|
|
|
|
54
|
$store->assert (bless [ undef, # LID |
98
|
|
|
|
|
|
|
undef, # SCOPE |
99
|
|
|
|
|
|
|
'is-subclass-of', # TYPE |
100
|
|
|
|
|
|
|
TM->ASSOC, # KIND |
101
|
|
|
|
|
|
|
[ 'subclass', 'superclass' ], # ROLES |
102
|
|
|
|
|
|
|
[ $_[1], $player ], # PLAYERS |
103
|
|
|
|
|
|
|
undef ], 'Assertion' ); |
104
|
|
|
|
|
|
|
} elsif ($type eq 'is-a') { |
105
|
0
|
|
|
|
|
0
|
$store->assert (bless [ undef, # LID |
106
|
|
|
|
|
|
|
undef, # SCOPE |
107
|
|
|
|
|
|
|
'isa', # TYPE |
108
|
|
|
|
|
|
|
TM->ASSOC, # KIND |
109
|
|
|
|
|
|
|
[ 'instance', 'class' ], # ROLES |
110
|
|
|
|
|
|
|
[ $_[1], $player ], # PLAYERS |
111
|
|
|
|
|
|
|
undef ], 'Assertion' ); |
112
|
|
|
|
|
|
|
} elsif ($type eq 'has-a') { # same, but other way round |
113
|
1
|
|
|
|
|
12
|
$store->assert (bless [ undef, # LID |
114
|
|
|
|
|
|
|
undef, # SCOPE |
115
|
|
|
|
|
|
|
'isa', # TYPE |
116
|
|
|
|
|
|
|
TM->ASSOC, # KIND |
117
|
|
|
|
|
|
|
[ 'instance', 'class' ], # ROLES |
118
|
|
|
|
|
|
|
[ $player, $_[1] ], # PLAYERS |
119
|
|
|
|
|
|
|
undef ], 'Assertion' ); |
120
|
|
|
|
|
|
|
} elsif ($templates->tids ( $type ) && |
121
|
|
|
|
|
|
|
(my @ts = $templates->match (TM->FORALL, type => $templates->tids ( $type ) ))) { |
122
|
5
|
50
|
|
|
|
13
|
warn "duplicate template for '$type' found (maybe typo?), taking one" if @ts > 1; |
123
|
5
|
|
|
|
|
19
|
my $t = $ts[0]; # I choose one |
124
|
10
|
|
|
|
|
31
|
$store->assert (bless [ undef, # LID |
125
|
|
|
|
|
|
|
undef, # SCOPE |
126
|
|
|
|
|
|
|
$type, # TYPE |
127
|
|
|
|
|
|
|
TM->ASSOC, # KIND |
128
|
|
|
|
|
|
|
[ # ROLES |
129
|
|
|
|
|
|
|
map { |
130
|
5
|
|
|
|
|
19
|
my $l = $templates->toplet ($_)->[TM->ADDRESS]; |
131
|
10
|
100
|
100
|
|
|
61
|
($l && $l eq LEFT ? |
|
|
100
|
66
|
|
|
|
|
132
|
|
|
|
|
|
|
$_[1] |
133
|
|
|
|
|
|
|
: |
134
|
|
|
|
|
|
|
($l && $l eq RIGHT ? |
135
|
|
|
|
|
|
|
$player |
136
|
|
|
|
|
|
|
: |
137
|
|
|
|
|
|
|
$_) |
138
|
|
|
|
|
|
|
) |
139
|
10
|
|
|
|
|
27
|
} @{$t->[TM->ROLES]} |
140
|
|
|
|
|
|
|
], |
141
|
|
|
|
|
|
|
[ # PLAYERS |
142
|
|
|
|
|
|
|
map { |
143
|
5
|
|
|
|
|
18
|
my $l = $templates->toplet ($_)->[TM->ADDRESS]; |
144
|
10
|
100
|
100
|
|
|
85
|
($l && $l eq LEFT ? |
|
|
100
|
66
|
|
|
|
|
145
|
|
|
|
|
|
|
$_[1] |
146
|
|
|
|
|
|
|
: |
147
|
|
|
|
|
|
|
($l && $l eq RIGHT ? |
148
|
|
|
|
|
|
|
$player |
149
|
|
|
|
|
|
|
: |
150
|
|
|
|
|
|
|
$_) |
151
|
|
|
|
|
|
|
) |
152
|
5
|
|
|
|
|
17
|
} @{$t->[TM->PLAYERS]} |
153
|
|
|
|
|
|
|
], |
154
|
|
|
|
|
|
|
undef ], 'Assertion' ); |
155
|
|
|
|
|
|
|
} else { |
156
|
1
|
|
|
|
|
15
|
die "unknown association type '$type' in inlined association"; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
1087
|
100
|
|
|
|
3902
|
warn "added toplet $_[1]" if $tracing; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
characteristics_indication |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
#warn "char/ind in topic: ".Dumper $_[7]; |
165
|
1082
|
|
|
1082
|
|
43023
|
my $id = $_[1]; |
166
|
|
|
|
|
|
|
# add assertions for every characteristic |
167
|
1957
|
|
66
|
|
|
35263
|
$_[0]->{USER}->{store}->assert ( map {bless [ undef, # LID |
|
1082
|
|
|
|
|
3394
|
|
168
|
|
|
|
|
|
|
$_->[1], # SCOPE |
169
|
|
|
|
|
|
|
$_->[2] || # TYPE |
170
|
|
|
|
|
|
|
($_->[0] == TM->NAME ? 'name' : 'occurrence'), |
171
|
|
|
|
|
|
|
$_->[0], # KIND |
172
|
|
|
|
|
|
|
[ 'thing', 'value' ], # ROLES |
173
|
|
|
|
|
|
|
[ $id, $_->[3] ], # PLAYERS |
174
|
|
|
|
|
|
|
undef ], 'Assertion' } |
175
|
1082
|
|
|
|
|
3085
|
@{$_[7]->[0]} ); |
176
|
|
|
|
|
|
|
|
177
|
1082
|
|
|
|
|
1884
|
map { $store->internalize ($id => \ $_ ) } @{$_[7]->[1]}; # add the subject indicators |
|
698
|
|
|
|
|
2307
|
|
|
1082
|
|
|
|
|
3316
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
{ # memorize basename types and scopes as implicitely defined |
180
|
1082
|
|
|
|
|
1592
|
my $implicits = $_[0]->{USER}->{implicits}; |
|
1082
|
|
|
|
|
3307
|
|
181
|
1104
|
|
|
|
|
4570
|
map { $implicits->{'isa-scope'}->{$_}++ } |
|
1104
|
|
|
|
|
2151
|
|
182
|
1082
|
|
|
|
|
3223
|
map { $_->[1] } |
183
|
1082
|
|
|
|
|
1899
|
grep ($_->[1], @{$_[7]->[0]}); # get the bloody scopes and tuck them away |
184
|
|
|
|
|
|
|
|
185
|
578
|
100
|
|
|
|
4360
|
map { $implicits->{'subclasses'}->{ $_->[0] == TM->NAME ? 'name' : 'occurrence' }->{$_->[2]}++ } |
|
1082
|
|
|
|
|
3676
|
|
186
|
1082
|
|
|
|
|
2545
|
grep ($_->[2], @{$_[7]->[0]}); # get all the characteristics with types |
187
|
|
|
|
|
|
|
} |
188
|
1082
|
50
|
|
|
|
5855
|
warn "added ".(scalar @{$_[7]->[0]})."characteristics for $_[1]" if $tracing > 1; |
|
0
|
|
|
|
|
0
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
reification_indication : # empty |
193
|
280
|
|
|
280
|
|
20330
|
| REIFIES ID { [ 1, $_[2] ] } # 0, 1, 2 are just local encoding, nothing relevant |
194
|
3
|
|
|
3
|
|
141
|
| ISREIFIED ID { [ 0, $_[2] ] } |
195
|
0
|
|
|
0
|
|
0
|
| ISINDICATEDBY ID { [ 2, $_[2] ] } |
196
|
|
|
|
|
|
|
; |
197
|
|
|
|
|
|
|
|
198
|
1088
|
|
|
1088
|
|
120337
|
types : { [] } # empty |
199
|
396
|
|
|
396
|
|
12289
|
| types type { push @{$_[1]}, @{$_[2]}; $_[1] } |
|
396
|
|
|
|
|
783
|
|
|
396
|
|
|
|
|
1445
|
|
|
396
|
|
|
|
|
1035
|
|
200
|
|
|
|
|
|
|
; |
201
|
|
|
|
|
|
|
|
202
|
10
|
|
|
10
|
|
500
|
type : ISA ID { [ $_[2] ] } |
203
|
386
|
|
|
386
|
|
12708
|
| LPAREN ids RPAREN { $_[2] } |
204
|
|
|
|
|
|
|
; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
characteristics_indication : # empty |
207
|
|
|
|
|
|
|
| characteristics_indication characteristic_indication |
208
|
2655
|
100
|
|
2655
|
|
159477
|
{ push @{$_[1]->[ ref($_[2]) eq 'ARRAY' ? 0 : 1 ]}, $_[2]; $_[1] } |
|
2655
|
|
|
|
|
10817
|
|
|
2655
|
|
|
|
|
8067
|
|
209
|
|
|
|
|
|
|
; # do not tell me this is not cryptic, it fast, though |
210
|
|
|
|
|
|
|
# if we get a characteristic back, then it is a list ref, then we add it to $_[1]->[0] |
211
|
|
|
|
|
|
|
# if we get a subject indication back, then it is a scalar, so we add it to $_[1]->[1] |
212
|
|
|
|
|
|
|
characteristic_indication : characteristic |
213
|
|
|
|
|
|
|
| indication |
214
|
|
|
|
|
|
|
; |
215
|
|
|
|
|
|
|
|
216
|
700
|
|
50
|
700
|
|
34217
|
indication : SIN { $_[0]->{USER}->{string} ||= "\n" } string |
217
|
698
|
|
|
698
|
|
23060
|
{ $_[3] } # TODO: replace with ID? |
218
|
|
|
|
|
|
|
; |
219
|
|
|
|
|
|
|
|
220
|
1960
|
|
50
|
1960
|
|
81840
|
characteristic : class { $_[0]->{USER}->{string} ||= "\n" } |
221
|
|
|
|
|
|
|
scope char_type string { # check whether we are dealing with URIs or strings |
222
|
1957
|
100
|
|
1957
|
|
111230
|
if ($_[1] == TM->NAME) { # names are always strings |
|
|
100
|
|
|
|
|
|
223
|
1351
|
|
|
|
|
17958
|
$_[5] = new TM::Literal ($_[5], TM::Literal->STRING); |
224
|
|
|
|
|
|
|
} elsif ($_[5] =~ /^\w+:\S+$/) { # can only be OCC, but is it URI? |
225
|
579
|
|
|
|
|
11786
|
$_[5] = new TM::Literal ($_[5], TM::Literal->URI); |
226
|
|
|
|
|
|
|
} else { # occurrence and not a URI -> string |
227
|
27
|
|
|
|
|
142
|
$_[5] = new TM::Literal ($_[5], TM::Literal->STRING); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
## warn "char ".Dumper [ $_[1], $_[3], $_[4], $_[5] ]; |
230
|
1957
|
|
|
|
|
7744
|
[ $_[1], $_[3], $_[4], $_[5] ] |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
; |
233
|
|
|
|
|
|
|
|
234
|
1352
|
|
|
1352
|
|
55755
|
class : BN { TM->NAME } |
235
|
580
|
|
|
580
|
|
18689
|
| OC { TM->OCC } |
236
|
28
|
|
|
28
|
|
824
|
| IN { TM->OCC } |
237
|
|
|
|
|
|
|
; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
char_type : # empty |
240
|
|
|
|
|
|
|
| assoc_type |
241
|
|
|
|
|
|
|
; |
242
|
|
|
|
|
|
|
|
243
|
578
|
|
|
578
|
|
34759
|
assoc_type : LPAREN ID RPAREN { $_[2] } |
244
|
|
|
|
|
|
|
; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
scope : # empty |
247
|
1105
|
|
|
1105
|
|
40801
|
| AT ID { $_[2] } |
248
|
|
|
|
|
|
|
; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
inline_assocs : # empty |
252
|
12
|
|
|
12
|
|
428
|
| inline_assocs inline_assoc { push @{$_[1]}, $_[2]; $_[1] } |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
30
|
|
253
|
|
|
|
|
|
|
; |
254
|
|
|
|
|
|
|
|
255
|
12
|
|
|
12
|
|
442
|
inline_assoc : ID ID { [ $_[1], $_[2] ] } |
256
|
|
|
|
|
|
|
; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
template_definition : LBRACKET |
259
|
4
|
|
|
4
|
|
217
|
{ ($_[0]->{USER}->{templates}, $_[0]->{USER}->{store}) = ($_[0]->{USER}->{store}, $_[0]->{USER}->{templates}); } |
260
|
|
|
|
|
|
|
# flag that we are inside a template |
261
|
|
|
|
|
|
|
association_definition |
262
|
4
|
|
|
4
|
|
146
|
{ ($_[0]->{USER}->{templates}, $_[0]->{USER}->{store}) = ($_[0]->{USER}->{store}, $_[0]->{USER}->{templates}); } |
263
|
|
|
|
|
|
|
#RBRACKET # consumed by members already |
264
|
|
|
|
|
|
|
; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
association_definition : LPAREN ID RPAREN scope reification_indication EOL |
267
|
|
|
|
|
|
|
association_members |
268
|
|
|
|
|
|
|
{ |
269
|
|
|
|
|
|
|
##warn "members ".Dumper $_[5]; |
270
|
|
|
|
|
|
|
## ??? TODO SCOPE ???? |
271
|
21
|
|
|
21
|
|
561
|
my (@roles, @players); |
272
|
21
|
|
|
|
|
29
|
foreach my $m (@{$_[7]}) { # one member |
|
21
|
|
|
|
|
51
|
|
273
|
30
|
|
|
|
|
79
|
my $role = shift @$m; # first is role |
274
|
|
|
|
|
|
|
|
275
|
30
|
|
|
|
|
78
|
while (@$m) { |
276
|
35
|
|
|
|
|
51
|
push @roles, $role; # roles repeat for every player |
277
|
35
|
|
|
|
|
48
|
my $player = shift @$m; |
278
|
35
|
|
|
|
|
126
|
push @players, $player; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
} |
281
|
21
|
|
|
|
|
197
|
my ($a) = $_[0]->{USER}->{store}->assert (bless [ undef, $_[4], $_[2], TM->ASSOC, \@roles, \@players, undef ], 'Assertion'); |
282
|
|
|
|
|
|
|
##warn "templates" .Dumper $_[0]->{USER}->{store}; |
283
|
|
|
|
|
|
|
{ # reification |
284
|
21
|
|
|
|
|
35
|
my $ms = $_[0]->{USER}->{store}; |
|
21
|
|
|
|
|
47
|
|
285
|
21
|
100
|
|
|
|
57
|
if (ref $_[5]) { |
286
|
4
|
100
|
|
|
|
15
|
if ($_[5]->[0] == 1) { # 1 = REIFIES, 0 = IS-REIFIED |
|
|
50
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# (assoc) reifies http://.... means |
288
|
|
|
|
|
|
|
# 1) the assoc will be addes as thing (is done already) |
289
|
|
|
|
|
|
|
# 2) the http:// will be used as one subject indicator |
290
|
1
|
50
|
|
|
|
17
|
die "reifier of association must be a URI" unless $_[5]->[1] =~ /^\w+:.+/; |
291
|
0
|
|
|
|
|
0
|
$ms->internalize ($a->[TM::LID], $_[5]->[1]); |
292
|
|
|
|
|
|
|
} elsif ($_[5]->[0] == 0) { # something reifies this assoc |
293
|
|
|
|
|
|
|
# (assoc) is-reified-by xxx means |
294
|
|
|
|
|
|
|
# 1) assoc is added as thing (is done already) |
295
|
|
|
|
|
|
|
# 2) the local identifier is added as thing with the abs URL of the assoc as subject address |
296
|
3
|
100
|
|
|
|
24
|
die "reifier must be local identifier" unless $_[5]->[1] =~ /^[A-Za-z][A-Za-z0-9_\.-]+$/; |
297
|
2
|
|
|
|
|
7
|
$ms->internalize ($_[5]->[1] => $a); |
298
|
|
|
|
|
|
|
} else { # this would be 'indication' but we do not want that here |
299
|
0
|
|
|
|
|
0
|
die "indication for associations are undefined"; |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
{ # memorize that association type subclasses association |
305
|
|
|
|
|
|
|
# my $implicits = $_[0]->{USER}->{implicits}; |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
# implicit $implicits->{'subclasses'}->{'association'}->{$_[2]}++; |
308
|
19
|
100
|
|
|
|
22
|
$_[0]->{USER}->{implicits}->{'isa-scope'}->{$_[4]}++ if $_[4]; |
|
19
|
|
|
|
|
49
|
|
309
|
|
|
|
|
|
|
} |
310
|
19
|
100
|
|
|
|
95
|
warn "added assertion $_[2]" if $tracing; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
; |
313
|
|
|
|
|
|
|
|
314
|
22
|
|
|
22
|
|
679
|
association_members : member { [ $_[1] ] } |
315
|
9
|
|
|
9
|
|
253
|
| association_members member { push @{$_[1]}, $_[2]; $_[1] } |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
22
|
|
316
|
|
|
|
|
|
|
; |
317
|
|
|
|
|
|
|
|
318
|
31
|
|
|
31
|
|
1968
|
member : ID COLON ids1 eom { [ $_[1], @{$_[3]} ] } |
|
31
|
|
|
|
|
124
|
|
319
|
|
|
|
|
|
|
; |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
eom : EOL # normal assoc |
322
|
|
|
|
|
|
|
| RBRACKET EOL # in case we are inside a template |
323
|
|
|
|
|
|
|
; |
324
|
|
|
|
|
|
|
|
325
|
31
|
|
|
31
|
|
692
|
ids1 : ids ID { push @{$_[1]}, $_[2]; $_[1] } |
|
31
|
|
|
|
|
75
|
|
|
31
|
|
|
|
|
69
|
|
326
|
|
|
|
|
|
|
; |
327
|
|
|
|
|
|
|
|
328
|
419
|
|
|
419
|
|
12241
|
ids : { [] } # empty |
329
|
762
|
|
|
762
|
|
24103
|
| ids ID { push @{$_[1]}, $_[2]; $_[1] } |
|
762
|
|
|
|
|
1943
|
|
|
762
|
|
|
|
|
3227
|
|
330
|
|
|
|
|
|
|
; |
331
|
|
|
|
|
|
|
|
332
|
2658
|
100
|
|
2658
|
|
94275
|
string : STRING EOL { die "empty string in characteristics" unless $_[1]; $_[1] } |
|
2655
|
|
|
|
|
7992
|
|
333
|
294
|
|
|
|
|
100627
|
; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
%% |
336
|
294
|
|
|
|
|
27807
|
|
337
|
294
|
|
|
|
|
4625
|
sub _Error { |
338
|
10
|
|
|
10
|
|
108
|
die "Syntax error: Found ".$_[0]->YYCurtok." but expected ".join (' or ', $_[0]->YYExpect); |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
2
|
|
|
2
|
|
45
|
use constant CHUNK_SIZE => 32000; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3293
|
|
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
sub _Lexer { |
344
|
17158
|
|
|
17158
|
|
559473
|
my $parser = shift; |
345
|
17158
|
|
|
|
|
53982
|
my $yydata = $parser->YYData; |
346
|
|
|
|
|
|
|
|
347
|
17158
|
100
|
66
|
|
|
202972
|
if (length ($yydata->{INPUT}) < 1024 && $yydata->{OFFSET} < $yydata->{TOTAL}) { |
348
|
293
|
|
|
|
|
1548
|
$yydata->{INPUT} .= substr ($yydata->{RESERVE}, $yydata->{OFFSET}, CHUNK_SIZE); |
349
|
293
|
|
|
|
|
1163
|
$yydata->{OFFSET} += CHUNK_SIZE; |
350
|
|
|
|
|
|
|
} |
351
|
17158
|
|
|
|
|
44970
|
my $refINPUT = \$yydata->{INPUT}; |
352
|
|
|
|
|
|
|
|
353
|
17158
|
|
|
|
|
25393
|
my $aux; # need this to store identifier/uri prefix for optimization |
354
|
|
|
|
|
|
|
|
355
|
17158
|
100
|
|
|
|
36241
|
$$refINPUT or return ('', undef); |
356
|
16883
|
|
|
|
|
72973
|
$$refINPUT =~ s/^[ \t]+//so; |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
#warn "lexer ($parser->{USER}->{string}):>>>".$parser->YYData->{INPUT}."<<<"; |
359
|
|
|
|
|
|
|
|
360
|
16883
|
100
|
|
|
|
66266
|
$$refINPUT =~ s/^\n//so and return ('EOL', undef); |
361
|
12696
|
100
|
|
|
|
29330
|
$$refINPUT =~ s/^in\b(?![\.-])//o and return ('IN', undef); |
362
|
12669
|
100
|
|
|
|
33865
|
$$refINPUT =~ s/^rd\b(?![\.-])//o and return ('IN', undef); |
363
|
12668
|
100
|
|
|
|
32149
|
$$refINPUT =~ s/^oc\b(?![\.-])//o and return ('OC', undef); |
364
|
12089
|
100
|
|
|
|
22663
|
$$refINPUT =~ s/^ex\b(?![\.-])//o and return ('OC', undef); |
365
|
12088
|
100
|
|
|
|
36366
|
$$refINPUT =~ s/^bn\b(?![\.-])//o and return ('BN', undef); |
366
|
|
|
|
|
|
|
|
367
|
10736
|
100
|
|
|
|
29109
|
$$refINPUT =~ s/^sin\b(?![\.-])//o and return ('SIN', undef); |
368
|
10036
|
100
|
|
|
|
33450
|
$$refINPUT =~ s/^is-a\b(?![\.-])//o and return ('ISA', undef); |
369
|
10026
|
100
|
|
|
|
25353
|
$$refINPUT =~ s/^reifies\b(?![\.-])//o and return ('REIFIES', undef); |
370
|
9746
|
50
|
|
|
|
52490
|
$$refINPUT =~ s/^=//o and return ('REIFIES', undef); |
371
|
9746
|
100
|
|
|
|
20038
|
$$refINPUT =~ s/^is-reified-by\b(?![\.-])//o and return ('ISREIFIED', undef); |
372
|
9743
|
50
|
|
|
|
18219
|
$$refINPUT =~ s/^~//o and return ('ISINDICATEDBY', undef); |
373
|
|
|
|
|
|
|
|
374
|
9743
|
100
|
|
|
|
44230
|
if (my $t = $parser->{USER}->{string}) { # parser said we should expect a string now, defaults terminator to \n |
375
|
|
|
|
|
|
|
##warn "scanning for string (..$t..) in ...". $$refINPUT . "...."; |
376
|
6602
|
100
|
|
|
|
22707
|
$$refINPUT =~ s/^:\s*<<<\n/:/o and # we know it better, it is <<< |
377
|
|
|
|
|
|
|
$t = "\n<<<\n"; |
378
|
|
|
|
|
|
|
|
379
|
6602
|
100
|
|
|
|
15349
|
$$refINPUT =~ s/^:\s*<<(\w+)\n/:/o and # we know it better, it is <
|
380
|
|
|
|
|
|
|
$t = "\n<<$1\n"; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
##warn "try finding string ..$t.. " ; |
383
|
6602
|
100
|
50
|
|
|
66064
|
$$refINPUT =~ s/^:\s*(.*?)\s*$t/\n/s and |
384
|
|
|
|
|
|
|
## (warn "returning $1" or 1) and |
385
|
|
|
|
|
|
|
(undef $parser->{USER}->{string} or return ('STRING', $1)); |
386
|
|
|
|
|
|
|
##warn "no string"; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
7085
|
100
|
|
|
|
16920
|
$$refINPUT =~ s/^://o and return ('COLON', undef); |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
## unfortunately, this does not what I want |
392
|
|
|
|
|
|
|
## $$refINPUT =~ s/^([A-Za-z][A-Za-z0-9_-]*)(?!:)//o and return ('ID', $1); # negative look-ahead |
393
|
|
|
|
|
|
|
## tricky optimization: don't ask |
394
|
7052
|
100
|
66
|
|
|
92163
|
$$refINPUT =~ s/^([A-Za-z][.A-Za-z0-9_-]*)//o and $aux = $1 # save this for later |
|
|
|
100
|
|
|
|
|
395
|
|
|
|
|
|
|
and $$refINPUT !~ /^:[\w\/]/ |
396
|
|
|
|
|
|
|
and return ('ID', $aux); |
397
|
|
|
|
|
|
|
|
398
|
3408
|
100
|
|
|
|
13822
|
$$refINPUT =~ s/^\(//so and return ('LPAREN', undef); |
399
|
2414
|
100
|
|
|
|
13775
|
$$refINPUT =~ s/^\)//so and return ('RPAREN', undef); |
400
|
1422
|
100
|
|
|
|
9998
|
$$refINPUT =~ s/^@//so and return ('AT', undef); |
401
|
|
|
|
|
|
|
|
402
|
316
|
100
|
|
|
|
7395
|
$$refINPUT =~ s/^(:[^\s\)\(\]\[]+)//o and return ('ID', $aux.$1); # is a URL/URN actually |
403
|
|
|
|
|
|
|
|
404
|
19
|
100
|
100
|
|
|
89
|
$$refINPUT =~ s/^(\d{4}-\d{1,2}-\d{1,2})(\s+(\d{1,2}):(\d{2}))?//o |
|
|
|
100
|
|
|
|
|
405
|
|
|
|
|
|
|
and return ('ID', sprintf "urn:x-date:%s:%02d:%02d", $1, $3 || 0, $4 || 0); # is a date |
406
|
|
|
|
|
|
|
|
407
|
17
|
100
|
|
|
|
50
|
$$refINPUT =~ s/^%log\s+(.*?)(?=\n)//so and return ('LOG', $1); # positive look-ahead |
408
|
16
|
100
|
|
|
|
47
|
$$refINPUT =~ s/^%cancel\s*(?=\n)//so and return ('CANCEL', $1); # positive look-ahead |
409
|
14
|
100
|
|
|
|
45
|
$$refINPUT =~ s/^%trace\s+(.*?)(?=\n)//so and return ('TRACE', $1); # positive look-ahead |
410
|
12
|
100
|
|
|
|
45
|
$$refINPUT =~ s/^%encoding\s+(.*?)(?=\n)//so and return ('ENCODING', $1); # positive look-ahead |
411
|
|
|
|
|
|
|
|
412
|
10
|
100
|
|
|
|
37
|
$$refINPUT =~ s/^\*//o and return ('ID', sprintf "uuid-%010d", $TM::toplet_ctr++); ## $parser->{USER}->{topic_count}++); |
413
|
|
|
|
|
|
|
|
414
|
8
|
100
|
|
|
|
37
|
$$refINPUT =~ s/^\[//so and return ('LBRACKET', undef); |
415
|
4
|
50
|
|
|
|
27
|
$$refINPUT =~ s/^\]//so and return ('RBRACKET', undef); |
416
|
|
|
|
|
|
|
# should not be an issue except on error |
417
|
0
|
0
|
|
|
|
0
|
$$refINPUT =~ s/^(.)//so and return ($1, $1); |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
} |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
sub parse { |
422
|
293
|
|
|
293
|
0
|
1815
|
my $self = shift; |
423
|
293
|
|
|
|
|
977
|
$_ = shift; |
424
|
|
|
|
|
|
|
|
425
|
293
|
|
|
|
|
1365
|
s/\r\n/\n/sg; |
426
|
293
|
|
|
|
|
756
|
s/\r/\n/sg; |
427
|
293
|
|
|
|
|
797
|
s/(?
|
428
|
293
|
|
|
|
|
1026
|
s/ \~ /\n/g; # replace _~_ with \n |
429
|
293
|
|
|
|
|
894
|
s/ \~\~ / \~ /g; # stuffed ~~ cleanout |
430
|
293
|
|
|
|
|
1549
|
s/^\#.*?\n/\n/mg; # # at the start of every line -> gone |
431
|
293
|
|
|
|
|
1447
|
s/\s\#.*?\n/\n/mg; # anything which starts with # -> gone |
432
|
293
|
|
|
|
|
826
|
s/(?
|
433
|
293
|
|
|
|
|
3556
|
s/\n\n\n+/\n\n/sg; # canonicalize line break (line count is gone already) |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
# we not only capture what is said EXPLICITELY in the map, we also collect implicit knowledge |
436
|
|
|
|
|
|
|
# we could add this immediately into the map at parsing, but it would slow the process down and |
437
|
|
|
|
|
|
|
# it would probably duplicate/complicate things |
438
|
293
|
|
|
|
|
2043
|
$self->{USER}->{implicits} = { |
439
|
|
|
|
|
|
|
'isa-thing' => undef, # just let them spring into existence |
440
|
|
|
|
|
|
|
'isa-scope' => undef, # just let them spring into existence |
441
|
|
|
|
|
|
|
'subclasses' => undef |
442
|
|
|
|
|
|
|
}; |
443
|
|
|
|
|
|
|
# clone a pseudo map into which to store templates as assocs temporarily |
444
|
293
|
|
|
|
|
2182
|
$self->{USER}->{templates} = new TM (baseuri => $self->{USER}->{store}->baseuri); |
445
|
|
|
|
|
|
|
|
446
|
293
|
|
|
|
|
2090
|
$self->YYData->{INPUT} = ''; |
447
|
293
|
|
|
|
|
2908
|
$self->YYData->{RESERVE} = $_; # here we park the whole string |
448
|
293
|
|
|
|
|
2555
|
$self->YYData->{TOTAL} = length ($_); # this is how much we have in the reserve |
449
|
293
|
|
|
|
|
2215
|
$self->YYData->{OFFSET} = 0; # and we start at index 0 |
450
|
|
|
|
|
|
|
|
451
|
293
|
|
|
|
|
2203
|
eval { |
452
|
293
|
|
|
|
|
2648
|
$self->YYParse ( yylex => \&_Lexer, yyerror => \&_Error ); |
453
|
293
|
100
|
|
|
|
34870
|
}; if ($@ =~ /^Cancelled/) { |
|
|
100
|
|
|
|
|
|
454
|
2
|
|
|
|
|
92
|
warn $@; # de-escalate Cancelling to warning |
455
|
|
|
|
|
|
|
} elsif ($@) { |
456
|
16
|
|
|
|
|
3340
|
die $@; # otherwise re-raise the exception |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
{ # resolving implicit stuff |
461
|
277
|
|
|
|
|
403
|
my $implicits = $self->{USER}->{implicits}; |
|
277
|
|
|
|
|
906
|
|
462
|
277
|
|
|
|
|
640
|
my $store = $self->{USER}->{store}; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
{ # all super/subclasses |
465
|
277
|
|
|
|
|
359
|
foreach my $superclass (keys %{$implicits->{'subclasses'}}) { |
|
277
|
|
|
|
|
443
|
|
|
277
|
|
|
|
|
1406
|
|
466
|
337
|
|
|
|
|
3404
|
$store->assert ( map { |
467
|
228
|
|
|
|
|
869
|
bless [ undef, undef, 'is-subclass-of', TM->ASSOC, [ 'superclass', 'subclass' ], [ $superclass, $_ ] ], 'Assertion' |
468
|
228
|
|
|
|
|
559
|
} keys %{$implicits->{'subclasses'}->{$superclass}}); |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
#warn "done with subclasses"; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
{ # all things in isa-things are THINGS, simply add them |
473
|
|
|
|
|
|
|
##warn "isa things ".Dumper [keys %{$implicits->{'isa-thing'}}]; |
474
|
277
|
|
|
|
|
869
|
$store->internalize (map { $_ => undef } keys %{$implicits->{'isa-thing'}}); |
|
277
|
|
|
|
|
511
|
|
|
1627
|
|
|
|
|
3179
|
|
|
277
|
|
|
|
|
1250
|
|
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
{ # establishing the scoping topics |
477
|
277
|
|
|
|
|
832
|
$store->assert (map { |
|
741
|
|
|
|
|
5155
|
|
478
|
277
|
|
|
|
|
7365
|
bless [ undef, undef, 'isa', TM->ASSOC, [ 'class', 'instance' ], [ 'scope', $_ ] ], 'Assertion' |
479
|
277
|
|
|
|
|
601
|
} keys %{$implicits->{'isa-scope'}}); |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
277
|
|
|
|
|
1764
|
return $self->{USER}->{store}; |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
#my $f = new TM::AsTMa::Fact; |
487
|
|
|
|
|
|
|
#$f->Run; |