source: fmts/trunk/p/C0XMAIN2.m@ 1343

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

version that blocks updates with more timings - may be broken

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