source: fmts/trunk/p/C0XF2N.m@ 1278

Last change on this file since 1278 was 1277, checked in by George Lilly, 13 years ago

a new user prompting entry point FILEINC0XF2N and more timing messages

File size: 19.7 KB
RevLine 
[1277]1C0XMAIN ; GPL - Fileman Triples entry point routine ;10/13/11 17:05
2 ;;0.1;C0X;nopatch;noreleasedate;Build 1
3 ;Copyright 2011 George Lilly. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 Q
21 ;
22 ; This is based on C0XMAIN but experiments with a fast load for triples
23 ; that will write directly to the fileman global
24 ; The file 172.101 is a F2N design style for triples, which means
25 ; that it is a Flat file with no subfiles, all fields at the root
26 ; ... it is a "2" file solution which means all strings are stored in
27 ; ... strings file and pointed to by the triples file
28 ; ... it is an N file because it has generated Node IDs instead of
29 ; ... DINUM which would use the IEN for the Node ID.
30 ; gpl 11/04/2011
31 ;
32INITFARY(ZFARY) ; INITIALIZE FILE NUMBERS AND OTHER USEFUL THINGS
33 ; FOR THE DEFAULT TRIPLE STORE. USE OTHER VALUES FOR SUPPORTING ADDITIONAL
34 ; TRIPLE STORES
35 S @ZFARY@("C0XTFN")=172.101 ; TRIPLES FILE NUMBER
36 S @ZFARY@("C0XSFN")=172.201 ; TRIPLES STRINGS FILE NUMBER
37 S @ZFARY@("C0XTN")=$NA(^C0X(101)) ; TRIPLES GLOBAL NAME
38 S @ZFARY@("C0XSN")=$NA(^C0X(201)) ; STRING FILE GLOBAL NAME
39 S @ZFARY@("C0XDIR")="/home/glilly/rdf/"
40 D USEFARY(ZFARY)
41 Q
42 ;
43USEFARY(ZFARY) ; INITIALIZES VARIABLES SAVED IN ARRAY ZFARY
44 N ZI S ZI=""
45 F S ZI=$O(@ZFARY@(ZI)) Q:ZI="" D
46 . ;N ZX
47 . S ZX="S "_ZI_"="""_@ZFARY@(ZI)_""""
48 . ;W !,ZX
49 . X ZX
50 Q
51 ;
52FILEIN ; INTERACTIVE ENTRY POINT FOR OPTION TO READ IN A FILE
53 I '$D(C0XFARY) D INITFARY("C0XFARY")
54 D USEFARY("C0XFARY")
55 S DIR(0)="F^3:240"
56 S DIR("A")="File Directory"
57 S DIR("B")=C0XDIR
58 D ^DIR
59 I Y="^" Q ;
60 S C0XDIR=Y
61 S C0XFARY("C0XDIR")=Y
62 S DIR(0)="F^3:240"
63 S DIR("A")="File Name"
64 I '$D(C0XFN) S DIR("B")="qds.rdf"
65 E S DIR("B")=C0XFN
66 D ^DIR
67 I Y="" Q ;
68 I Y="^" Q ;
69 S C0XFN=Y
70 D IMPORT(C0XFN,C0XDIR,,"C0XFARY")
71 Q
72 ;
73IMPORT(FNAME,FDIR,FURL,FARY) ; EXTRINSIC THAT READS A FILE FROM THE STANDARD
74 ; DIRECTORY, LOADS IT INTO THE TRIPLESTORE AS TEXT, AND RETURNS THE
75 ; NODE NAME OF THE TEXT TRIPLE
76 ; FDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR)
77 ; FURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE
78 ; FARY IS THE OPTIONAL FILE ARRAY OF THE TRIPLE STORE TO USE
79 I '$D(FARY) D ;
80 . D INITFARY("C0XFARY")
81 . S FARY="C0XFARY"
82 D USEFARY(FARY)
83 N ZD,ZTMP
84 I '$D(FDIR) S FDIR=C0XDIR ; DIRECTORY OF THE RDF FILE
85 I '$D(FURL) D ;
86 . N ZN2 S ZN2=$TR(FNAME,".","_") ; REMOVE THE DOT FROM THE NAME
87 . S FURL=FDIR_ZN2
88 N ZTMP
89 S ZTMP=$NA(^TMP("C0X",$J,"FILEIN",1)) ; WHERE TO PUT THE INCOMING FILE
90 K @ZTMP ; MAKE SURE IT'S CLEAR
91 S C0XSTART=$$NOW^XLFDT
92 W !,"STARTED: ",C0XSTART
93 W !,"READING IN: ",FNAME
94 I '$$FILEREAD(ZTMP,FDIR,FNAME,4) D Q ; QUIT IF NO SUCCESS
95 . W !,"ERROR READING FILE: ",FDIR,FNAME
96 S ZRDF=$NA(^TMP("C0X",$J,"FILEIN")) ; WITHOUT THE SUBSCRIPT
97 W !,$O(@ZRDF@(""),-1)," LINES READ"
98 D INSRDF(ZRDF,FURL,FARY) ; IMPORT AND PROCESS THE RDF
99 Q
100 ;
101WGET(ZURL,FARY) ; GET FROM THE INTERNET AN RDF FILE AND INSERT IT
102 ;
103 I '$D(FARY) D ;
104 . D INITFARY("C0XFARY")
105 . S FARY="C0XFARY"
106 D USEFARY(FARY)
107 ;N ZLOC,ZTMP
108 K ZTMP
109 S ZLOC=$NA(^TMP("C0X","WGET",$J))
110 K @ZLOC
111 S C0XSTART=$$NOW^XLFDT
112 W !,"STARTED: ",C0XSTART
113 W !,"DOWNLOADING: ",ZURL
114 S OK=$$httpGET^%zewdGTM(ZURL,.ZTMP)
115 M @ZLOC=ZTMP
116 S C0XLINES=$O(@ZLOC@(""),-1)
117 W !,C0XLINES," LINES READ"
118 S C0XDLC=$$NOW^XLFDT ; DOWNLOAD COMPLETE
119 W !,"DOWNLOAD COMPLETE AT ",C0XDLC
120 S C0XDIFF=$$FMDIFF^XLFDT(C0XDLC,C0XSTART,2)
121 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
122 I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XLINES/C0XDIFF,".")," LINES PER SEC"
123 D INSRDF(ZLOC,ZURL,FARY)
124 Q
125 ;
126INSRDF(ZRDF,ZNAME,FARY) ; INSERT AN RDF FILE INTO THE STORE AND PROCESS
127 ; ZRDF IS PASSED BY NAME
128 I '$D(FARY) D ;
129 . D INITFARY("C0XFARY")
130 . S FARY="C0XFARY"
131 D USEFARY(FARY)
132 N ZGRAPH,ZSUBJECT
133 S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME
134 S ZSUBJECT=$$ANONS ; RANDOM ANOYMOUS SUBJECT
135 D ADD(ZGRAPH,ZSUBJECT,"fmts:url",ZNAME,FARY)
136 N ZTXTNM
137 S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE
138 D ADD(ZGRAPH,ZSUBJECT,"fmts:rdfSource",ZTXTNM,FARY)
139 D UPDIE(.C0XFDA) ; TRY IT OUT
140 K C0XCNT ;RESET FOR NEXT TIME
141 D STORETXT(ZRDF,ZTXTNM,FARY)
142 W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:rdfSource ",ZTXTNM
143 D PROCESS2(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF
144 Q
145 ;
146STORETXT(ZTXT,ZNAME,FARY) ; STORE TEXT IN THE TRIPLESTORE AT ZNAME
147 ;
148 I '$D(FARY) D ;
149 . D INITFARY("C0XFARY")
150 . S FARY="C0XFARY"
151 D USEFARY(FARY)
152 N ZIEN
153 S ZIEN=$$IENOF(ZNAME,FARY) ; GET THE IEN
154 D CLEAN^DILF
155 K ZERR
156 D WP^DIE(C0XSFN,ZIEN_",",1,,ZTXT,"ZERR")
157 I $D(ZERR) D ;
158 . ZWR ZERR
159 Q
160 ;
161GETTXT(ZRTN,ZNAME,FARY) ; RETURNS RDF SOURCE OR OTHER TEXT
162 ; ZRTN IS PASSED BY REFERENCE
163 I '$D(FARY) D ;
164 . D INITFARY("C0XFARY")
165 . S FARY="C0XFARY"
166 D USEFARY(FARY)
167 N ZIEN
168 S ZIEN=$$IENOF(ZNAME)
169 S OK=$$GET1^DIQ(C0XSFN,ZIEN_",",1,,"ZRTN")
170 Q
171 ;
172WHERETXT(ZNAME,FARY) ; EXTRINSIC WHICH RETURNS THE NAME OF THE GLOBAL
173 ; WHERE THE TEXT IS LOCATED. NAME IS THE NAME OF THE STRING
174 I '$D(FARY) D ;
175 . D INITFARY("C0XFARY")
176 . S FARY="C0XFARY"
177 D USEFARY(FARY)
178 N ZIEN
179 S ZIEN=$$IENOF(ZNAME)
180 Q $NA(@C0XSN@(ZIEN,1))
181 ;
182FILEREAD(ZINTMP,ZDIR,ZFNAME,ZLVL) ; READS A FILE INTO ZINTMP USING FTG^%ZISH
183 ; ZINTMP IS PASSED BY NAME AND INCLUDES THE NEW SUBSCRIPT
184 ; IE ^TMP("C0X","FILEIN",1)
185 ; ZLVL IN THIS CASE WOULD BE 3 INCREMENTING THE 1
186 ; EXTRINSIC WHICH RETURNS THE RESULT OF FTG^%ZISH
187 S OK=$$FTG^%ZISH(ZDIR,FNAME,ZINTMP,ZLVL)
188 Q OK
189 ;
190TESTPROC ; TEST PROCESS WITH EXISTING SMALL RDF FILE
191 S ZIN=$NA(^TMP("C0X",12226,"FILEIN"))
192 S ZGRAPH="/test/rdfFile"
193 S ZM="/test/rdfFile/meta"
194 D PROCESS(.G,ZIN,ZGRAPH,ZM)
195 Q
196 ;
197PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE
198 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING
199 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE
200 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS
201 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA
202 ;
203 I '$D(FARY) D ;
204 . D INITFARY("C0XFARY")
205 . S FARY="C0XFARY"
206 D USEFARY(FARY)
207 ; -- first parse the rdf file with the MXML parser
208 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML
209 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W")
210 ; -- assign the MXLM dom global name to ZDOM
211 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID))
212 W !,$O(@ZDOM@(""),-1)," XML NODES PARSED"
213 ; -- populate the metagraph to point to the graph with status unfinished
214 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT
215 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH
216 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH
217 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished
218 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT")
219 S C0XDATE=$$NOW^XLFDT
220 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY)
221 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store
222 ; --
223 ; -- pull out the vocabularies in the RDF statement. marked with xmlns:
224 ; -- put them in a local variable for quick reference
225 ; -- TODO: create a graph for vocabularies and validate incoming against it
226 ;
227 S C0XVOC=""
228 N ZI,ZJ,ZK S ZI=""
229 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns
230 . S ZVOC=$P(ZI,"xmlns:",2)
231 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))
232 ;W !,"VOCABS:" ZWR C0XVOC
233 ;
234 ; -- look for children called rdf:Description. quit if none. not an rdf file
235 ;
236 S ZI=$O(@ZDOM@(1,"C",""))
237 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file
238 . W !,"Error. Not an RDF file. Cannot process."
239 ;
240 ; -- now process the rdf description children
241 ;
242 S ZI=""
243 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate
244 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ;
245 . ; -- we are skipping any child that is not rdf:Description
246 . ; -- TODO: check to see if this is right in general
247 . ;
248 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ;
249 . . W !,"SKIPPING NODE: ",ZI
250 . ; -- now looking for the subject for the triples
251 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about"))
252 . I ZX'="" D ; we have the subject
253 . . ;W " about: ",ZX
254 . . S C0XSUB=ZX
255 . E D ;
256 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject
257 . . I ZX'="" D ;
258 . . . S C0XSUB=ZX
259 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT
260 . ;
261 . ; -- we now have the subject. the children of this node have the rest
262 . ;
263 . S ZJ="" ; for the children of the rdf:Description nodes
264 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child
265 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix
266 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space
267 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix
268 . . I C0XPRE[":" D ; expand using vocabulary
269 . . . N ZB,ZA
270 . . . S ZB=$P(C0XPRE,":",1)
271 . . . S ZA=$P(C0XPRE,":",2)
272 . . . I $G(C0XVOC(ZB))'="" D ;
273 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
274 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object
275 . . I ZY'="" D Q ;
276 . . . S C0XOBJ=ZY ; object
277 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple
278 . . ; -- this is an else because of the quit above
279 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object
280 . . I ZX'="" D Q ; got one
281 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject
282 . . . ; without change... this could be foolish .. look at it again later
283 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
284 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here
285 . . I C0XOBJ="" D Q ; not a happy situation
286 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ
287 . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
288 W !,"INSERTING ",C0XCNT," TRIPLES"
289 D UPDIE(.C0XFDA) ; commit the updates to the file
290 ; next, mark the graph as finished
291 S C0XEND=$$NOW^XLFDT
292 W !," ENDED AT: ",C0XEND
293 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2)
294 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
295 I C0XDIFF'=0 D ;
296 . W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
297 Q
298 ;
299PROCESS2(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE
300 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING
301 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE
302 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS
303 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA
304 ;
305 I '$D(FARY) D ;
306 . D INITFARY("C0XFARY")
307 . S FARY="C0XFARY"
308 D USEFARY(FARY)
309 ;N BATCNT
310 ;N BATMAX
311 S BATCNT=0 ; BATCH COUNTER
312 S BATMAX=10000 ; TRY BATCHES OF THIS SIZE
313 ; -- first parse the rdf file with the MXML parser
314 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML
315 S C0XDLC2=$$NOW^XLFDT ; START OF PARSE
316 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W")
317 ; -- assign the MXLM dom global name to ZDOM
318 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID))
319 S C0XNODE=$O(@ZDOM@(""),-1)
320 W !,C0XNODE," XML NODES PARSED"
321 S C0XPRS=$$NOW^XLFDT ; PARSE COMPLETE
322 W !,"PARSE COMPLETE AT ",C0XPRS
323 S C0XDIFF=$$FMDIFF^XLFDT(C0XPRS,C0XDLC2,2)
324 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
325 I C0XDIFF'=0 D ;
326 . W !," APPROXIMATELY ",$P(C0XNODE/C0XDIFF,".")," NODES PER SECOND"
327 ; -- populate the metagraph to point to the graph with status unfinished
328 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT
329 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH
330 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH
331 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished
332 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT")
333 S C0XDATE=$$NOW^XLFDT
334 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY)
335 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store
336 ; --
337 ; -- pull out the vocabularies in the RDF statement. marked with xmlns:
338 ; -- put them in a local variable for quick reference
339 ; -- TODO: create a graph for vocabularies and validate incoming against it
340 ;
341 S C0XVOC=""
342 N ZI,ZJ,ZK S ZI=""
343 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns
344 . S ZVOC=$P(ZI,"xmlns:",2)
345 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))
346 ;W !,"VOCABS:" ZWR C0XVOC
347 ;
348 ; -- look for children called rdf:Description. quit if none. not an rdf file
349 ;
350 S ZI=$O(@ZDOM@(1,"C",""))
351 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file
352 . W !,"Error. Not an RDF file. Cannot process."
353 ;
354 ; -- now process the rdf description children
355 ;
356 S ZI=""
357 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate
358 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ;
359 . ; -- we are skipping any child that is not rdf:Description
360 . ; -- TODO: check to see if this is right in general
361 . ;
362 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ;
363 . . W !,"SKIPPING NODE: ",ZI
364 . ; -- now looking for the subject for the triples
365 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about"))
366 . I ZX'="" D ; we have the subject
367 . . ;W " about: ",ZX
368 . . S C0XSUB=ZX
369 . E D ;
370 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject
371 . . I ZX'="" D ;
372 . . . S C0XSUB=ZX
373 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT
374 . ;
375 . ; -- we now have the subject. the children of this node have the rest
376 . ;
377 . S ZJ="" ; for the children of the rdf:Description nodes
378 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child
379 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix
380 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space
381 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix
382 . . I C0XPRE[":" D ; expand using vocabulary
383 . . . N ZB,ZA
384 . . . S ZB=$P(C0XPRE,":",1)
385 . . . S ZA=$P(C0XPRE,":",2)
386 . . . I $G(C0XVOC(ZB))'="" D ;
387 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
388 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object
389 . . I ZY'="" D Q ;
390 . . . S C0XOBJ=ZY ; object
391 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple
392 . . ; -- this is an else because of the quit above
393 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object
394 . . I ZX'="" D Q ; got one
395 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject
396 . . . ; without change... this could be foolish .. look at it again later
397 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
398 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here
399 . . I C0XOBJ="" D Q ; not a happy situation
400 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ
401 . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
402 S C0XTRP=$$NOW^XLFDT ; PARSE COMPLETE
403 W !,"TRIPLES COMPLETE AT ",C0XTRP
404 S C0XDIFF=$$FMDIFF^XLFDT(C0XTRP,C0XPRS,2)
405 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
406 I C0XDIFF'=0 D ;
407 . W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
408 W !,"INSERTING ",C0XCNT," TRIPLES"
409 I $D(C0XFDA) D UPDIE(.C0XFDA) ; commit the updates to the file
410 ; next, mark the graph as finished
411 S C0XINS=$$NOW^XLFDT ; PARSE COMPLETE
412 W !,"INSERTION COMPLETE AT ",C0XPRS
413 S C0XDIFF=$$FMDIFF^XLFDT(C0XINS,C0XTRP,2)
414 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
415 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," NODES PER SECOND"
416 S C0XEND=$$NOW^XLFDT
417 W !," ENDED AT: ",C0XEND
418 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2)
419 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
420 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
421 Q
422 ;
423SHOW(ZN) ;
424 ZWR ^TMP("MXMLDOM",$J,1,ZN,*)
425 Q
426 ;
427ANONS() ; RETURNS AN ANONOMOUS SUBJECT
428 Q "_S:"_$$LKY9
429 ;
430NEWG(NGRAPH,NMETA) ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED
431 ; THEN CREATES A NEW GRAPH AND POINTS THE METAGRAPH TO IT
432 ; NGRAPH AND NMETA ARE PASSED BY REFERENCE AND ARE THE RETURN
433 S NGRAPH="G"_$$LKY9
434 S NMETA=NGRAPH_"A"
435 Q
436 ;
437ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
438 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE
439 I '$D(FARY) D ;
440 . D INITFARY("C0XFARY")
441 . S FARY="C0XFARY"
442 D USEFARY(FARY)
443 I '$D(C0XCNT) S C0XCNT=0
444 N ZNODE
445 S ZNODE="N"_$$LKY17
446 N ZNARY ; GET READY TO CALL IENOFA
447 S ZNARY("ZG",ZG)=""
448 S ZNARY("ZS",ZS)=""
449 S ZNARY("ZP",ZP)=""
450 S ZNARY("ZO",ZO)=""
451 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS
452 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN
453 ;S ZSIEN=$$IENOF(ZS)
454 ;S ZPIEN=$$IENOF(ZP)
455 ;S ZOIEN=$$IENOF(ZO)
456 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED
457 S C0XCNT=C0XCNT+1
458 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.01)=ZNODE
459 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.02)=$O(ZIENS("IEN","ZG",""))
460 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.03)=$O(ZIENS("IEN","ZS",""))
461 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.04)=$O(ZIENS("IEN","ZP",""))
462 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.05)=$O(ZIENS("IEN","ZO",""))
463 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE
464 Q
465 ;
466ADD2(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
467 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE
468 I '$D(FARY) D ;
469 . D INITFARY("C0XFARY")
470 . S FARY="C0XFARY"
471 D USEFARY(FARY)
472 I '$D(C0XCNT) S C0XCNT=0
473 N ZNODE
474 S ZNODE="N"_$$LKY17
475 N ZNARY ; GET READY TO CALL IENOFA
476 S ZNARY("ZG",ZG)=""
477 S ZNARY("ZS",ZS)=""
478 S ZNARY("ZP",ZP)=""
479 S ZNARY("ZO",ZO)=""
480 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS
481 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN
482 ;S ZSIEN=$$IENOF(ZS)
483 ;S ZPIEN=$$IENOF(ZP)
484 ;S ZOIEN=$$IENOF(ZO)
485 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED
486 S BATCNT=BATCNT+1
487 S C0XCNT=C0XCNT+1
488 S C0XFDA(C0XTFN,"?+"_BATCNT_",",.01)=ZNODE
489 S C0XFDA(C0XTFN,"?+"_BATCNT_",",.02)=$O(ZIENS("IEN","ZG",""))
490 S C0XFDA(C0XTFN,"?+"_BATCNT_",",.03)=$O(ZIENS("IEN","ZS",""))
491 S C0XFDA(C0XTFN,"?+"_BATCNT_",",.04)=$O(ZIENS("IEN","ZP",""))
492 S C0XFDA(C0XTFN,"?+"_BATCNT_",",.05)=$O(ZIENS("IEN","ZO",""))
493 I BATCNT=BATMAX D ; BATCH IS DONE
494 . D UPDIE(.C0XFDA)
495 . K C0XFDA
496 . S BATCNT=0 ; RESET COUNTER
497 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE
498 Q
499 ;
500LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
501 ; UNIQUE NODE AND GRAPH NAMES
502 N ZN,ZI
503 S ZN=""
504 F ZI=1:1:9 D ;
505 . S ZN=ZN_$R(10)
506 Q ZN
507 ;
508LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
509 ; UNIQUE NODE AND GRAPH NAMES
510 N ZN,ZI
511 S ZN=""
512 F ZI=1:1:17 D ;
513 . S ZN=ZN_$R(10)
514 Q ZN
515 ;
516IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
517 I '$D(FARY) D ;
518 . D INITFARY("C0XFARY")
519 . S FARY="C0XFARY"
520 N ZIEN
521 S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
522 I ZIEN="" D ;
523 . S C0XFDA2(C0XSFN,"+1,",.01)=ZSTRING
524 . D UPDIE(.C0XFDA2)
525 . S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
526 . K C0XFDA2
527 Q ZIEN
528 ;
529IENOFA(ZOUTARY,ZINARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
530 ; OR ADD THEM IF
531 ; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE
532 ; ZINARY LOOKS LIKE ZINARY("VAR","VAL")=""
533 ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)=""
534 I '$D(FARY) D ;
535 . D INITFARY("C0XFARY")
536 . S FARY="C0XFARY"
537 K ZOUTARY ; START WITH CLEAN RESULTS
538 K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
539 N ZI S ZI=""
540 N ZV,ZIEN
541 N ZCNT S ZCNT=0
542 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; LOOK FOR MISSING STRINGS
543 . S ZV=$O(ZINARY(ZI,""))
544 . I $O(@C0XSN@("B",ZV,""))="" D ;
545 . . S ZCNT=ZCNT+1
546 . . S C0XFDA2(C0XSFN,"+"_ZCNT_",",.01)=ZV
547 I $D(C0XFDA2) D ;
548 . D UPDIE(.C0XFDA2) ; ADD MISSING STRINGS
549 . K C0XFDA2 ; CLEAN UP
550 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; NOT GET ALL IENS
551 . S ZV=$O(ZINARY(ZI,""))
552 . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW
553 . I ZIEN="" D ;
554 . . W !,"ERROR ADDING STRING: ",ZV
555 . . B
556 . S ZOUTARY("IEN",ZI,ZIEN)=""
557 Q
558 ;
559UPDIE(ZFDA) ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
560 ; ZFDA IS PASSED BY REFERENCE
561 ;ZWR ZFDA
562 ;B
563 K ZERR
564 D CLEAN^DILF
565 D UPDATE^DIE("","ZFDA","","ZERR")
566 I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST,
567 ; INVOKE THE ERROR TRAP IF TASKED
568 ;. W "ERROR",!
569 ;. ZWR ZERR
570 ;. B
571 K ZFDA
572 Q
573 ;
Note: See TracBrowser for help on using the repository browser.