Changeset 1294 for fmts/trunk/p
- Timestamp:
- Nov 12, 2011, 12:15:56 PM (13 years ago)
- Location:
- fmts/trunk/p
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fmts/trunk/p/C0XF2N.m
r1279 r1294 1 C0X MAIN ; GPL - Fileman Triples entry point routine ;10/13/11 17:052 ;;0.1;C0X;nopatch;noreleasedate;Build 11 C0XF2N ; GPL - Fileman Triples entry point routine ;10/13/11 17:05 2 ;;0.1;C0X;nopatch;noreleasedate;Build 5 3 3 ;Copyright 2011 George Lilly. Licensed under the terms of the GNU 4 4 ;General Public License See attached copy of the License. … … 33 33 ; FOR THE DEFAULT TRIPLE STORE. USE OTHER VALUES FOR SUPPORTING ADDITIONAL 34 34 ; TRIPLE STORES 35 I $D(@ZFARY) Q ; ALREADY INITIALIZED 35 36 S @ZFARY@("C0XTFN")=172.101 ; TRIPLES FILE NUMBER 36 37 S @ZFARY@("C0XSFN")=172.201 ; TRIPLES STRINGS FILE NUMBER 37 38 S @ZFARY@("C0XTN")=$NA(^C0X(101)) ; TRIPLES GLOBAL NAME 38 39 S @ZFARY@("C0XSN")=$NA(^C0X(201)) ; STRING FILE GLOBAL NAME 39 S @ZFARY@("C0XDIR")="/home/glilly/fmts/trunk/samples/ qds/"40 S @ZFARY@("C0XDIR")="/home/glilly/fmts/trunk/samples/" 40 41 S @ZFARY@("BLKLOAD")=1 ; this file supports block load 41 42 S @ZFARY@("FMTSSTYLE")="F2N" ; fileman style … … 71 72 S C0XFN=Y 72 73 D IMPORT(C0XFN,C0XDIR,,"C0XFARY") 73 Q 74 ; 75 IMPORT(FNAME,FDIR,FURL,FARY) ; EXTRINSIC THAT READS A FILE FROM THE STANDARD 74 K C0XFDA 75 Q 76 ; 77 IMPORT(FNAME,INDIR,INURL,FARY) ; EXTRINSIC THAT READS A FILE FROM THE STANDARD 76 78 ; DIRECTORY, LOADS IT INTO THE TRIPLESTORE AS TEXT, AND RETURNS THE 77 79 ; NODE NAME OF THE TEXT TRIPLE 78 ; FDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR)79 ; FURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE80 ; INDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR) 81 ; INURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE 80 82 ; FARY IS THE OPTIONAL FILE ARRAY OF THE TRIPLE STORE TO USE 81 83 I '$D(FARY) D ; … … 84 86 D USEFARY(FARY) 85 87 N ZD,ZTMP 86 I '$D(FDIR) S FDIR=C0XDIR ; DIRECTORY OF THE RDF FILE 87 I '$D(FURL) D ; 88 . N ZN2 S ZN2=$TR(FNAME,".","_") ; REMOVE THE DOT FROM THE NAME 89 . S FURL=FDIR_ZN2 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 90 93 N ZTMP 91 94 S ZTMP=$NA(^TMP("C0X",$J,"FILEIN",1)) ; WHERE TO PUT THE INCOMING FILE … … 94 97 W !,"STARTED: ",C0XSTART 95 98 W !,"READING IN: ",FNAME 96 I '$$FILEREAD(ZTMP, FDIR,FNAME,4) D Q ; QUIT IF NO SUCCESS97 . W !,"ERROR READING FILE: ", FDIR,FNAME99 I '$$FILEREAD(ZTMP,INDIR,FNAME,4) D Q ; QUIT IF NO SUCCESS 100 . W !,"ERROR READING FILE: ",INDIR,FNAME 98 101 S ZRDF=$NA(^TMP("C0X",$J,"FILEIN")) ; WITHOUT THE SUBSCRIPT 99 102 W !,$O(@ZRDF@(""),-1)," LINES READ" 100 D INSRDF(ZRDF,FURL,FARY) ; IMPORT AND PROCESS THE RDF 103 D INSRDF(ZRDF,INURL,FARY) ; IMPORT AND PROCESS THE RDF 104 K INURL 105 K C0XFDA 106 K ^TMP("MXMLDOM",$J) 101 107 Q 102 108 ; … … 132 138 . S FARY="C0XFARY" 133 139 D USEFARY(FARY) 140 S BATCNT=0 ; BATCH COUNTER 141 S BATMAX=10000 ; TRY BATCHES OF THIS SIZE 134 142 N ZGRAPH,ZSUBJECT 135 143 S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME … … 139 147 S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE 140 148 D ADD(ZGRAPH,ZSUBJECT,"fmts:rdfSource",ZTXTNM,FARY) 141 D UPDIE(.C0XFDA) ; TRY IT OUT149 D SWUPDIE(.C0XFDA) ; TRY IT OUT 142 150 K C0XCNT ;RESET FOR NEXT TIME 143 151 D STORETXT(ZRDF,ZTXTNM,FARY) 144 152 W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:rdfSource ",ZTXTNM 145 D PROCESS 2(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF153 D PROCESS(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF 146 154 Q 147 155 ; … … 207 215 . S FARY="C0XFARY" 208 216 D USEFARY(FARY) 217 ;N BATCNT 218 ;N BATMAX 209 219 ; -- first parse the rdf file with the MXML parser 210 220 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML 221 S C0XDLC2=$$NOW^XLFDT ; START OF PARSE 211 222 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") 223 K @ZRDF ; DON'T NEED INPUT BUFFER ANYMORE 212 224 ; -- assign the MXLM dom global name to ZDOM 213 225 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID)) 214 W !,$O(@ZDOM@(""),-1)," XML NODES PARSED" 226 S C0XNODE=$O(@ZDOM@(""),-1) 227 W !,C0XNODE," XML NODES PARSED" 228 S C0XPRS=$$NOW^XLFDT ; PARSE COMPLETE 229 W !,"PARSE COMPLETE AT ",C0XPRS 230 S C0XDIFF=$$FMDIFF^XLFDT(C0XPRS,C0XDLC2,2) 231 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 232 I C0XDIFF'=0 D ; 233 . W !," APPROXIMATELY ",$P(C0XNODE/C0XDIFF,".")," NODES PER SECOND" 215 234 ; -- populate the metagraph to point to the graph with status unfinished 216 235 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT … … 218 237 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH 219 238 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished 239 W !,"INSERTING GRAPH: ",ZGRF 220 240 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT") 221 241 S C0XDATE=$$NOW^XLFDT 222 242 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY) 223 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store243 D SWUPDIE(.C0XFDA) ; commit the metagraph changes to the triple store 224 244 ; -- 225 245 ; -- pull out the vocabularies in the RDF statement. marked with xmlns: … … 288 308 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ 289 309 . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 290 W !,"INSERTING ",C0XCNT," TRIPLES"291 D UPDIE(.C0XFDA) ; commit the updates to the file292 ; next, mark the graph as finished293 S C0XEND=$$NOW^XLFDT294 W !," ENDED AT: ",C0XEND295 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2)296 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"297 I C0XDIFF'=0 D ;298 . W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"299 Q300 ;301 PROCESS2(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE302 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING303 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE304 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS305 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA306 ;307 I '$D(FARY) D ;308 . D INITFARY("C0XFARY")309 . S FARY="C0XFARY"310 D USEFARY(FARY)311 ;N BATCNT312 ;N BATMAX313 S BATCNT=0 ; BATCH COUNTER314 S BATMAX=10000 ; TRY BATCHES OF THIS SIZE315 ; -- first parse the rdf file with the MXML parser316 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML317 S C0XDLC2=$$NOW^XLFDT ; START OF PARSE318 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W")319 ; -- assign the MXLM dom global name to ZDOM320 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID))321 S C0XNODE=$O(@ZDOM@(""),-1)322 W !,C0XNODE," XML NODES PARSED"323 S C0XPRS=$$NOW^XLFDT ; PARSE COMPLETE324 W !,"PARSE COMPLETE AT ",C0XPRS325 S C0XDIFF=$$FMDIFF^XLFDT(C0XPRS,C0XDLC2,2)326 W !," ELAPSED TIME: ",C0XDIFF," SECONDS"327 I C0XDIFF'=0 D ;328 . W !," APPROXIMATELY ",$P(C0XNODE/C0XDIFF,".")," NODES PER SECOND"329 ; -- populate the metagraph to point to the graph with status unfinished330 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT331 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH332 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH333 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished334 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT")335 S C0XDATE=$$NOW^XLFDT336 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY)337 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store338 ; --339 ; -- pull out the vocabularies in the RDF statement. marked with xmlns:340 ; -- put them in a local variable for quick reference341 ; -- TODO: create a graph for vocabularies and validate incoming against it342 ;343 S C0XVOC=""344 N ZI,ZJ,ZK S ZI=""345 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns346 . S ZVOC=$P(ZI,"xmlns:",2)347 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))348 ;W !,"VOCABS:" ZWR C0XVOC349 ;350 ; -- look for children called rdf:Description. quit if none. not an rdf file351 ;352 S ZI=$O(@ZDOM@(1,"C",""))353 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file354 . W !,"Error. Not an RDF file. Cannot process."355 ;356 ; -- now process the rdf description children357 ;358 S ZI=""359 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate360 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ;361 . ; -- we are skipping any child that is not rdf:Description362 . ; -- TODO: check to see if this is right in general363 . ;364 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ;365 . . W !,"SKIPPING NODE: ",ZI366 . ; -- now looking for the subject for the triples367 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about"))368 . I ZX'="" D ; we have the subject369 . . ;W " about: ",ZX370 . . S C0XSUB=ZX371 . E D ;372 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject373 . . I ZX'="" D ;374 . . . S C0XSUB=ZX375 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT376 . ;377 . ; -- we now have the subject. the children of this node have the rest378 . ;379 . S ZJ="" ; for the children of the rdf:Description nodes380 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child381 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix382 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space383 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix384 . . I C0XPRE[":" D ; expand using vocabulary385 . . . N ZB,ZA386 . . . S ZB=$P(C0XPRE,":",1)387 . . . S ZA=$P(C0XPRE,":",2)388 . . . I $G(C0XVOC(ZB))'="" D ;389 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded390 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object391 . . I ZY'="" D Q ;392 . . . S C0XOBJ=ZY ; object393 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple394 . . ; -- this is an else because of the quit above395 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object396 . . I ZX'="" D Q ; got one397 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject398 . . . ; without change... this could be foolish .. look at it again later399 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node400 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here401 . . I C0XOBJ="" D Q ; not a happy situation402 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ403 . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node404 310 S C0XTRP=$$NOW^XLFDT ; PARSE COMPLETE 405 311 W !,"TRIPLES COMPLETE AT ",C0XTRP … … 419 325 S C0XDIFF=$$FMDIFF^XLFDT(C0XINS,C0XTRP,2) 420 326 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 421 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," NODES PER SECOND"327 I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," NODES PER SECOND" 422 328 S C0XEND=$$NOW^XLFDT 423 329 W !," ENDED AT: ",C0XEND 424 330 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2) 425 331 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 426 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"332 I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND" 427 333 Q 428 334 ; … … 432 338 ; 433 339 ANONS() ; RETURNS AN ANONOMOUS SUBJECT 434 Q "_ S:"_$$LKY9340 Q "_:S"_$$LKY9 435 341 ; 436 342 NEWG(NGRAPH,NMETA) ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED … … 442 348 ; 443 349 ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT 444 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE445 I '$D(FARY) D ;446 . D INITFARY("C0XFARY")447 . S FARY="C0XFARY"448 D USEFARY(FARY)449 I '$D(C0XCNT) S C0XCNT=0450 N ZNODE451 S ZNODE="N"_$$LKY17452 N ZNARY ; GET READY TO CALL IENOFA453 S ZNARY("ZG",ZG)=""454 S ZNARY("ZS",ZS)=""455 S ZNARY("ZP",ZP)=""456 S ZNARY("ZO",ZO)=""457 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS458 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN459 ;S ZSIEN=$$IENOF(ZS)460 ;S ZPIEN=$$IENOF(ZP)461 ;S ZOIEN=$$IENOF(ZO)462 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED463 S C0XCNT=C0XCNT+1464 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.01)=ZNODE465 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.02)=$O(ZIENS("IEN","ZG",""))466 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.03)=$O(ZIENS("IEN","ZS",""))467 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.04)=$O(ZIENS("IEN","ZP",""))468 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.05)=$O(ZIENS("IEN","ZO",""))469 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE470 Q471 ;472 ADD2(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT473 350 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE 474 351 I '$D(FARY) D ; … … 637 514 Q 638 515 ; 516 SWUPDIE(ZFDA) ; SWITCH BETWEEN UPDIE AND BULKLOAD 517 . I $G(BLKLOAD) D ; bulk load 518 . . D BULKLOAD(.ZFDA) ; bulk load the batch 519 . E D ; no bulk load 520 . . D UPDIE(.ZFDA) 521 . K ZFDA 522 Q 523 ; 639 524 UPDIE(ZFDA) ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS 640 525 ; ZFDA IS PASSED BY REFERENCE -
fmts/trunk/p/C0XMAIN.m
r1274 r1294 1 C0XMAIN ; 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 INITFARY(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 ; 33 USEFARY(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 ; 42 IMPORT(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 ; 70 WGET(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 W !,$O(@ZLOC@(""),-1)," LINES READ" 86 D INSRDF(ZLOC,ZURL,FARY) 87 Q 88 ; 89 INSRDF(ZRDF,ZNAME,FARY) ; INSERT AN RDF FILE INTO THE STORE AND PROCESS 90 ; ZRDF IS PASSED BY NAME 91 I '$D(FARY) D ; 92 . D INITFARY("C0XFARY") 93 . S FARY="C0XFARY" 94 D USEFARY(FARY) 95 N ZGRAPH,ZSUBJECT 96 S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME 97 S ZSUBJECT=$$ANONS ; RANDOM ANOYMOUS SUBJECT 98 D ADD(ZGRAPH,ZSUBJECT,"fmts:url",ZNAME,FARY) 99 N ZTXTNM 100 S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE 101 D ADD(ZGRAPH,ZSUBJECT,"fmts:rdfSource",ZTXTNM,FARY) 102 D UPDIE(.C0XFDA) ; TRY IT OUT 103 K C0XCNT ;RESET FOR NEXT TIME 104 D STORETXT(ZRDF,ZTXTNM,FARY) 105 W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:rdfSource ",ZTXTNM 106 D PROCESS2(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF 107 Q 108 ; 109 STORETXT(ZTXT,ZNAME,FARY) ; STORE TEXT IN THE TRIPLESTORE AT ZNAME 110 ; 111 I '$D(FARY) D ; 112 . D INITFARY("C0XFARY") 113 . S FARY="C0XFARY" 114 D USEFARY(FARY) 115 N ZIEN 116 S ZIEN=$$IENOF(ZNAME,FARY) ; GET THE IEN 117 D CLEAN^DILF 118 K ZERR 119 D WP^DIE(C0XSFN,ZIEN_",",1,,ZTXT,"ZERR") 120 I $D(ZERR) D ; 121 . ZWR ZERR 122 Q 123 ; 124 GETTXT(ZRTN,ZNAME,FARY) ; RETURNS RDF SOURCE OR OTHER TEXT 125 ; ZRTN IS PASSED BY REFERENCE 126 I '$D(FARY) D ; 127 . D INITFARY("C0XFARY") 128 . S FARY="C0XFARY" 129 D USEFARY(FARY) 130 N ZIEN 131 S ZIEN=$$IENOF(ZNAME) 132 S OK=$$GET1^DIQ(C0XSFN,ZIEN_",",1,,"ZRTN") 133 Q 134 ; 135 WHERETXT(ZNAME,FARY) ; EXTRINSIC WHICH RETURNS THE NAME OF THE GLOBAL 136 ; WHERE THE TEXT IS LOCATED. NAME IS THE NAME OF THE STRING 137 I '$D(FARY) D ; 138 . D INITFARY("C0XFARY") 139 . S FARY="C0XFARY" 140 D USEFARY(FARY) 141 N ZIEN 142 S ZIEN=$$IENOF(ZNAME) 143 Q $NA(@C0XSN@(ZIEN,1)) 144 ; 145 FILEIN(ZINTMP,ZDIR,ZFNAME,ZLVL) ; READS A FILE INTO ZINTMP USING FTG^%ZISH 146 ; ZINTMP IS PASSED BY NAME AND INCLUDES THE NEW SUBSCRIPT 147 ; IE ^TMP("C0X","FILEIN",1) 148 ; ZLVL IN THIS CASE WOULD BE 3 INCREMENTING THE 1 149 ; EXTRINSIC WHICH RETURNS THE RESULT OF FTG^%ZISH 150 S OK=$$FTG^%ZISH(ZDIR,FNAME,ZINTMP,ZLVL) 151 Q OK 152 ; 153 TESTPROC ; TEST PROCESS WITH EXISTING SMALL RDF FILE 154 S ZIN=$NA(^TMP("C0X",12226,"FILEIN")) 155 S ZGRAPH="/test/rdfFile" 156 S ZM="/test/rdfFile/meta" 157 D PROCESS(.G,ZIN,ZGRAPH,ZM) 158 Q 159 ; 160 PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE 161 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING 162 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE 163 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS 164 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA 165 ; 166 I '$D(FARY) D ; 167 . D INITFARY("C0XFARY") 168 . S FARY="C0XFARY" 169 D USEFARY(FARY) 170 ; -- first parse the rdf file with the MXML parser 171 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML 172 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") 173 ; -- assign the MXLM dom global name to ZDOM 174 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID)) 175 W !,$O(@ZDOM@(""),-1)," XML NODES PARSED" 176 ; -- populate the metagraph to point to the graph with status unfinished 177 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT 178 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH 179 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH 180 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished 181 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT") 182 S C0XDATE=$$NOW^XLFDT 183 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY) 184 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store 185 ; -- 186 ; -- pull out the vocabularies in the RDF statement. marked with xmlns: 187 ; -- put them in a local variable for quick reference 188 ; -- TODO: create a graph for vocabularies and validate incoming against it 189 ; 190 S C0XVOC="" 191 N ZI,ZJ,ZK S ZI="" 192 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns 193 . S ZVOC=$P(ZI,"xmlns:",2) 194 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI)) 195 ;W !,"VOCABS:" ZWR C0XVOC 196 ; 197 ; -- look for children called rdf:Description. quit if none. not an rdf file 198 ; 199 S ZI=$O(@ZDOM@(1,"C","")) 200 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file 201 . W !,"Error. Not an RDF file. Cannot process." 202 ; 203 ; -- now process the rdf description children 204 ; 205 S ZI="" 206 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate 207 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ; 208 . ; -- we are skipping any child that is not rdf:Description 209 . ; -- TODO: check to see if this is right in general 210 . ; 211 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; 212 . . W !,"SKIPPING NODE: ",ZI 213 . ; -- now looking for the subject for the triples 214 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about")) 215 . I ZX'="" D ; we have the subject 216 . . ;W " about: ",ZX 217 . . S C0XSUB=ZX 218 . E D ; 219 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject 220 . . I ZX'="" D ; 221 . . . S C0XSUB=ZX 222 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT 223 . ; 224 . ; -- we now have the subject. the children of this node have the rest 225 . ; 226 . S ZJ="" ; for the children of the rdf:Description nodes 227 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child 228 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix 229 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space 230 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix 231 . . I C0XPRE[":" D ; expand using vocabulary 232 . . . N ZB,ZA 233 . . . S ZB=$P(C0XPRE,":",1) 234 . . . S ZA=$P(C0XPRE,":",2) 235 . . . I $G(C0XVOC(ZB))'="" D ; 236 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded 237 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object 238 . . I ZY'="" D Q ; 239 . . . S C0XOBJ=ZY ; object 240 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple 241 . . ; -- this is an else because of the quit above 242 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object 243 . . I ZX'="" D Q ; got one 244 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject 245 . . . ; without change... this could be foolish .. look at it again later 246 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 247 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here 248 . . I C0XOBJ="" D Q ; not a happy situation 249 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ 250 . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 251 W !,"INSERTING ",C0XCNT," TRIPLES" 252 D UPDIE(.C0XFDA) ; commit the updates to the file 253 ; next, mark the graph as finished 254 S C0XEND=$$NOW^XLFDT 255 W !," ENDED AT: ",C0XEND 256 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2) 257 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 258 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND" 259 Q 260 ; 261 PROCESS2(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE 262 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING 263 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE 264 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS 265 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA 266 ; 267 I '$D(FARY) D ; 268 . D INITFARY("C0XFARY") 269 . S FARY="C0XFARY" 270 D USEFARY(FARY) 271 ;N BATCNT 272 ;N BATMAX 273 S BATCNT=0 ; BATCH COUNTER 274 S BATMAX=10000 ; TRY BATCHES OF THIS SIZE 275 ; -- first parse the rdf file with the MXML parser 276 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML 277 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") 278 ; -- assign the MXLM dom global name to ZDOM 279 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID)) 280 W !,$O(@ZDOM@(""),-1)," XML NODES PARSED" 281 ; -- populate the metagraph to point to the graph with status unfinished 282 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT 283 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH 284 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH 285 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished 286 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT") 287 S C0XDATE=$$NOW^XLFDT 288 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY) 289 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store 290 ; -- 291 ; -- pull out the vocabularies in the RDF statement. marked with xmlns: 292 ; -- put them in a local variable for quick reference 293 ; -- TODO: create a graph for vocabularies and validate incoming against it 294 ; 295 S C0XVOC="" 296 N ZI,ZJ,ZK S ZI="" 297 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns 298 . S ZVOC=$P(ZI,"xmlns:",2) 299 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI)) 300 ;W !,"VOCABS:" ZWR C0XVOC 301 ; 302 ; -- look for children called rdf:Description. quit if none. not an rdf file 303 ; 304 S ZI=$O(@ZDOM@(1,"C","")) 305 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file 306 . W !,"Error. Not an RDF file. Cannot process." 307 ; 308 ; -- now process the rdf description children 309 ; 310 S ZI="" 311 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate 312 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ; 313 . ; -- we are skipping any child that is not rdf:Description 314 . ; -- TODO: check to see if this is right in general 315 . ; 316 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; 317 . . W !,"SKIPPING NODE: ",ZI 318 . ; -- now looking for the subject for the triples 319 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about")) 320 . I ZX'="" D ; we have the subject 321 . . ;W " about: ",ZX 322 . . S C0XSUB=ZX 323 . E D ; 324 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject 325 . . I ZX'="" D ; 326 . . . S C0XSUB=ZX 327 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT 328 . ; 329 . ; -- we now have the subject. the children of this node have the rest 330 . ; 331 . S ZJ="" ; for the children of the rdf:Description nodes 332 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child 333 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix 334 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space 335 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix 336 . . I C0XPRE[":" D ; expand using vocabulary 337 . . . N ZB,ZA 338 . . . S ZB=$P(C0XPRE,":",1) 339 . . . S ZA=$P(C0XPRE,":",2) 340 . . . I $G(C0XVOC(ZB))'="" D ; 341 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded 342 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object 343 . . I ZY'="" D Q ; 344 . . . S C0XOBJ=ZY ; object 345 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple 346 . . ; -- this is an else because of the quit above 347 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object 348 . . I ZX'="" D Q ; got one 349 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject 350 . . . ; without change... this could be foolish .. look at it again later 351 . . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 352 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here 353 . . I C0XOBJ="" D Q ; not a happy situation 354 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ 355 . . D ADD2(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 356 W !,"INSERTING ",C0XCNT," TRIPLES" 357 I $D(C0XFDA) D UPDIE(.C0XFDA) ; commit the updates to the file 358 ; next, mark the graph as finished 359 S C0XEND=$$NOW^XLFDT 360 W !," ENDED AT: ",C0XEND 361 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2) 362 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 363 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND" 364 Q 365 ; 366 SHOW(ZN) ; 367 ZWR ^TMP("MXMLDOM",$J,1,ZN,*) 368 Q 369 ; 370 ANONS() ; RETURNS AN ANONOMOUS SUBJECT 371 Q "_S:"_$$LKY9 372 ; 373 NEWG(NGRAPH,NMETA) ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED 374 ; THEN CREATES A NEW GRAPH AND POINTS THE METAGRAPH TO IT 375 ; NGRAPH AND NMETA ARE PASSED BY REFERENCE AND ARE THE RETURN 376 S NGRAPH="G"_$$LKY9 377 S NMETA=NGRAPH_"A" 378 Q 379 ; 380 ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT 381 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE 382 I '$D(FARY) D ; 383 . D INITFARY("C0XFARY") 384 . S FARY="C0XFARY" 385 D USEFARY(FARY) 386 I '$D(C0XCNT) S C0XCNT=0 387 N ZNODE 388 S ZNODE="N"_$$LKY17 389 N ZNARY ; GET READY TO CALL IENOFA 390 S ZNARY("ZG",ZG)="" 391 S ZNARY("ZS",ZS)="" 392 S ZNARY("ZP",ZP)="" 393 S ZNARY("ZO",ZO)="" 394 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS 395 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN 396 ;S ZSIEN=$$IENOF(ZS) 397 ;S ZPIEN=$$IENOF(ZP) 398 ;S ZOIEN=$$IENOF(ZO) 399 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED 400 S C0XCNT=C0XCNT+1 401 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.01)=ZNODE 402 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.02)=$O(ZIENS("IEN","ZG","")) 403 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.03)=$O(ZIENS("IEN","ZS","")) 404 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.04)=$O(ZIENS("IEN","ZP","")) 405 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.05)=$O(ZIENS("IEN","ZO","")) 406 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE 407 Q 408 ; 409 ADD2(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT 410 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE 411 I '$D(FARY) D ; 412 . D INITFARY("C0XFARY") 413 . S FARY="C0XFARY" 414 D USEFARY(FARY) 415 I '$D(C0XCNT) S C0XCNT=0 416 N ZNODE 417 S ZNODE="N"_$$LKY17 418 N ZNARY ; GET READY TO CALL IENOFA 419 S ZNARY("ZG",ZG)="" 420 S ZNARY("ZS",ZS)="" 421 S ZNARY("ZP",ZP)="" 422 S ZNARY("ZO",ZO)="" 423 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS 424 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN 425 ;S ZSIEN=$$IENOF(ZS) 426 ;S ZPIEN=$$IENOF(ZP) 427 ;S ZOIEN=$$IENOF(ZO) 428 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED 429 S C0XCNT=C0XCNT+1 430 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.01)=ZNODE 431 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.02)=$O(ZIENS("IEN","ZG","")) 432 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.03)=$O(ZIENS("IEN","ZS","")) 433 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.04)=$O(ZIENS("IEN","ZP","")) 434 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.05)=$O(ZIENS("IEN","ZO","")) 435 S BATCNT=BATCNT+1 436 I BATCNT=BATMAX D ; BATCH IS DONE 437 . D UPDIE(.C0XFDA) 438 . K C0XFDA 439 . S BATCNT=0 ; RESET COUNTER 440 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE 441 Q 442 ; 443 LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 444 ; UNIQUE NODE AND GRAPH NAMES 445 N ZN,ZI 446 S ZN="" 447 F ZI=1:1:9 D ; 448 . S ZN=ZN_$R(10) 449 Q ZN 450 ; 451 LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 452 ; UNIQUE NODE AND GRAPH NAMES 453 N ZN,ZI 454 S ZN="" 455 F ZI=1:1:17 D ; 456 . S ZN=ZN_$R(10) 457 Q ZN 458 ; 459 IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE 460 I '$D(FARY) D ; 461 . D INITFARY("C0XFARY") 462 . S FARY="C0XFARY" 463 N ZIEN 464 S ZIEN=$O(@C0XSN@("B",ZSTRING,"")) 465 I ZIEN="" D ; 466 . S C0XFDA2(C0XSFN,"+1,",.01)=ZSTRING 467 . D UPDIE(.C0XFDA2) 468 . S ZIEN=$O(@C0XSN@("B",ZSTRING,"")) 469 . K C0XFDA2 470 Q ZIEN 471 ; 472 IENOFA(ZOUTARY,ZINARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE 473 ; OR ADD THEM IF 474 ; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE 475 ; ZINARY LOOKS LIKE ZINARY("VAR","VAL")="" 476 ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)="" 477 I '$D(FARY) D ; 478 . D INITFARY("C0XFARY") 479 . S FARY="C0XFARY" 480 K ZOUTARY ; START WITH CLEAN RESULTS 481 K C0XFDA2 ; USE A SEPARATE FDA FOR THIS 482 N ZI S ZI="" 483 N ZV,ZIEN 484 N ZCNT S ZCNT=0 485 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; LOOK FOR MISSING STRINGS 486 . S ZV=$O(ZINARY(ZI,"")) 487 . I $O(@C0XSN@("B",ZV,""))="" D ; 488 . . S ZCNT=ZCNT+1 489 . . S C0XFDA2(C0XSFN,"+"_ZCNT_",",.01)=ZV 490 I $D(C0XFDA2) D ; 491 . D UPDIE(.C0XFDA2) ; ADD MISSING STRINGS 492 . K C0XFDA2 ; CLEAN UP 493 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; NOT GET ALL IENS 494 . S ZV=$O(ZINARY(ZI,"")) 495 . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW 496 . I ZIEN="" D ; 497 . . W !,"ERROR ADDING STRING: ",ZV 498 . . B 499 . S ZOUTARY("IEN",ZI,ZIEN)="" 500 Q 501 ; 502 UPDIE(ZFDA) ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS 503 ; ZFDA IS PASSED BY REFERENCE 504 ;ZWR ZFDA 505 ;B 506 K ZERR 507 D CLEAN^DILF 508 D UPDATE^DIE("","ZFDA","","ZERR") 509 I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST, 510 ; INVOKE THE ERROR TRAP IF TASKED 511 ;. W "ERROR",! 512 ;. ZWR ZERR 513 ;. B 514 K ZFDA 515 Q 516 ; 1 C0XMAIN ; GPL - Fileman Triples entry point routine ;10/13/11 17:05 2 ;;0.1;C0X;nopatch;noreleasedate;Build 5 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 INITFARY(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 S @ZFARY@("C0XDIR")="/home/george/fmts/trunk/samples/" 31 D USEFARY(ZFARY) 32 Q 33 ; 34 USEFARY(ZFARY) ; INITIALIZES VARIABLES SAVED IN ARRAY ZFARY 35 N ZI S ZI="" 36 F S ZI=$O(@ZFARY@(ZI)) Q:ZI="" D 37 . ;N ZX 38 . S ZX="S "_ZI_"="""_@ZFARY@(ZI)_"""" 39 . ;W !,ZX 40 . X ZX 41 Q 42 ; 43 IMPORT(FNAME,FDIR,FURL,FARY) ; EXTRINSIC THAT READS A FILE FROM THE STANDARD 44 ; DIRECTORY, LOADS IT INTO THE TRIPLESTORE AS TEXT, AND RETURNS THE 45 ; NODE NAME OF THE TEXT TRIPLE 46 ; FDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR) 47 ; FURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE 48 ; FARY IS THE OPTIONAL FILE ARRAY OF THE TRIPLE STORE TO USE 49 I '$D(FARY) D ; 50 . D INITFARY("C0XFARY") 51 . S FARY="C0XFARY" 52 D USEFARY(FARY) 53 N ZD,ZTMP 54 I '$D(FDIR) S FDIR=C0XDIR ; DIRECTORY OF THE RDF FILE 55 I '$D(FURL) D ; 56 . N ZN2 S ZN2=$TR(FNAME,".","_") ; REMOVE THE DOT FROM THE NAME 57 . S FURL=FDIR_ZN2 58 N ZTMP 59 S ZTMP=$NA(^TMP("C0X",$J,"FILEIN",1)) ; WHERE TO PUT THE INCOMING FILE 60 K @ZTMP ; MAKE SURE IT'S CLEAR 61 S C0XSTART=$$NOW^XLFDT 62 W !,"STARTED: ",C0XSTART 63 W !,"READING IN: ",FNAME 64 I '$$FILEIN(ZTMP,FDIR,FNAME,4) D Q ; QUIT IF NO SUCCESS 65 . W !,"ERROR READING FILE: ",FDIR,FNAME 66 S ZRDF=$NA(^TMP("C0X",$J,"FILEIN")) ; WITHOUT THE SUBSCRIPT 67 W !,$O(@ZRDF@(""),-1)," LINES READ" 68 D INSRDF(ZRDF,FURL,FARY) ; IMPORT AND PROCESS THE RDF 69 Q 70 ; 71 WGET(ZURL,FARY) ; GET FROM THE INTERNET AN RDF FILE AND INSERT IT 72 ; 73 I '$D(FARY) D ; 74 . D INITFARY("C0XFARY") 75 . S FARY="C0XFARY" 76 D USEFARY(FARY) 77 ;N ZLOC,ZTMP 78 K ZTMP 79 S ZLOC=$NA(^TMP("C0X","WGET",$J)) 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 W !,$O(@ZLOC@(""),-1)," LINES READ" 86 D INSRDF(ZLOC,ZURL,FARY) 87 Q 88 ; 89 INSRDF(ZRDF,ZNAME,FARY) ; INSERT AN RDF FILE INTO THE STORE AND PROCESS 90 ; ZRDF IS PASSED BY NAME 91 I '$D(FARY) D ; 92 . D INITFARY("C0XFARY") 93 . S FARY="C0XFARY" 94 D USEFARY(FARY) 95 N ZGRAPH,ZSUBJECT 96 S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME 97 S ZSUBJECT=$$ANONS ; RANDOM ANOYMOUS SUBJECT 98 D ADD(ZGRAPH,ZSUBJECT,"fmts:url",ZNAME,FARY) 99 N ZTXTNM 100 S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE 101 D ADD(ZGRAPH,ZSUBJECT,"fmts:rdfSource",ZTXTNM,FARY) 102 D UPDIE(.C0XFDA) ; TRY IT OUT 103 K C0XCNT ;RESET FOR NEXT TIME 104 D STORETXT(ZRDF,ZTXTNM,FARY) 105 W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:rdfSource ",ZTXTNM 106 D PROCESS(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF 107 Q 108 ; 109 STORETXT(ZTXT,ZNAME,FARY) ; STORE TEXT IN THE TRIPLESTORE AT ZNAME 110 ; 111 I '$D(FARY) D ; 112 . D INITFARY("C0XFARY") 113 . S FARY="C0XFARY" 114 D USEFARY(FARY) 115 N ZIEN 116 S ZIEN=$$IENOF(ZNAME,FARY) ; GET THE IEN 117 D CLEAN^DILF 118 K ZERR 119 D WP^DIE(C0XSFN,ZIEN_",",1,,ZTXT,"ZERR") 120 I $D(ZERR) D ; 121 . ZWR ZERR 122 Q 123 ; 124 GETTXT(ZRTN,ZNAME,FARY) ; RETURNS RDF SOURCE OR OTHER TEXT 125 ; ZRTN IS PASSED BY REFERENCE 126 I '$D(FARY) D ; 127 . D INITFARY("C0XFARY") 128 . S FARY="C0XFARY" 129 D USEFARY(FARY) 130 N ZIEN 131 S ZIEN=$$IENOF(ZNAME) 132 S OK=$$GET1^DIQ(C0XSFN,ZIEN_",",1,,"ZRTN") 133 Q 134 ; 135 WHERETXT(ZNAME,FARY) ; EXTRINSIC WHICH RETURNS THE NAME OF THE GLOBAL 136 ; WHERE THE TEXT IS LOCATED. NAME IS THE NAME OF THE STRING 137 I '$D(FARY) D ; 138 . D INITFARY("C0XFARY") 139 . S FARY="C0XFARY" 140 D USEFARY(FARY) 141 N ZIEN 142 S ZIEN=$$IENOF(ZNAME) 143 Q $NA(@C0XSN@(ZIEN,1)) 144 ; 145 FILEIN(ZINTMP,ZDIR,ZFNAME,ZLVL) ; READS A FILE INTO ZINTMP USING FTG^%ZISH 146 ; ZINTMP IS PASSED BY NAME AND INCLUDES THE NEW SUBSCRIPT 147 ; IE ^TMP("C0X","FILEIN",1) 148 ; ZLVL IN THIS CASE WOULD BE 3 INCREMENTING THE 1 149 ; EXTRINSIC WHICH RETURNS THE RESULT OF FTG^%ZISH 150 S OK=$$FTG^%ZISH(ZDIR,FNAME,ZINTMP,ZLVL) 151 Q OK 152 ; 153 TESTPROC ; TEST PROCESS WITH EXISTING SMALL RDF FILE 154 S ZIN=$NA(^TMP("C0X",12226,"FILEIN")) 155 S ZGRAPH="/test/rdfFile" 156 S ZM="/test/rdfFile/meta" 157 D PROCESS(.G,ZIN,ZGRAPH,ZM) 158 Q 159 ; 160 PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE 161 ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING 162 ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE 163 ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS 164 ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA 165 ; 166 I '$D(FARY) D ; 167 . D INITFARY("C0XFARY") 168 . S FARY="C0XFARY" 169 D USEFARY(FARY) 170 ; -- first parse the rdf file with the MXML parser 171 ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML 172 S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") 173 ; -- assign the MXLM dom global name to ZDOM 174 S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID)) 175 W !,$O(@ZDOM@(""),-1)," XML NODES PARSED" 176 ; -- populate the metagraph to point to the graph with status unfinished 177 S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT 178 I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH 179 D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH 180 D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished 181 ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT") 182 S C0XDATE=$$NOW^XLFDT 183 D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY) 184 D UPDIE(.C0XFDA) ; commit the metagraph changes to the triple store 185 ; -- 186 ; -- pull out the vocabularies in the RDF statement. marked with xmlns: 187 ; -- put them in a local variable for quick reference 188 ; -- TODO: create a graph for vocabularies and validate incoming against it 189 ; 190 S C0XVOC="" 191 N ZI,ZJ,ZK S ZI="" 192 F S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI="" D ; FOR EACH xmlns 193 . S ZVOC=$P(ZI,"xmlns:",2) 194 . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI)) 195 ;W !,"VOCABS:" ZWR C0XVOC 196 ; 197 ; -- look for children called rdf:Description. quit if none. not an rdf file 198 ; 199 S ZI=$O(@ZDOM@(1,"C","")) 200 I $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; not an rdf file 201 . W !,"Error. Not an RDF file. Cannot process." 202 ; 203 ; -- now process the rdf description children 204 ; 205 S ZI="" 206 S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate 207 F S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI="" D ; 208 . ; -- we are skipping any child that is not rdf:Description 209 . ; -- TODO: check to see if this is right in general 210 . ; 211 . IF $G(@ZDOM@(1,"C",ZI))'="rdf:Description" D Q ; 212 . . W !,"SKIPPING NODE: ",ZI 213 . ; -- now looking for the subject for the triples 214 . S ZX=$G(@ZDOM@(ZI,"A","rdf:about")) 215 . I ZX'="" D ; we have the subject 216 . . ;W " about: ",ZX 217 . . S C0XSUB=ZX 218 . E D ; 219 . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject 220 . . I ZX'="" D ; 221 . . . S C0XSUB=ZX 222 . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT 223 . ; 224 . ; -- we now have the subject. the children of this node have the rest 225 . ; 226 . S ZJ="" ; for the children of the rdf:Description nodes 227 . F S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ="" D ; for each child 228 . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix 229 . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space 230 . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix 231 . . I C0XPRE[":" D ; expand using vocabulary 232 . . . N ZB,ZA 233 . . . S ZB=$P(C0XPRE,":",1) 234 . . . S ZA=$P(C0XPRE,":",2) 235 . . . I $G(C0XVOC(ZB))'="" D ; 236 . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded 237 . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object 238 . . I ZY'="" D Q ; 239 . . . S C0XOBJ=ZY ; object 240 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple 241 . . ; -- this is an else because of the quit above 242 . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object 243 . . I ZX'="" D Q ; got one 244 . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject 245 . . . ; without change... this could be foolish .. look at it again later 246 . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 247 . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here 248 . . I C0XOBJ="" D Q ; not a happy situation 249 . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ 250 . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node 251 W !,"INSERTING ",C0XCNT," TRIPLES" 252 D UPDIE(.C0XFDA) ; commit the updates to the file 253 ; next, mark the graph as finished 254 S C0XEND=$$NOW^XLFDT 255 W !," ENDED AT: ",C0XEND 256 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2) 257 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 258 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND" 259 Q 260 ; 261 SHOW(ZN) ; 262 ZWR ^TMP("MXMLDOM",$J,1,ZN,*) 263 Q 264 ; 265 ANONS() ; RETURNS AN ANONOMOUS SUBJECT 266 Q "_S:"_$$LKY9 267 ; 268 NEWG(NGRAPH,NMETA) ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED 269 ; THEN CREATES A NEW GRAPH AND POINTS THE METAGRAPH TO IT 270 ; NGRAPH AND NMETA ARE PASSED BY REFERENCE AND ARE THE RETURN 271 S NGRAPH="G"_$$LKY9 272 S NMETA=NGRAPH_"A" 273 Q 274 ; 275 ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT 276 ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE 277 I '$D(FARY) D ; 278 . D INITFARY("C0XFARY") 279 . S FARY="C0XFARY" 280 D USEFARY(FARY) 281 I '$D(C0XCNT) S C0XCNT=0 282 N ZNODE 283 S ZNODE="N"_$$LKY17 284 N ZNARY ; GET READY TO CALL IENOFA 285 S ZNARY("ZG",ZG)="" 286 S ZNARY("ZS",ZS)="" 287 S ZNARY("ZP",ZP)="" 288 S ZNARY("ZO",ZO)="" 289 D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS 290 ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN 291 ;S ZSIEN=$$IENOF(ZS) 292 ;S ZPIEN=$$IENOF(ZP) 293 ;S ZOIEN=$$IENOF(ZO) 294 ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED 295 S C0XCNT=C0XCNT+1 296 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.01)=ZNODE 297 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.02)=$O(ZIENS("IEN","ZG","")) 298 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.03)=$O(ZIENS("IEN","ZS","")) 299 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.04)=$O(ZIENS("IEN","ZP","")) 300 S C0XFDA(C0XTFN,"?+"_C0XCNT_",",.05)=$O(ZIENS("IEN","ZO","")) 301 ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE 302 Q 303 ; 304 LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 305 ; UNIQUE NODE AND GRAPH NAMES 306 N ZN,ZI 307 S ZN="" 308 F ZI=1:1:9 D ; 309 . S ZN=ZN_$R(10) 310 Q ZN 311 ; 312 LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 313 ; UNIQUE NODE AND GRAPH NAMES 314 N ZN,ZI 315 S ZN="" 316 F ZI=1:1:17 D ; 317 . S ZN=ZN_$R(10) 318 Q ZN 319 ; 320 IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE 321 I '$D(FARY) D ; 322 . D INITFARY("C0XFARY") 323 . S FARY="C0XFARY" 324 N ZIEN 325 S ZIEN=$O(@C0XSN@("B",ZSTRING,"")) 326 I ZIEN="" D ; 327 . S C0XFDA2(C0XSFN,"+1,",.01)=ZSTRING 328 . D UPDIE(.C0XFDA2) 329 . S ZIEN=$O(@C0XSN@("B",ZSTRING,"")) 330 . K C0XFDA2 331 Q ZIEN 332 ; 333 IENOFA(ZOUTARY,ZINARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE 334 ; OR ADD THEM IF 335 ; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE 336 ; ZINARY LOOKS LIKE ZINARY("VAR","VAL")="" 337 ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)="" 338 I '$D(FARY) D ; 339 . D INITFARY("C0XFARY") 340 . S FARY="C0XFARY" 341 K ZOUTARY ; START WITH CLEAN RESULTS 342 K C0XFDA2 ; USE A SEPARATE FDA FOR THIS 343 N ZI S ZI="" 344 N ZV,ZIEN 345 N ZCNT S ZCNT=0 346 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; LOOK FOR MISSING STRINGS 347 . S ZV=$O(ZINARY(ZI,"")) 348 . I $O(@C0XSN@("B",ZV,""))="" D ; 349 . . S ZCNT=ZCNT+1 350 . . S C0XFDA2(C0XSFN,"+"_ZCNT_",",.01)=ZV 351 I $D(C0XFDA2) D ; 352 . D UPDIE(.C0XFDA2) ; ADD MISSING STRINGS 353 . K C0XFDA2 ; CLEAN UP 354 F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; NOT GET ALL IENS 355 . S ZV=$O(ZINARY(ZI,"")) 356 . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW 357 . I ZIEN="" D ; 358 . . W !,"ERROR ADDING STRING: ",ZV 359 . . B 360 . S ZOUTARY("IEN",ZI,ZIEN)="" 361 Q 362 ; 363 UPDIE(ZFDA) ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS 364 ; ZFDA IS PASSED BY REFERENCE 365 ;ZWR ZFDA 366 ;B 367 K ZERR 368 D CLEAN^DILF 369 D UPDATE^DIE("","ZFDA","","ZERR") 370 I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST, 371 ; INVOKE THE ERROR TRAP IF TASKED 372 ;. W "ERROR",! 373 ;. ZWR ZERR 374 ;. B 375 K ZFDA 376 Q 377 ; -
fmts/trunk/p/C0XTEST.m
r1280 r1294 1 C0XTEST 2 ;;0.1;C0X;nopatch;noreleasedate;Build 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 EN 23 24 25 26 27 28 29 30 f zi=1:1:10000 d ; try a test of 10000 nodes31 32 33 34 35 36 37 38 39 40 41 42 43 W !," APPROXIMATELY ",$P(10000/C0XDIFF,".")," NODES PER SECOND"44 45 46 LKY9() 47 48 49 50 51 52 53 54 LKY17() 55 56 57 58 59 60 61 62 BULKLOAD(ZBFDA) 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 BLKERR 122 123 124 125 1 C0XTEST ; GPL - Fileman Triples bulk load tester ;11/6/11 17:05 2 ;;0.1;C0X;nopatch;noreleasedate;Build 5 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 EN ; run the test 23 ; 24 k C0XFDA ; clear the node variable 25 i '$d(^C0X(101,0)) d ; global doesn't exist 26 . s ^C0X(101,0)="C0X TRIPLE^172.101^1^1" 27 n zg 28 S zg="_:G"_$$LKY9 ; all nodes are in the same graph 29 n zi 30 f zi=1:1:100000 d ; try a test of 10000 nodes 31 . s C0XFDA(172.101,zi,.01)="N"_$$LKY17 ; node name 32 . s C0XFDA(172.101,zi,.02)=zg 33 . s C0XFDA(172.101,zi,.03)=$R(100000) 34 . s C0XFDA(172.101,zi,.04)=$R(100000) 35 . s C0XFDA(172.101,zi,.05)=$R(100000) 36 S C0XST=$$NOW^XLFDT ; start of the insertion test 37 W !,"INSERTION STARTS AT ",C0XST,! 38 d BULKLOAD(.C0XFDA) 39 s C0XEND=$$NOW^XLFDT ; end of the insertion test 40 W !,"INSERTION ENDS AT ",C0XEND 41 S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XST,2) 42 W !," ELAPSED TIME: ",C0XDIFF," SECONDS" 43 I C0XDIFF>0 W !," APPROXIMATELY ",$P(100000/C0XDIFF,".")," NODES PER SECOND" 44 q 45 ; 46 LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 47 ; UNIQUE NODE AND GRAPH NAMES 48 N ZN,ZI 49 S ZN="" 50 F ZI=1:1:9 D ; 51 . S ZN=ZN_$R(10) 52 Q ZN 53 ; 54 LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING 55 ; UNIQUE NODE AND GRAPH NAMES 56 N ZN,ZI 57 S ZN="" 58 F ZI=1:1:17 D ; 59 . S ZN=ZN_$R(10) 60 Q ZN 61 ; 62 BULKLOAD(ZBFDA) ; BULK LOADER FOR LOADING TRIPLES INTO FILE 172.101 63 ; USING GLOBAL SETS INSTEAD OF UPDATE^DIE 64 ; QUITS IF FILE IS NOT 172.101 65 ; EXPECTS AN FDA WITHOUT STRINGS FOR THE IENS, STARTING AT 1 66 ; QUITS IF FIRST ENTRY IS NOT IENS 1 67 ; ASSUMES THAT THE LAST IENS IS THE COUNT OF ENTRIES 68 ; ZBFDA IS PASSED BY REFERENCE 69 ; 70 ; -- reserves a block of iens from file 172.101 by locking the zero node 71 ; -- ^C0X(101,0) and adding the count of entries to piece 2 and 3 72 ; -- then unlocking to minimize the duration of the lock 73 ; 74 W !,"USING BULKLOAD" 75 I '$D(ZBFDA) Q ; EMPTY FDA 76 I $O(ZBFDA(""))'=172.101 Q ; WRONG FILE 77 N ZCNT,ZP3,ZP4 78 ; -- find the number of nodes to insert 79 S ZCNT=$O(ZBFDA(172.101,""),-1) 80 I ZCNT="" D Q ; 81 . W !,"ERROR IN BULK LOAD - INVALID NODE COUNT" 82 . B 83 ; -- lock the zero node and reserve a block of iens to insert 84 W !,"LOCKING ZERO NODE" 85 LOCK +^C0X(101,0) 86 S ZP3=$P(^C0X(101,0),U,3) 87 S ZP4=$P(^C0X(101,0),U,4) 88 S $P(^C0X(101,0),U,3)=ZP3+ZCNT+1 89 S $P(^C0X(101,0),U,4)=ZP4+ZCNT+1 90 LOCK -^C0X(101,0) 91 N ZI,ZN,ZG,ZS,ZP,ZO,ZIEN,ZBASE 92 S ZBASE=ZP3 ; the last ien in the file 93 W !,"ZERO NODE UNLOCKED, IENS RESERVED=",ZCNT 94 W !,$$NOW^XLFDT 95 S ZI="" 96 F S ZI=$O(ZBFDA(172.101,ZI)) Q:ZI="" D ; 97 . S ZN=$G(ZBFDA(172.101,ZI,.01)) ; node name 98 . I ZN="" D BLKERR Q ; 99 . S ZG=$G(ZBFDA(172.101,ZI,.02)) ; graph pointer 100 . I ZG="" D BLKERR Q ; 101 . S ZS=$G(ZBFDA(172.101,ZI,.03)) ; subject pointer 102 . I ZS="" D BLKERR Q ; 103 . S ZP=$G(ZBFDA(172.101,ZI,.04)) ; predicate pointer 104 . I ZP="" D BLKERR Q ; 105 . S ZO=$G(ZBFDA(172.101,ZI,.05)) ; object pointer 106 . I ZO="" D BLKERR Q ; 107 . S ZIEN=ZI+ZBASE ; the new ien 108 . S ^C0X(101,ZIEN,0)=ZN_U_ZG_U_ZS_U_ZP_U_ZO ; set the zero node 109 . S ^C0X(101,"B",ZN,ZIEN)="" ; the B index 110 . S ^C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index 111 . S ^C0X(101,"SPO",ZS,ZP,ZO)="" 112 . S ^C0X(101,"SOP",ZS,ZO,ZP)="" 113 . S ^C0X(101,"OPS",ZO,ZP,ZS)="" 114 . S ^C0X(101,"OSP",ZO,ZS,ZP)="" 115 . S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS)="" 116 . S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP)="" 117 . S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO)="" 118 . S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO)="" 119 Q 120 ; 121 BLKERR ; 122 W !,"ERROR IN BULK LOAD",! ZWR ZBFDA(ZI) 123 B 124 Q 125 ;
Note:
See TracChangeset
for help on using the changeset viewer.