Changeset 1343 for fmts/trunk


Ignore:
Timestamp:
Jan 20, 2012, 3:18:05 PM (13 years ago)
Author:
George Lilly
Message:

beginning some retrieval code

Location:
fmts/trunk/p
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • fmts/trunk/p/C0XF2N.m

    r1322 r1343  
    11C0XF2N ; GPL - Fileman Triples entry point routine ;10/13/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 5
     2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
    33 ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    44 ;General Public License See attached copy of the License.
  • fmts/trunk/p/C0XINIT.m

    r1294 r1343  
    11C0XINIT ; GPL - Fileman Triples initialization routine ;10/13/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 5
     2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
    33 ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    44 ;General Public License See attached copy of the License.
  • fmts/trunk/p/C0XMAIN.m

    r1294 r1343  
    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         ;
     1C0XMAIN ; 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 ;
     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 S @ZFARY@("C0XDIR")="/home/george/fmts/trunk/samples/"
     31 D USEFARY(ZFARY)
     32 Q
     33 ;
     34USEFARY(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 ;
     43IMPORT(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 ;
     71WGET(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 ;
     89INSRDF(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 ;
     109STORETXT(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 ;
     124GETTXT(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 ;
     135WHERETXT(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 ;
     145FILEIN(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 ;
     153TESTPROC ; 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 ;
     160PROCESS(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 ;
     261SHOW(ZN) ;
     262 ZWR ^TMP("MXMLDOM",$J,1,ZN,*)
     263 Q
     264 ;
     265ANONS() ; RETURNS AN ANONOMOUS SUBJECT
     266 Q "_S:"_$$LKY9
     267 ;
     268NEWG(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 ;
     275ADD(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 ;
     304LKY9() ;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 ;
     312LKY17() ;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 ;
     320IENOF(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 ;
     333IENOFA(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 ;
     363UPDIE(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

    r1294 r1343  
    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         ;
     1C0XTEST ; GPL - Fileman Triples bulk load tester ;11/6/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 ;
     22EN ; 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 ;
     46LKY9() ;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 ;
     54LKY17() ;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 ;
     62BULKLOAD(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 ;
     121BLKERR ;
     122 W !,"ERROR IN BULK LOAD",! ZWR ZBFDA(ZI)
     123 B
     124 Q
     125 ;
  • fmts/trunk/p/C0XTKSB.m

    r1322 r1343  
    11C0XTESTKSB ; GPL - Fileman Triples bulk load tester ;11/6/11  17:05
    2  ; KSB - modified to fix a minor bug and to use
     2 ; KSB - modified to fix a minor bug and to use;;;;;Build 7
    33 ;       high resolution time if routines available ; 11/19/11 1410 EST
    44 ;;0.1;C0X;nopatch;noreleasedate;Build 1
     
    128128 Q
    129129 ;
    130 H()
     130H() 
    131131 quit:$length($ztrnlnm("GTMXC_posix"))&$length($text(zhorolog^%POSIX)) $$zhorolog^%POSIX quit $horolog
  • fmts/trunk/p/C0XUTIL.m

    r1322 r1343  
    11C0XUTIL ; GPL - Fileman Triples utilities ;11/07/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 5
     2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
    33 ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    44 ;General Public License See attached copy of the License.
Note: See TracChangeset for help on using the changeset viewer.