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

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

added retrival of triples

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