1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\ProvidesFileRCS{tikzlibraryrdf.code.tex}
\def\tikz@add@rdf@pre@option#1{\expandafter\def\expandafter\tikz@rdf@pre@options\expandafter{\tikz@rdf@pre@options#1}}%
\def\tikz@add@rdf@post@option#1{\expandafter\def\expandafter\tikz@rdf@post@options\expandafter{\tikz@rdf@post@options#1}}%
\let\tikz@rdf@pre@options\pgfutil@empty
\let\tikz@rdf@post@options\pgfutil@empty
\tikzset{
%
% Switching on the engine
%
rdf engine on/.code={%
\def\tikz@clear@rdf@options{\let\tikz@rdf@pre@options\pgfutil@empty\let\tikz@rdf@post@options\pgfutil@empty}%
\def\tikz@do@rdf@pre@options{\tikz@rdf@pre@options\let\tikz@rdf@pre@options\pgfutil@empty}%
\def\tikz@do@rdf@post@options{\tikz@rdf@post@options\let\tikz@rdf@post@options\pgfutil@empty}%
\pgfkeys{/tikz/rdf engine/.code=\tikz@add@rdf@pre@option{\pgfqkeys{/tikz/rdf engine}{##1}}}%
},
rdf engine/.cd,
%
every statement/.style=,
%
% Namespaces
%
prefix/.code=\pgfrdfprefix{#1},
%
% Core commands
%
statement/.code={%
{%
\pgfkeys{/tikz/rdf engine/every statement}%
\pgfqkeys{/tikz/rdf engine/statements}{#1}%
\iftikz@rdf@is@a@container\tikz@rdf@init@container\fi%
\iftikz@rdf@is@a@member\tikz@rdf@make@member\fi%
\tikz@rdf@make@triple%
\expandafter}\tikz@rdf@action%
},
get scope curie/.code={%
\ifx\tikz@id@name\pgfutil@empty%
\def\tikz@id@name{@rdf}%
\fi%
\pgfidrefnextuse\tikz@temp{\tikz@id@name}%
\edef#1{\tikzrdfhashmark\tikz@temp}%
},
get new resource curie/.code={%
\pgfsys@new@id\tikz@temp%
\edef#1{\tikzrdfhashmark\tikz@temp}%
},
scope is new context/.style={get scope curie=\tikzrdfcontext}
}%
\def\tikzrdfcontext{\tikzrdfhashmark}%empty by default
\tikzset{
rdf engine/statements/.cd,
%
% Core properties of statements
%
subject/.code={%
\def\tikz@rdf@target{\tikz@rdf@subject}%
\tikz@rdf@parse{#1}%
},
predicate/.code={%
\def\tikz@rdf@target{\tikz@rdf@predicate}%
\tikz@rdf@parse{#1}%
},
object/.code={%
\let\tikz@rdf@object@literal\relax%
\let\tikz@rdf@object\relax%
\def\tikz@temp{#1}%
\ifx\tikz@temp\tikz@rdf@current@scope@text%
\tikz@rdf@object@scope@contenttrue%
\else%
\tikz@rdf@object@scope@contentfalse%
\def\tikz@rdf@target{\tikz@rdf@object}%
\tikz@rdf@parse{#1}%
\fi%
},
%
% Shorthands
%
has type/.style={predicate=rdf:type,object={#1}},
%
% Containers
%
is a bag/.style={has type=rdf:Bag, is a container},
is a sequence/.style={has type=rdf:Seq, is a container},
is an alternative/.style={has type=rdf:Alt, is a container},
%
is a container/.code={\tikz@rdf@is@a@containertrue},
%
has as member/.code={\tikz@rdf@is@a@membertrue},%
}%
\def\tikz@rdf@current@scope@text{scope content}%
\let\tikz@rdf@subject\relax
\let\tikz@rdf@predicate\pgfutil@empty
\let\tikz@rdf@object\relax
\let\tikz@rdf@object@literal\relax
\let\tikz@rdf@container\relax
\newif\iftikz@rdf@object@scope@content
\newif\iftikz@rdf@is@a@container
\newif\iftikz@rdf@is@a@member
\def\tikz@rdf@parse#1{%
\edef\tikz@temp{#1}%
\expandafter\tikz@rdf@parse@#1\relax%
}%
\def\tikz@rdf@parse@{%
\pgfutil@ifnextchar({\tikz@rdf@parse@name}{%)
\pgfutil@ifnextchar"{\tikz@rdf@parse@literals}{%
\tikz@rdf@parse@curie%
}%
}%
}%
\def\tikz@rdf@parse@name(#1)\relax{%
\pgfidrefprevuse\tikz@rdf@the@id{#1}\expandafter\edef\tikz@rdf@target{\tikzrdfhashmark\tikz@rdf@the@id}%
}%
\def\tikz@rdf@parse@literals"#1"{%
\ifx\tikz@rdf@target\tikz@rdf@object@name%
\def\tikz@rdf@object@literal{#1}%
\else%
\tikzerror{Only RDF objects can be literals}%
\fi%
\pgfutil@ifnextchar\relax\pgfutil@gobble\tikz@rdf@parse@literals@rest%
}%
\def\tikz@rdf@parse@literals@rest and scope content\relax{%
\tikz@rdf@object@scope@contenttrue%
}%
\def\tikz@rdf@object@name{\tikz@rdf@object}%
\def\tikz@rdf@parse@curie#1\relax{%
\expandafter\def\tikz@rdf@target{#1}%
}%
{%
\catcode`\#=11
\gdef\tikzrdfhashmark{#}%
}%
\def\tikz@rdf@make@triple{%
% First, ensure that subject, predicate and object are set:
\ifx\tikz@rdf@subject\relax%
\tikzerror{RDF statement misses subject}%
\else%
\ifx\tikz@rdf@predicate\relax%
\tikzerror{RDF statement misses predicate}%
\else%
\iftikz@rdf@object@scope@content%
\edef\tikz@marshal{\noexpand\tikz@rdf@make@content@triple{\tikz@rdf@subject}{\tikz@rdf@predicate}{\tikz@rdf@object@literal}}%
\tikz@marshal%
\else%
\ifx\tikz@rdf@object\relax%
\ifx\tikz@rdf@object@literal\relax%
\tikzerror{RDF statement misses object}%
\else%
\edef\tikz@marshal{\noexpand\tikz@rdf@make@literal@triple{\tikz@rdf@subject}{\tikz@rdf@predicate}{\tikz@rdf@object@literal}}%
\tikz@marshal%
\fi%
\else%
\edef\tikz@marshal{\noexpand\tikz@rdf@make@normal@triple{\tikz@rdf@subject}{\tikz@rdf@predicate}{\tikz@rdf@object}}%
\tikz@marshal%
\fi%
\fi%
\fi%
\fi%
}%
\def\tikz@rdf@make@content@triple#1#2#3{%
\def\tikz@rdf@action{%
\def\tikz@rdf@invoke@code{%
\def\tikz@temp{#3}%
\ifx\tikz@temp\tikz@rdf@object@literal@text\else%
\pgfrdfcontent{#3}%
\fi%
\pgfrdfabout{#1}%
\pgfrdfdatatype{rdf:XMLLiteral}%
\foreach \tikz@rdf@pred in {#2}{%
\ifx\tikz@rdf@pred\pgfutil@empty\else%
\expandafter\pgfrdfproperty\expandafter{\tikz@rdf@pred}%
\fi%
}%
}%
}%
}%
\def\tikz@rdf@make@literal@triple#1#2#3{%
\def\tikz@rdf@action{%
\tikz@add@rdf@post@option{%
{%
\pgfrdfabout{#1}%
\foreach \tikz@rdf@pred in {#2}{%
\ifx\tikz@rdf@pred\pgfutil@empty\else%
\expandafter\pgfrdfproperty\expandafter{\tikz@rdf@pred}%
\fi%
}%
\pgfrdfcontent{#3}%
\pgfidscope%
\endpgfidscope%
}%
}%
}%
}%
\def\tikz@rdf@make@normal@triple#1#2#3{%
\def\tikz@rdf@action{%
\tikz@add@rdf@post@option{%
{%
\pgfrdfabout{#1}%
\foreach \tikz@rdf@pred in {#2}{%
\ifx\tikz@rdf@pred\pgfutil@empty\else%
\expandafter\pgfrdfproperty\expandafter{\tikz@rdf@pred}%
\fi%
}%
\pgfrdfresource{#3}%
\pgfidscope%
\endpgfidscope%
}%
}%
}%
}%
\def\tikz@rdf@object@literal@text{\tikz@rdf@object@literal}%
% Containers
\def\tikz@rdf@init@container{%
\ifx\tikz@rdf@subject\relax%
\tikzerror{RDF statement misses subject}%
\else%
\expandafter\gdef\csname tikz@rdf@c@\tikz@rdf@subject\endcsname{0}%
\fi%
}%
\def\tikz@rdf@make@member{%
\ifx\tikz@rdf@subject\relax%
\tikzerror{RDF statement misses subject}%
\else%
% Get number:
\expandafter\let\expandafter\tikz@temp\csname tikz@rdf@c@\tikz@rdf@subject\endcsname%
\ifx\tikz@temp\relax%
\tikzerror{RDF subject is not a container}%
\else%
\c@pgf@counta\tikz@temp%
\advance\c@pgf@counta by1\relax%
\expandafter\xdef\csname tikz@rdf@c@\tikz@rdf@subject\endcsname{\the\c@pgf@counta}%
\edef\tikz@rdf@predicate{rdf:_\the\c@pgf@counta}%
\fi%
\fi%
}%
% Hooks:
\let\tikz@rdf@invoke@code\relax
\def\tikz@rdf@id@hook{%
\tikz@rdf@invoke@code%
\let\tikz@rdf@invoke@code\relax%
}%
% Add hook:
\expandafter\def\expandafter\tikz@id@hook\expandafter{\tikz@id@hook\tikz@rdf@id@hook}%
\endinput
|