Changeset 1539


Ignore:
Timestamp:
Sep 26, 2012, 12:58:34 PM (12 years ago)
Author:
Sam Habiel
Message:

Proper KIDS build + Routines

Location:
fmts/trunk
Files:
1 added
11 deleted
8 edited

Legend:

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

    r1499 r1539  
    1 C0XF2N ; GPL - Fileman Triples entry point routine ;10/13/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    4  ;General Public License See attached copy of the License.
    5  ;
    6  ;This program is free software; you can redistribute it and/or modify
    7  ;it under the terms of the GNU General Public License as published by
    8  ;the Free Software Foundation; either version 2 of the License, or
    9  ;(at your option) any later version.
    10  ;
    11  ;This program is distributed in the hope that it will be useful,
    12  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  ;GNU General Public License for more details.
    15  ;
    16  ;You should have received a copy of the GNU General Public License along
    17  ;with this program; if not, write to the Free Software Foundation, Inc.,
    18  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    19  ;
    20  Q
    21  ;
    22  ; This is based on C0XMAIN but experiments with a fast load for triples
    23  ; that will write directly to the fileman global
    24  ; The file 172.101 is a F2N design style for triples, which means
    25  ; that it is a Flat file with no subfiles, all fields at the root
    26  ; ... it is a "2" file solution which means all strings are stored in
    27  ; ...    strings file and pointed to by the triples file
    28  ; ... it is an N file because it has generated Node IDs instead of
    29  ; ...   DINUM which would use the IEN for the Node ID.
    30  ; gpl 11/04/2011
    31  ;
    32 INITFARY(ZFARY) ; INITIALIZE FILE NUMBERS AND OTHER USEFUL THINGS
    33  ; FOR THE DEFAULT TRIPLE STORE. USE OTHER VALUES FOR SUPPORTING ADDITIONAL
    34  ; TRIPLE STORES
    35  I $D(@ZFARY) Q  ; ALREADY INITIALIZED
    36  S @ZFARY@("C0XTFN")=172.101 ; TRIPLES FILE NUMBER
    37  S @ZFARY@("C0XSFN")=172.201 ; TRIPLES STRINGS FILE NUMBER
    38  S @ZFARY@("C0XTN")=$NA(^C0X(101)) ; TRIPLES GLOBAL NAME
    39  S @ZFARY@("C0XSN")=$NA(^C0X(201)) ; STRING FILE GLOBAL NAME
    40  S @ZFARY@("C0XDIR")="/home/glilly/fmts/trunk/samples/smart-new/"
    41  S @ZFARY@("BLKLOAD")=1 ; this file supports block load
    42  S @ZFARY@("FMTSSTYLE")="F2N" ; fileman style
    43  S @ZFARY@("REPLYFMT")="JSON"
    44  D USEFARY(ZFARY)
    45  Q
    46  ;
    47 USEFARY(ZFARY) ; INITIALIZES VARIABLES SAVED IN ARRAY ZFARY
    48  N ZI S ZI=""
    49  F  S ZI=$O(@ZFARY@(ZI)) Q:ZI=""  D 
    50  . ;N ZX
    51  . S ZX="S "_ZI_"="""_@ZFARY@(ZI)_""""
    52  . ;W !,ZX
    53  . X ZX
    54  Q
    55  ;
    56 FILEIN ; INTERACTIVE ENTRY POINT FOR OPTION TO READ IN A FILE
    57  I '$D(C0XFARY) D INITFARY("C0XFARY")
    58  D USEFARY("C0XFARY")
    59  S DIR(0)="F^3:240"
    60  S DIR("A")="File Directory"
    61  S DIR("B")=C0XDIR
    62  D ^DIR
    63  I Y="^" Q  ;
    64  S C0XDIR=Y
    65  S C0XFARY("C0XDIR")=Y
    66  S DIR(0)="F^3:240"
    67  S DIR("A")="File Name"
    68  I '$D(C0XFN) S DIR("B")="qds.rdf"
    69  E  S DIR("B")=C0XFN
    70  D ^DIR
    71  I Y="" Q  ;
    72  I Y="^" Q  ;
    73  S C0XFN=Y
    74  D IMPORT(C0XFN,C0XDIR,,"C0XFARY")
    75  K C0XFDA
    76  Q
    77  ;
    78 IMPORT(FNAME,INDIR,INURL,FARY) ; EXTRINSIC THAT READS A FILE FROM THE STANDARD
    79  ; DIRECTORY, LOADS IT INTO THE TRIPLESTORE AS TEXT, AND RETURNS THE
    80  ; NODE NAME OF THE TEXT TRIPLE
    81  ; INDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR)
    82  ; INURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE
    83  ; FARY IS THE OPTIONAL FILE ARRAY OF THE TRIPLE STORE TO USE
    84  I '$D(FARY) D  ;
    85  . D INITFARY("C0XFARY")
    86  . S FARY="C0XFARY"
    87  D USEFARY(FARY)
    88  N ZD,ZTMP
    89  I '$D(INDIR) S INDIR=C0XDIR ; DIRECTORY OF THE RDF FILE
    90  I $G(INURL)="" D  ;
    91  . ;N ZN2 S ZN2=$P(FNAME,".",1)_"_"_$P(FNAME,".",2) ; REMOVE THE DOT
    92  . ;S INURL=FDIR_ZN2
    93  . S INURL=INDIR_FNAME
    94  N ZTMP
    95  S ZTMP=$NA(^TMP("C0X",$J,"FILEIN",1)) ; WHERE TO PUT THE INCOMING FILE
    96  K @ZTMP ; MAKE SURE IT'S CLEAR
    97  S C0XSTART=$$NOW^XLFDT
    98  W !,"STARTED: ",C0XSTART
    99  W !,"READING IN: ",FNAME
    100  I '$$FILEREAD(ZTMP,INDIR,FNAME,4) D  Q  ; QUIT IF NO SUCCESS
    101  . W !,"ERROR READING FILE: ",INDIR,FNAME
    102  S ZRDF=$NA(^TMP("C0X",$J,"FILEIN")) ; WITHOUT THE SUBSCRIPT
    103  W !,$O(@ZRDF@(""),-1)," LINES READ"
    104  D INSRDF(ZRDF,INURL,FARY) ; IMPORT AND PROCESS THE RDF
    105  K INURL
    106  K C0XFDA
    107  ;K ^TMP("MXMLDOM",$J)
    108  Q
    109  ;
    110 WGET(ZURL,FARY) ; GET FROM THE INTERNET AN RDF FILE AND INSERT IT
    111  ;
    112  I '$D(FARY) D  ;
    113  . D INITFARY("C0XFARY")
    114  . S FARY="C0XFARY"
    115  D USEFARY(FARY)
    116  ;N ZLOC,ZTMP
    117  K ZTMP
    118  S ZLOC=$NA(^TMP("C0X","WGET",$J))
    119  K @ZLOC
    120  S C0XSTART=$$NOW^XLFDT
    121  W !,"STARTED: ",C0XSTART
    122  W !,"DOWNLOADING: ",ZURL
    123  S OK=$$httpGET^%zewdGTM(ZURL,.ZTMP)
    124  M @ZLOC=ZTMP
    125  S C0XLINES=$O(@ZLOC@(""),-1)
    126  W !,C0XLINES," LINES READ"
    127  S C0XDLC=$$NOW^XLFDT ; DOWNLOAD COMPLETE
    128  W !,"DOWNLOAD COMPLETE AT ",C0XDLC
    129  S C0XDIFF=$$FMDIFF^XLFDT(C0XDLC,C0XSTART,2)
    130  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    131  I C0XDIFF'=0  W !," APPROXIMATELY ",$P(C0XLINES/C0XDIFF,".")," LINES PER SEC"
    132  D INSRDF(ZLOC,ZURL,FARY)
    133  Q
    134  ;
    135 INSRDF(ZRDF,ZNAME,FARY) ; INSERT AN RDF FILE INTO THE STORE AND PROCESS
    136  ; ZRDF IS PASSED BY NAME
    137  I '$D(FARY) D  ;
    138  . D INITFARY("C0XFARY")
    139  . S FARY="C0XFARY"
    140  D USEFARY(FARY)
    141  S BATCNT=0 ; BATCH COUNTER
    142  S BATMAX=10000 ; TRY BATCHES OF THIS SIZE
    143  N ZGRAPH,ZSUBJECT
    144  S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME
    145  S ZSUBJECT=$$ANONS() ; RANDOM ANOYMOUS SUBJECT
    146  D ADD(ZGRAPH,ZSUBJECT,"fmts:url",ZNAME,FARY)
    147  N ZTXTNM
    148  S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE
    149  D ADD(ZGRAPH,ZSUBJECT,"fmts:fileSource",ZTXTNM,FARY)
    150  D ADD(ZGRAPH,ZSUBJECT,"fmts:fileTag",$$name2tag(ZNAME),FARY)
    151  D SWUPDIE(.C0XFDA) ; TRY IT OUT
    152  K C0XCNT ;RESET FOR NEXT TIME
    153  D STORETXT(ZRDF,ZTXTNM,FARY)
    154  W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:fileSource ",ZTXTNM
    155  D PROCESS(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF
    156  Q
    157  ;
    158 name2tag(zname) ; extrinsic which returns a tag derived from a name
    159  ; /home/vista/project.xml ==> project
    160  q $p($re($p($re(zname),"/")),".")
    161  ;
    162 STORETXT(ZTXT,ZNAME,FARY) ; STORE TEXT IN THE TRIPLESTORE AT ZNAME
    163  ;
    164  I '$D(FARY) D  ;
    165  . D INITFARY("C0XFARY")
    166  . S FARY="C0XFARY"
    167  D USEFARY(FARY)
    168  N ZIEN
    169  S ZIEN=$$IENOF(ZNAME,FARY) ; GET THE IEN
    170  D CLEAN^DILF
    171  K ZERR
    172  D WP^DIE(C0XSFN,ZIEN_",",1,,ZTXT,"ZERR")
    173  I $D(ZERR) D  Q  ;
    174  . W !,"ERROR CREATING WORD PROCESSING FIELD"
    175  . S C0XERR="ERROR CREATING WORD PROCESSING FIELD"
    176  . D ^%ZTER ; error trap
    177  Q
    178  ;
    179 GETTXT(ZRTN,ZNAME,FARY) ; RETURNS RDF SOURCE OR OTHER TEXT
    180  ; ZRTN IS PASSED BY REFERENCE
    181  I '$D(FARY) D  ;
    182  . D INITFARY("C0XFARY")
    183  . S FARY="C0XFARY"
    184  D USEFARY(FARY)
    185  N ZIEN
    186  S ZIEN=$$IENOF(ZNAME)
    187  S OK=$$GET1^DIQ(C0XSFN,ZIEN_",",1,,"ZRTN")
    188  Q
    189  ;
    190 WHERETXT(ZNAME,FARY) ; EXTRINSIC WHICH RETURNS THE NAME OF THE GLOBAL
    191  ; WHERE THE TEXT IS LOCATED. NAME IS THE NAME OF THE STRING
    192  I '$D(FARY) D  ;
    193  . D INITFARY("C0XFARY")
    194  . S FARY="C0XFARY"
    195  D USEFARY(FARY)
    196  N ZIEN
    197  S ZIEN=$$IENOF(ZNAME)
    198  Q $NA(@C0XSN@(ZIEN,1))
    199  ;
    200 FILEREAD(ZINTMP,ZDIR,ZFNAME,ZLVL) ; READS A FILE INTO ZINTMP USING FTG^%ZISH
    201  ; ZINTMP IS PASSED BY NAME AND INCLUDES THE NEW SUBSCRIPT
    202  ; IE ^TMP("C0X","FILEIN",1)
    203  ; ZLVL IN THIS CASE WOULD BE 3 INCREMENTING THE 1
    204  ; EXTRINSIC WHICH RETURNS THE RESULT OF FTG^%ZISH
    205  S OK=$$FTG^%ZISH(ZDIR,FNAME,ZINTMP,ZLVL)
    206  Q OK
    207  ;
    208 TESTPROC ; TEST PROCESS WITH EXISTING SMALL RDF FILE
    209  S ZIN=$NA(^TMP("C0X",12226,"FILEIN"))
    210  S ZGRAPH="/test/rdfFile"
    211  S ZM="/test/rdfFile/meta"
    212  D PROCESS(.G,ZIN,ZGRAPH,ZM)
    213  Q
    214  ;
    215 VISTAOWL ;
    216  S ZRDF=$NA(^TMP("C0X",542,"FILEIN"))
    217  S ZNAME="/home/glilly/vistaowl/VistAOWL.owl"
    218  S ZGRAPH="_:G431590209"
    219  S FARY="C0XFARY"
    220  D INITFARY(FARY)
    221  S C0XDOCID=1
    222  S BATCNT=0
    223  S BATMAX=10000
    224  D PROCESS(.G,ZRDF,ZGRAPH,ZNAME,FARY)
    225  Q
    226  ;
    227 PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE
    228  ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING
    229  ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE
    230  ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS
    231  ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA
    232  ;
    233  I '$D(FARY) D  ;
    234  . D INITFARY("C0XFARY")
    235  . S FARY="C0XFARY"
    236  D USEFARY(FARY)
    237  ;N BATCNT
    238  ;N BATMAX
    239  ; -- first parse the rdf file with the MXML parser
    240  ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML
    241  S C0XDLC2=$$NOW^XLFDT ; START OF PARSE
    242  I @ZRDF@(1)'["<?xml" D  Q  ;
    243  . K @ZRDF ; don't need the input buffer
    244  . W !,"Not an XML file"
    245  S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") ;
    246  ;B
    247  K @ZRDF ; DON'T NEED INPUT BUFFER ANYMORE
    248  ; -- assign the MXLM dom global name to ZDOM
    249  S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID))
    250  ;S ZDOM=$NA(^TMP("MXMLDOM",16850,C0XDOCID)) ;VISTAOWL DOM
    251  S C0XNODE=$O(@ZDOM@(""),-1)
    252  W !,C0XNODE," XML NODES PARSED"
    253  S C0XPRS=$$NOW^XLFDT ; PARSE COMPLETE
    254  W !,"PARSE COMPLETE AT ",C0XPRS
    255  S C0XDIFF=$$FMDIFF^XLFDT(C0XPRS,C0XDLC2,2)
    256  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    257  I C0XDIFF'=0 D  ;
    258  . W !," APPROXIMATELY ",$P(C0XNODE/C0XDIFF,".")," NODES PER SECOND"
    259  ; -- populate the metagraph to point to the graph with status unfinished
    260  S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT
    261  I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH
    262  D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH
    263  D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished
    264  W !,"INSERTING GRAPH: ",ZGRF
    265  ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT")
    266  S C0XDATE=$$NOW^XLFDT
    267  D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY)
    268  D SWUPDIE(.C0XFDA) ; commit the metagraph changes to the triple store
    269  ; --
    270  ; -- pull out the vocabularies in the RDF statement. marked with xmlns:
    271  ; -- put them in a local variable for quick reference
    272  ; -- TODO: create a graph for vocabularies and validate incoming against it
    273  ;
    274  S C0XVOC=""
    275  N ZI,ZJ,ZK S ZI=""
    276  F  S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI=""  D  ; FOR EACH xmlns
    277  . S ZVOC=$P(ZI,"xmlns:",2)
    278  . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))
    279  I $D(DEBUG) D  ;
    280  . W !,"VOCABS:"
    281  . N ZZ S ZZ=""
    282  . F  S ZZ=$O(C0XVOC(ZZ)) Q:ZZ=""  W !,ZZ,":",C0XVOC(ZZ)
    283  ;
    284  ; -- look for children called rdf:Description. quit if none. not an rdf file
    285  ;
    286  S C0XTYPE("rdf:Description")=1
    287  S C0XTYPE("owl:ObjectProperty")=1
    288  S C0XTYPE("owl:Ontology")=1
    289  S C0XTYPE("owl:Class")=1
    290  S C0XTYPE("rdfs:subClassOf")=1
    291  S C0XTYPE("rdf:RDF")=1
    292  S ZI=$O(@ZDOM@(1,"C",""))
    293  I '$G(C0XTYPE(@ZDOM@(1,"C",ZI))) D  ;Q  ; not an rdf file
    294  . W !,"Unusual RDF file ",@ZDOM@(1,"C",ZI)
    295  . ;W !,"Error. Not an RDF file. Cannot process."
    296  . D SHOW(1)
    297  ;
    298  ; -- now process the rdf description children
    299  ;
    300  S ZI=""
    301  S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate
    302  F  S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI=""  D  ;
    303  . ; -- we are skipping any child that is not rdf:Description
    304  . ; -- TODO: check to see if this is right in general
    305  . ;
    306  . IF '$G(C0XTYPE(@ZDOM@(1,"C",ZI))) D  Q  ;
    307  . . W !,"SKIPPING NODE: ",ZI
    308  . ; -- now looking for the subject for the triples
    309  . S ZX=$G(@ZDOM@(ZI,"A","rdf:about"))
    310  . I ZX'="" D  ; we have the subject
    311  . . ;W " about: ",ZX
    312  . . S C0XSUB=ZX
    313  . E  D  ;
    314  . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject
    315  . . I ZX'="" D  ;
    316  . . . S C0XSUB=ZX
    317  . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT
    318  . ;
    319  . ; -- we now have the subject. the children of this node have the rest
    320  . ;
    321  . S ZJ="" ; for the children of the rdf:Description nodes
    322  . F  S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ=""  D  ; for each child
    323  . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix
    324  . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space
    325  . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix
    326  . . I C0XPRE[":" D  ; expand using vocabulary
    327  . . . N ZB,ZA
    328  . . . S ZB=$P(C0XPRE,":",1)
    329  . . . S ZA=$P(C0XPRE,":",2)
    330  . . . I $G(C0XVOC(ZB))'="" D  ;
    331  . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
    332  . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object
    333  . . I ZY'="" D  Q ;
    334  . . . S C0XOBJ=$$EXT^C0XUTIL(ZY) ; object
    335  . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple
    336  . . ; -- this is an else because of the quit above
    337  . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object
    338  . . I ZX'="" D  Q  ; got one
    339  . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject
    340  . . . ; without change... this could be foolish .. look at it again later
    341  . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
    342  . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here
    343  . . I C0XOBJ="" D  Q  ; not a happy situation
    344  . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ
    345  . . S C0XOBJ=$$EXT^C0XUTIL(C0XOBJ) ; might be namespaced
    346  . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
    347  S C0XTRP=$$NOW^XLFDT ; PARSE COMPLETE
    348  W !,"TRIPLES COMPLETE AT ",C0XTRP
    349  S C0XDIFF=$$FMDIFF^XLFDT(C0XTRP,C0XPRS,2)
    350  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    351  I C0XDIFF'=0 D  ;
    352  . W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
    353  W !,"INSERTING ",C0XCNT," TRIPLES"
    354  I $D(C0XFDA) D  ;
    355  . I $G(BLKLOAD) D  ;
    356  . . D BULKLOAD(.C0XFDA)
    357  . E  D  ;
    358  . . D UPDIE(.C0XFDA) ; commit the updates to the file
    359  ; next, mark the graph as finished
    360  S C0XINS=$$NOW^XLFDT ; PARSE COMPLETE
    361  W !,"INSERTION COMPLETE AT ",C0XPRS
    362  S C0XDIFF=$$FMDIFF^XLFDT(C0XINS,C0XTRP,2)
    363  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    364  I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," NODES PER SECOND"
    365  S C0XEND=$$NOW^XLFDT
    366  W !," ENDED AT: ",C0XEND
    367  S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2)
    368  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    369  I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
    370  Q
    371  ;
    372 SHOW(ZN) ;
    373  I '$D(C0XJOB) S C0XJOB=$J
    374  N ZD
    375  S ZD=$NA(^TMP("MXMLDOM",C0XJOB,1,ZN))
    376  W ZD,"=",@ZD
    377  F  S ZD=$Q(@ZD) Q:$QS(ZD,4)'=ZN  W !,ZD,"=",@ZD
    378  ;ZWR ^TMP("MXMLDOM",C0XJOB,1,ZN,*)
    379  Q
    380  ;
    381 ANONS() ; RETURNS AN ANONOMOUS SUBJECT
    382  Q "iDPsDPss"_$$LKY9
    383  ;
    384 NEWG(NGRAPH,NMETA) ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED
    385  ; THEN CREATES A NEW GRAPH AND POINTS THE METAGRAPH TO IT
    386  ; NGRAPH AND NMETA ARE PASSED BY REFERENCE AND ARE THE RETURN
    387  S NGRAPH="G"_$$LKY9
    388  S NMETA=NGRAPH_"A"
    389  Q
    390  ;
    391 STARTADD ; INITIALIZE C0XFDA AND BATCNT
    392  K C0XFDA
    393  K BATCNT
    394  Q
    395  ;
    396 ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
    397  ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE
    398  I '$D(FARY) D  ;
    399  . D INITFARY("C0XFARY")
    400  . S FARY="C0XFARY"
    401  D USEFARY(FARY)
    402  I '$D(C0XCNT) S C0XCNT=0
    403  N ZNODE
    404  S ZNODE="N"_$$LKY17
    405  N ZNARY ; GET READY TO CALL IENOFA
    406  I (ZG="")!(ZS="")!(ZP="")!(ZO="") D  Q  ;
    407  . I $G(DEBUG) W !,"Error Empty String ZG:"_ZG_" ZS:"_ZS_" ZP:"_ZP_" ZO"_ZO
    408  S ZNARY("ZG",ZG)=""
    409  S ZNARY("ZS",ZS)=""
    410  S ZNARY("ZP",ZP)=""
    411  S ZNARY("ZO",ZO)=""
    412  D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS
    413  ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN
    414  ;S ZSIEN=$$IENOF(ZS)
    415  ;S ZPIEN=$$IENOF(ZP)
    416  ;S ZOIEN=$$IENOF(ZO)
    417  ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED
    418  I '$D(BATCNT) S BATCNT=0
    419  S BATCNT=BATCNT+1
    420  S C0XCNT=C0XCNT+1
    421  I $G(BLKLOAD)=1 D  ; we are using bulk load
    422  . S C0XFDA(C0XTFN,BATCNT,.01)=ZNODE
    423  . S C0XFDA(C0XTFN,BATCNT,.02)=$O(ZIENS("IEN","ZG",""))
    424  . S C0XFDA(C0XTFN,BATCNT,.03)=$O(ZIENS("IEN","ZS",""))
    425  . S C0XFDA(C0XTFN,BATCNT,.04)=$O(ZIENS("IEN","ZP",""))
    426  . S C0XFDA(C0XTFN,BATCNT,.05)=$O(ZIENS("IEN","ZO",""))
    427  E  D  ;
    428  . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.01)=ZNODE
    429  . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.02)=$O(ZIENS("IEN","ZG",""))
    430  . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.03)=$O(ZIENS("IEN","ZS",""))
    431  . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.04)=$O(ZIENS("IEN","ZP",""))
    432  . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.05)=$O(ZIENS("IEN","ZO",""))
    433  I '$D(BATMAX) S BATMAX=10000
    434  I BATCNT=BATMAX D  ; BATCH IS DONE
    435  . I $G(BLKLOAD) D  ; bulk load
    436  . . D BULKLOAD(.C0XFDA) ; bulk load the batch
    437  . E  D  ; no bulk load
    438  . . D UPDIE(.C0XFDA)
    439  . K C0XFDA
    440  . S BATCNT=0 ; RESET COUNTER
    441  ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE
    442  Q
    443  ;
    444 LKY5() ;EXTRINIC THAT RETURNS A RANDOM 5 DIGIT NUMBER. USED FOR GENERATING
    445  ; UNIQUE NODE AND GRAPH NAMES
    446  N ZN,ZI
    447  S ZN=""
    448  F ZI=1:1:5 D  ;
    449  . S ZN=ZN_$R(10)
    450  Q ZN
    451  ;
    452 LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
    453  ; UNIQUE NODE AND GRAPH NAMES
    454  N ZN,ZI
    455  S ZN=""
    456  F ZI=1:1:9 D  ;
    457  . S ZN=ZN_$R(10)
    458  Q ZN
    459  ;
    460 LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
    461  ; UNIQUE NODE AND GRAPH NAMES
    462  N ZN,ZI
    463  S ZN=""
    464  F ZI=1:1:17 D  ;
    465  . S ZN=ZN_$R(10)
    466  Q ZN
    467  ;
    468  ; these routines add the string if it is not found
    469  ;
    470 IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
    471  I '$D(FARY) D  ;
    472  . D INITFARY("C0XFARY")
    473  . S FARY="C0XFARY"
    474  N ZIEN
    475  I $G(ZSTRING)="" Q "" ; NO STRING
    476  S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
    477  I ZIEN="" D  ;
    478  . S C0XFDA2(C0XSFN,"+1,",.01)=ZSTRING
    479  . D UPDIE(.C0XFDA2)
    480  . S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
    481  . K C0XFDA2
    482  Q ZIEN
    483  ;
    484 IENOFA(ZOUTARY,INARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
    485  ; OR ADD THEM IF
    486  ; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE
    487  ; ZINARY LOOKS LIKE ZINARY("VAR","VAL")=""
    488  ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)=""
    489  I '$D(FARY) D  ;
    490  . D INITFARY("C0XFARY")
    491  . S FARY="C0XFARY"
    492  K ZOUTARY ; START WITH CLEAN RESULTS
    493  K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
    494  I '$D(C0XVOC) D VOCINIT^C0XUTIL
    495  N ZINARY
    496  N ZI S ZI=""
    497  F  S ZI=$O(INARY(ZI)) Q:ZI=""  D  ;
    498  . N ZK
    499  . S ZK=$O(INARY(ZI,""))
    500  . S ZINARY($$EXT^C0XUTIL(ZI),$$EXT^C0XUTIL(ZK))=""
    501  N ZV,ZIEN,ABORT
    502  S ABORT=0
    503  N ZCNT S ZCNT=0
    504  F  S ZI=$O(ZINARY(ZI)) Q:(ZI="")!+ABORT  D  ; LOOK FOR MISSING STRINGS
    505  . S ZV=$O(ZINARY(ZI,""))
    506  . I ZV="" S ABORT=1 Q  ; abandon quad -- missing an entry
    507  . I ZV["^" S ZV=$TR(ZV,"^","|")
    508  . I $O(@C0XSN@("B",ZV,""))="" D  ;
    509  . . S ZCNT=ZCNT+1
    510  . . S C0XFDA2(C0XSFN,"+"_ZCNT_",",.01)=ZV
    511  I +ABORT Q  ;
    512  I $D(C0XFDA2) D  ;
    513  . D UPDIE(.C0XFDA2) ; ADD MISSING STRINGS
    514  . K C0XFDA2 ; CLEAN UP
    515  F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; NOW GET ALL IENS
    516  . S ZV=$O(ZINARY(ZI,""))
    517  . I ZV["^" S ZV=$TR(ZV,"^","|")
    518  . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW
    519  . I ZIEN="" D  ;
    520  . . W !,"ERROR ADDING STRING: ",ZV
    521  . . B
    522  . S ZOUTARY("IEN",ZI,ZIEN)=""
    523  Q
    524  ;
    525 ADDINN(ZG,ZS,ZARY) ; ADD IF NOT NULL
    526  ; ZG IS THE GRAPH NAME, PASSED BY VALUE
    527  ; ZS IS THE SUBJECT, PASSED BY VALUE
    528  ; ZARY IS AN ARRAY, PASSED BY REFERENCE OF THE PREDICATE AND OBJECT
    529  ;  FORMAT IS ZARY(PRED)=OBJ
    530  N ZI S ZI=""
    531  F  S ZI=$O(ZARY(ZI)) Q:ZI=""  D  ;
    532  . ;I ZARY(ZI)="" S ZARY(ZI)="NULL"
    533  . I ZARY(ZI)'="" D  ;
    534  . . D ADD^C0XF2N(ZG,ZS,ZI,ZARY(ZI))
    535  . . I $D(DEBUG) W !,"ADDING",ZI," ",ZARY(ZI)
    536  ;ZWR ZARY
    537  Q
    538  ;
    539 BULKLOAD(ZBFDA) ; BULK LOADER FOR LOADING TRIPLES INTO FILE 172.101
    540  ; USING GLOBAL SETS INSTEAD OF UPDATE^DIE
    541  ; QUITS IF FILE IS NOT 172.101
    542  ; EXPECTS AN FDA WITHOUT STRINGS FOR THE IENS, STARTING AT 1
    543  ; QUITS IF FIRST ENTRY IS NOT IENS 1
    544  ; ASSUMES THAT THE LAST IENS IS THE COUNT OF ENTRIES
    545  ; ZBFDA IS PASSED BY REFERENCE
    546  ;
    547  ; -- reserves a block of iens from file 172.101 by locking the zero node
    548  ; -- ^C0X(101,0) and adding the count of entries to piece 2 and 3
    549  ; -- then unlocking to minimize the duration of the lock
    550  ;
    551  I $D(DEBUG) W !,"USING BULKLOAD"
    552  I '$D(ZBFDA) Q  ; EMPTY FDA
    553  I $O(ZBFDA(""))'=172.101 Q  ; WRONG FILE
    554  N ZCNT,ZP3,ZP4
    555  ; -- find the number of nodes to insert
    556  S ZCNT=$O(ZBFDA(172.101,""),-1)
    557  I ZCNT="" D  Q  ;
    558  . W !,"ERROR IN BULK LOAD - INVALID NODE COUNT"
    559  . B
    560  ; -- lock the zero node and reserve a block of iens to insert
    561  I $D(DEBUG) W !,"LOCKING ZERO NODE"
    562  LOCK +^C0X(101,0)
    563  S ZP3=$P(^C0X(101,0),U,3)
    564  S ZP4=$P(^C0X(101,0),U,4)
    565  S $P(^C0X(101,0),U,3)=ZP3+ZCNT+1
    566  S $P(^C0X(101,0),U,4)=ZP4+ZCNT+1
    567  LOCK -^C0X(101,0)
    568  N ZI,ZN,ZG,ZS,ZP,ZO,ZIEN,ZBASE
    569  S ZBASE=ZP3 ; the last ien in the file
    570  I $D(DEBUG) W !,"ZERO NODE UNLOCKED, IENS RESERVED=",ZCNT
    571  I $D(DEBUG) W !,$$NOW^XLFDT
    572  S ZI=""
    573  F  S ZI=$O(ZBFDA(172.101,ZI)) Q:ZI=""  D  ;
    574  . S ZN=$G(ZBFDA(172.101,ZI,.01)) ; node name
    575  . I ZN="" D BLKERR Q  ;
    576  . S ZG=$G(ZBFDA(172.101,ZI,.02)) ; graph pointer
    577  . I ZG="" D BLKERR Q  ;
    578  . S ZS=$G(ZBFDA(172.101,ZI,.03)) ; subject pointer
    579  . I ZS="" D BLKERR Q  ;
    580  . S ZP=$G(ZBFDA(172.101,ZI,.04)) ; predicate pointer
    581  . I ZP="" D BLKERR Q  ;
    582  . S ZO=$G(ZBFDA(172.101,ZI,.05)) ; object pointer
    583  . I ZO="" D BLKERR Q  ;
    584  . S ZIEN=ZI+ZBASE ; the new ien
    585  . S ^C0X(101,ZIEN,0)=ZN_U_ZG_U_ZS_U_ZP_U_ZO ; set the zero node
    586  . D INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO)
    587  Q
    588  ;
    589 INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO) ; HARD SET THE INDEX FOR ONE ENTRY
    590  S ^C0X(101,"B",ZN,ZIEN)="" ; the B index
    591  S ^C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index
    592  S ^C0X(101,"SPO",ZS,ZP,ZO,ZIEN)=""
    593  S ^C0X(101,"SOP",ZS,ZO,ZP,ZIEN)=""
    594  S ^C0X(101,"OPS",ZO,ZP,ZS,ZIEN)=""
    595  S ^C0X(101,"OSP",ZO,ZS,ZP,ZIEN)=""
    596  S ^C0X(101,"PSO",ZP,ZS,ZO,ZIEN)=""
    597  S ^C0X(101,"POS",ZP,ZO,ZS,ZIEN)=""
    598  S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS,ZIEN)=""
    599  S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP,ZIEN)=""
    600  S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO,ZIEN)=""
    601  S ^C0X(101,"GPOS",ZG,ZP,ZO,ZS,ZIEN)=""
    602  S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO,ZIEN)=""
    603  S ^C0X(101,"GSOP",ZG,ZS,ZO,ZP,ZIEN)=""
    604  Q
    605  ;
    606 REINDEX ; REINDEX THE ^C0X(101, TRIPLE STORE
    607  K ^C0X(101,"B")
    608  K ^C0X(101,"G")
    609  K ^C0X(101,"SPO")
    610  K ^C0X(101,"SOP")
    611  K ^C0X(101,"OPS")
    612  K ^C0X(101,"OSP")
    613  K ^C0X(101,"PSO")
    614  K ^C0X(101,"POS")
    615  K ^C0X(101,"GOPS")
    616  K ^C0X(101,"GOSP")
    617  K ^C0X(101,"GPSO")
    618  K ^C0X(101,"GPOS")
    619  K ^C0X(101,"GSPO")
    620  K ^C0X(101,"GSOP")
    621  N ZIEN,ZZ
    622  S ZIEN=0
    623  F  S ZIEN=$O(^C0X(101,ZIEN)) Q:+ZIEN=0  D  ; FOR EACH NODE
    624  . S ZZ=$G(^C0X(101,ZIEN,0))
    625  . I ZZ="" D  Q  ;
    626  . . W !,"ERROR REINDEXING NODE ",ZI
    627  . S ZN=$P(ZZ,"^",1)
    628  . S ZG=$P(ZZ,"^",2)
    629  . S ZS=$P(ZZ,"^",3)
    630  . S ZP=$P(ZZ,"^",4)
    631  . S ZO=$P(ZZ,"^",5)
    632  . D INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO)
    633  Q
    634  ;
    635 BLKERR ;
    636  W !,"ERROR IN BULK LOAD"
    637  S C0XERR="ERROR IN BULK LOAD"
    638  S C0XLOC=ZBFDA(ZI)
    639  D ^%ZTER ; report the error
    640  B
    641  Q
    642  ;
    643 DELGRAPH(ZGRF,FARY) ; delete a graph from the triplestore
    644  ; (doesn't delete strings)
    645  ;
    646  I '$D(FARY) D  ;
    647  . D INITFARY("C0XFARY")
    648  . S FARY="C0XFARY"
    649  D USEFARY(FARY)
    650  N ZGRAPH
    651  D TING(.ZGRAPH,ZGRF,FARY)
    652  I '$D(ZGRAPH) D  Q  ;
    653  . I $D(DEBUG) W !,"NO TRIPLES IN GRAPH"
    654  K C0XFDA
    655  N ZI S ZI=""
    656  F  S ZI=$O(ZGRAPH(ZI)) Q:ZI=""  D  ;
    657  . S C0XFDA(C0XTFN,ZI_",",.01)="@"
    658  D UPDIE(.C0XFDA)
    659  Q
    660  ;
    661 TING(ZRTN,ZGRF,FARY) ; return the iens for graph ZGRF
    662  ; ZRTN is passed by reference
    663  I '$D(FARY) D  ;
    664  . D INITFARY("C0XFARY")
    665  . S FARY="C0XFARY"
    666  D USEFARY(FARY)
    667  K ZRTN
    668  N ZI,ZG S ZI=""
    669  S ZG=$$IENOF^C0XGET1(ZGRF)
    670  I ZG="" D  Q  ;
    671  . I $D(DEBUG) W !,"ERROR GRAPH NOT FOUND"
    672  I '$D(@C0XTN@("G",ZG)) Q  ;
    673  F  S ZI=$O(@C0XTN@("G",ZG,ZI)) Q:ZI=""  D  ;
    674  . S ZRTN(ZI)=""
    675  Q
    676  
    677 SWUPDIE(ZFDA) ; SWITCH BETWEEN UPDIE AND BULKLOAD
    678  I $G(BLKLOAD)=1 D  ; bulk load
    679  . D BULKLOAD(.ZFDA) ; bulk load the batch
    680  E  D  ; no bulk load
    681  . D UPDIE(.ZFDA)
    682  K ZFDA
    683  Q
    684  ;
    685 UPDIE(ZFDA) ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
    686  ; ZFDA IS PASSED BY REFERENCE
    687  ;ZWR ZFDA
    688  ;B
    689  K ZERR
    690  D CLEAN^DILF
    691  D UPDATE^DIE("","ZFDA","","ZERR")
    692  I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST,
    693  ; INVOKE THE ERROR TRAP IF TASKED
    694  ;. W "ERROR",!
    695  ;. ZWR ZERR
    696  ;. B
    697  K ZFDA
    698  Q
    699  ;
     1C0XF2N  ; GPL - Fileman Triples entry point routine ;10/13/11  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     3        ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
     4        ;General Public License See attached copy of the License.
     5        ;
     6        ;This program is free software; you can redistribute it and/or modify
     7        ;it under the terms of the GNU General Public License as published by
     8        ;the Free Software Foundation; either version 2 of the License, or
     9        ;(at your option) any later version.
     10        ;
     11        ;This program is distributed in the hope that it will be useful,
     12        ;but WITHOUT ANY WARRANTY; without even the implied warranty of
     13        ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14        ;GNU General Public License for more details.
     15        ;
     16        ;You should have received a copy of the GNU General Public License along
     17        ;with this program; if not, write to the Free Software Foundation, Inc.,
     18        ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     19        ;
     20        Q
     21        ;
     22        ; This is based on C0XMAIN but experiments with a fast load for triples
     23        ; that will write directly to the fileman global
     24        ; The file 172.101 is a F2N design style for triples, which means
     25        ; that it is a Flat file with no subfiles, all fields at the root
     26        ; ... it is a "2" file solution which means all strings are stored in
     27        ; ...    strings file and pointed to by the triples file
     28        ; ... it is an N file because it has generated Node IDs instead of
     29        ; ...   DINUM which would use the IEN for the Node ID.
     30        ; gpl 11/04/2011
     31        ;
     32INITFARY(ZFARY) ; INITIALIZE FILE NUMBERS AND OTHER USEFUL THINGS
     33        ; FOR THE DEFAULT TRIPLE STORE. USE OTHER VALUES FOR SUPPORTING ADDITIONAL
     34        ; TRIPLE STORES
     35        I $D(@ZFARY) Q  ; ALREADY INITIALIZED
     36        S @ZFARY@("C0XTFN")=172.101 ; TRIPLES FILE NUMBER
     37        S @ZFARY@("C0XSFN")=172.201 ; TRIPLES STRINGS FILE NUMBER
     38        S @ZFARY@("C0XTN")=$NA(^C0X(101)) ; TRIPLES GLOBAL NAME
     39        S @ZFARY@("C0XSN")=$NA(^C0X(201)) ; STRING FILE GLOBAL NAME
     40        S @ZFARY@("C0XDIR")="/home/glilly/fmts/trunk/samples/smart-new/"
     41        S @ZFARY@("BLKLOAD")=1 ; this file supports block load
     42        S @ZFARY@("FMTSSTYLE")="F2N" ; fileman style
     43        S @ZFARY@("REPLYFMT")="JSON"
     44        D USEFARY(ZFARY)
     45        Q
     46        ;
     47USEFARY(ZFARY)  ; INITIALIZES VARIABLES SAVED IN ARRAY ZFARY
     48        N ZI S ZI=""
     49        F  S ZI=$O(@ZFARY@(ZI)) Q:ZI=""  D 
     50        . ;N ZX
     51        . S ZX="S "_ZI_"="""_@ZFARY@(ZI)_""""
     52        . ;W !,ZX
     53        . X ZX
     54        Q
     55        ;
     56FILEIN  ; INTERACTIVE ENTRY POINT FOR OPTION TO READ IN A FILE
     57        I '$D(C0XFARY) D INITFARY("C0XFARY")
     58        D USEFARY("C0XFARY")
     59        S DIR(0)="F^3:240"
     60        S DIR("A")="File Directory"
     61        S DIR("B")=C0XDIR
     62        D ^DIR
     63        I Y="^" Q  ;
     64        S C0XDIR=Y
     65        S C0XFARY("C0XDIR")=Y
     66        S DIR(0)="F^3:240"
     67        S DIR("A")="File Name"
     68        I '$D(C0XFN) S DIR("B")="qds.rdf"
     69        E  S DIR("B")=C0XFN
     70        D ^DIR
     71        I Y="" Q  ;
     72        I Y="^" Q  ;
     73        S C0XFN=Y
     74        D IMPORT(C0XFN,C0XDIR,,"C0XFARY")
     75        K C0XFDA
     76        Q
     77        ;
     78IMPORT(FNAME,INDIR,INURL,FARY)  ; EXTRINSIC THAT READS A FILE FROM THE STANDARD
     79        ; DIRECTORY, LOADS IT INTO THE TRIPLESTORE AS TEXT, AND RETURNS THE
     80        ; NODE NAME OF THE TEXT TRIPLE
     81        ; INDIR IS THE OPTIONAL DIRECTORY (DEFAUTS TO STANDARD DIR)
     82        ; INURL IS THE OPTIONAL URI FOR ACCESSING THE FILE FROM THE TRIPLE STORE
     83        ; FARY IS THE OPTIONAL FILE ARRAY OF THE TRIPLE STORE TO USE
     84        I '$D(FARY) D  ;
     85        . D INITFARY("C0XFARY")
     86        . S FARY="C0XFARY"
     87        D USEFARY(FARY)
     88        N ZD,ZTMP
     89        I '$D(INDIR) S INDIR=C0XDIR ; DIRECTORY OF THE RDF FILE
     90        I $G(INURL)="" D  ;
     91        . ;N ZN2 S ZN2=$P(FNAME,".",1)_"_"_$P(FNAME,".",2) ; REMOVE THE DOT
     92        . ;S INURL=FDIR_ZN2
     93        . S INURL=INDIR_FNAME
     94        N ZTMP
     95        S ZTMP=$NA(^TMP("C0X",$J,"FILEIN",1)) ; WHERE TO PUT THE INCOMING FILE
     96        K @ZTMP ; MAKE SURE IT'S CLEAR
     97        S C0XSTART=$$NOW^XLFDT
     98        W !,"STARTED: ",C0XSTART
     99        W !,"READING IN: ",FNAME
     100        I '$$FILEREAD(ZTMP,INDIR,FNAME,4) D  Q  ; QUIT IF NO SUCCESS
     101        . W !,"ERROR READING FILE: ",INDIR,FNAME
     102        S ZRDF=$NA(^TMP("C0X",$J,"FILEIN")) ; WITHOUT THE SUBSCRIPT
     103        W !,$O(@ZRDF@(""),-1)," LINES READ"
     104        D INSRDF(ZRDF,INURL,FARY) ; IMPORT AND PROCESS THE RDF
     105        K INURL
     106        K C0XFDA
     107        ;K ^TMP("MXMLDOM",$J)
     108        Q
     109        ;
     110WGET(ZURL,FARY) ; GET FROM THE INTERNET AN RDF FILE AND INSERT IT
     111        ;
     112        I '$D(FARY) D  ;
     113        . D INITFARY("C0XFARY")
     114        . S FARY="C0XFARY"
     115        D USEFARY(FARY)
     116        ;N ZLOC,ZTMP
     117        K ZTMP
     118        S ZLOC=$NA(^TMP("C0X","WGET",$J))
     119        K @ZLOC
     120        S C0XSTART=$$NOW^XLFDT
     121        W !,"STARTED: ",C0XSTART
     122        W !,"DOWNLOADING: ",ZURL
     123        S OK=$$httpGET^%zewdGTM(ZURL,.ZTMP)
     124        M @ZLOC=ZTMP
     125        S C0XLINES=$O(@ZLOC@(""),-1)
     126        W !,C0XLINES," LINES READ"
     127        S C0XDLC=$$NOW^XLFDT ; DOWNLOAD COMPLETE
     128        W !,"DOWNLOAD COMPLETE AT ",C0XDLC
     129        S C0XDIFF=$$FMDIFF^XLFDT(C0XDLC,C0XSTART,2)
     130        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     131        I C0XDIFF'=0  W !," APPROXIMATELY ",$P(C0XLINES/C0XDIFF,".")," LINES PER SEC"
     132        D INSRDF(ZLOC,ZURL,FARY)
     133        Q
     134        ;
     135INSRDF(ZRDF,ZNAME,FARY) ; INSERT AN RDF FILE INTO THE STORE AND PROCESS
     136        ; ZRDF IS PASSED BY NAME
     137        I '$D(FARY) D  ;
     138        . D INITFARY("C0XFARY")
     139        . S FARY="C0XFARY"
     140        D USEFARY(FARY)
     141        S BATCNT=0 ; BATCH COUNTER
     142        S BATMAX=10000 ; TRY BATCHES OF THIS SIZE
     143        N ZGRAPH,ZSUBJECT
     144        S ZGRAPH="_:G"_$$LKY9 ; RANDOM GRAPH NAME
     145        S ZSUBJECT=$$ANONS() ; RANDOM ANOYMOUS SUBJECT
     146        D ADD(ZGRAPH,ZSUBJECT,"fmts:url",ZNAME,FARY)
     147        N ZTXTNM
     148        S ZTXTNM="_TXT_INCOMING_RDF_FILE_"_ZNAME_"_"_$$LKY9 ; NAME FOR TEXT NODE
     149        D ADD(ZGRAPH,ZSUBJECT,"fmts:fileSource",ZTXTNM,FARY)
     150        D ADD(ZGRAPH,ZSUBJECT,"fmts:fileTag",$$name2tag(ZNAME),FARY)
     151        D SWUPDIE(.C0XFDA) ; TRY IT OUT
     152        K C0XCNT ;RESET FOR NEXT TIME
     153        D STORETXT(ZRDF,ZTXTNM,FARY)
     154        W !,"ADDED: ",ZGRAPH," ",ZSUBJECT," fmts:fileSource ",ZTXTNM
     155        D PROCESS(.G,ZRDF,ZNAME,ZGRAPH,FARY) ; PARSE AND INSERT THE RDF
     156        Q
     157        ;
     158name2tag(zname) ; extrinsic which returns a tag derived from a name
     159        ; /home/vista/project.xml ==> project
     160        q $p($re($p($re(zname),"/")),".")
     161        ;
     162STORETXT(ZTXT,ZNAME,FARY)       ; STORE TEXT IN THE TRIPLESTORE AT ZNAME
     163        ;
     164        I '$D(FARY) D  ;
     165        . D INITFARY("C0XFARY")
     166        . S FARY="C0XFARY"
     167        D USEFARY(FARY)
     168        N ZIEN
     169        S ZIEN=$$IENOF(ZNAME,FARY) ; GET THE IEN
     170        D CLEAN^DILF
     171        K ZERR
     172        D WP^DIE(C0XSFN,ZIEN_",",1,,ZTXT,"ZERR")
     173        I $D(ZERR) D  Q  ;
     174        . W !,"ERROR CREATING WORD PROCESSING FIELD"
     175        . S C0XERR="ERROR CREATING WORD PROCESSING FIELD"
     176        . D ^%ZTER ; error trap
     177        Q
     178        ;
     179GETTXT(ZRTN,ZNAME,FARY) ; RETURNS RDF SOURCE OR OTHER TEXT
     180        ; ZRTN IS PASSED BY REFERENCE
     181        I '$D(FARY) D  ;
     182        . D INITFARY("C0XFARY")
     183        . S FARY="C0XFARY"
     184        D USEFARY(FARY)
     185        N ZIEN
     186        S ZIEN=$$IENOF(ZNAME)
     187        S OK=$$GET1^DIQ(C0XSFN,ZIEN_",",1,,"ZRTN")
     188        Q
     189        ;
     190WHERETXT(ZNAME,FARY)    ; EXTRINSIC WHICH RETURNS THE NAME OF THE GLOBAL
     191        ; WHERE THE TEXT IS LOCATED. NAME IS THE NAME OF THE STRING
     192        I '$D(FARY) D  ;
     193        . D INITFARY("C0XFARY")
     194        . S FARY="C0XFARY"
     195        D USEFARY(FARY)
     196        N ZIEN
     197        S ZIEN=$$IENOF(ZNAME)
     198        Q $NA(@C0XSN@(ZIEN,1))
     199        ;
     200FILEREAD(ZINTMP,ZDIR,ZFNAME,ZLVL)       ; READS A FILE INTO ZINTMP USING FTG^%ZISH
     201        ; ZINTMP IS PASSED BY NAME AND INCLUDES THE NEW SUBSCRIPT
     202        ; IE ^TMP("C0X","FILEIN",1)
     203        ; ZLVL IN THIS CASE WOULD BE 3 INCREMENTING THE 1
     204        ; EXTRINSIC WHICH RETURNS THE RESULT OF FTG^%ZISH
     205        S OK=$$FTG^%ZISH(ZDIR,FNAME,ZINTMP,ZLVL)
     206        Q OK
     207        ;
     208TESTPROC        ; TEST PROCESS WITH EXISTING SMALL RDF FILE
     209        S ZIN=$NA(^TMP("C0X",12226,"FILEIN"))
     210        S ZGRAPH="/test/rdfFile"
     211        S ZM="/test/rdfFile/meta"
     212        D PROCESS(.G,ZIN,ZGRAPH,ZM)
     213        Q
     214        ;
     215VISTAOWL        ;
     216        S ZRDF=$NA(^TMP("C0X",542,"FILEIN"))
     217        S ZNAME="/home/glilly/vistaowl/VistAOWL.owl"
     218        S ZGRAPH="_:G431590209"
     219        S FARY="C0XFARY"
     220        D INITFARY(FARY)
     221        S C0XDOCID=1
     222        S BATCNT=0
     223        S BATMAX=10000
     224        D PROCESS(.G,ZRDF,ZGRAPH,ZNAME,FARY)
     225        Q
     226        ;
     227PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY)      ; PROCESS AN INCOMING RDF FILE
     228        ; ZRTN IS PASS BY REFERENCE AND RETURNS MESSAGES ABOUT THE PROCESSING
     229        ; ZRDF IS PASSED BY NAME AND IS THE GLOBAL CONTAINING THE RDF FILE
     230        ; ZGRF IS THE NAME OF THE GRAPH TO USE IN THE TRIPLE STORE FOR RESULTS
     231        ; ZMETA IS OPTIONAL AND IS THE NAME OF THE GRAPH TO STORE METADATA
     232        ;
     233        I '$D(FARY) D  ;
     234        . D INITFARY("C0XFARY")
     235        . S FARY="C0XFARY"
     236        D USEFARY(FARY)
     237        ;N BATCNT
     238        ;N BATMAX
     239        ; -- first parse the rdf file with the MXML parser
     240        ;S C0XDOCID=$$PARSE^C0CNHIN(ZRDF,"C0XARRAY") ; PARSE WITH MXML
     241        S C0XDLC2=$$NOW^XLFDT ; START OF PARSE
     242        I @ZRDF@(1)'["<?xml" D  Q  ;
     243        . K @ZRDF ; don't need the input buffer
     244        . W !,"Not an XML file"
     245        S C0XDOCID=$$EN^MXMLDOM(ZRDF,"W") ;
     246        ;B
     247        K @ZRDF ; DON'T NEED INPUT BUFFER ANYMORE
     248        ; -- assign the MXLM dom global name to ZDOM
     249        S ZDOM=$NA(^TMP("MXMLDOM",$J,C0XDOCID))
     250        ;S ZDOM=$NA(^TMP("MXMLDOM",16850,C0XDOCID)) ;VISTAOWL DOM
     251        S C0XNODE=$O(@ZDOM@(""),-1)
     252        W !,C0XNODE," XML NODES PARSED"
     253        S C0XPRS=$$NOW^XLFDT ; PARSE COMPLETE
     254        W !,"PARSE COMPLETE AT ",C0XPRS
     255        S C0XDIFF=$$FMDIFF^XLFDT(C0XPRS,C0XDLC2,2)
     256        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     257        I C0XDIFF'=0 D  ;
     258        . W !," APPROXIMATELY ",$P(C0XNODE/C0XDIFF,".")," NODES PER SECOND"
     259        ; -- populate the metagraph to point to the graph with status unfinished
     260        S METAS=$$ANONS ; GET AN ANONOMOUS RANDOM SUBJECT
     261        I '$D(ZMETA) S ZMETA="_:G"_$$LKY9 ; RANDOM GRAPH NAME FOR METAGRAPH
     262        D ADD(ZMETA,METAS,"fmts:about",ZGRF,FARY) ; POINT THE META TO THE GRAPH
     263        D ADD(ZMETA,METAS,"fmts:status","unfinished",FARY) ; mark as unfinished
     264        W !,"INSERTING GRAPH: ",ZGRF
     265        ;S C0XDATE=$$FMDTOUTC^C0CUTIL($$NOW^XLFDT,"DT")
     266        S C0XDATE=$$NOW^XLFDT
     267        D ADD(ZMETA,METAS,"fmts:dateTime",C0XDATE,FARY)
     268        D SWUPDIE(.C0XFDA) ; commit the metagraph changes to the triple store
     269        ; --
     270        ; -- pull out the vocabularies in the RDF statement. marked with xmlns:
     271        ; -- put them in a local variable for quick reference
     272        ; -- TODO: create a graph for vocabularies and validate incoming against it
     273        ;
     274        S C0XVOC=""
     275        N ZI,ZJ,ZK S ZI=""
     276        F  S ZI=$O(@ZDOM@(1,"A",ZI)) Q:ZI=""  D  ; FOR EACH xmlns
     277        . S ZVOC=$P(ZI,"xmlns:",2)
     278        . I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))
     279        I $D(DEBUG) D  ;
     280        . W !,"VOCABS:"
     281        . N ZZ S ZZ=""
     282        . F  S ZZ=$O(C0XVOC(ZZ)) Q:ZZ=""  W !,ZZ,":",C0XVOC(ZZ)
     283        ;
     284        ; -- look for children called rdf:Description. quit if none. not an rdf file
     285        ;
     286        S C0XTYPE("rdf:Description")=1
     287        S C0XTYPE("owl:ObjectProperty")=1
     288        S C0XTYPE("owl:Ontology")=1
     289        S C0XTYPE("owl:Class")=1
     290        S C0XTYPE("rdfs:subClassOf")=1
     291        S C0XTYPE("rdf:RDF")=1
     292        S ZI=$O(@ZDOM@(1,"C",""))
     293        I '$G(C0XTYPE(@ZDOM@(1,"C",ZI))) D  ;Q  ; not an rdf file
     294        . W !,"Unusual RDF file ",@ZDOM@(1,"C",ZI)
     295        . ;W !,"Error. Not an RDF file. Cannot process."
     296        . D SHOW(1)
     297        ;
     298        ; -- now process the rdf description children
     299        ;
     300        S ZI=""
     301        S (C0XSUB,C0XPRE,C0XOBJ)="" ; INITIALIZE subject, object and predicate
     302        F  S ZI=$O(@ZDOM@(1,"C",ZI)) Q:ZI=""  D  ;
     303        . ; -- we are skipping any child that is not rdf:Description
     304        . ; -- TODO: check to see if this is right in general
     305        . ;
     306        . IF '$G(C0XTYPE(@ZDOM@(1,"C",ZI))) D  Q  ;
     307        . . W !,"SKIPPING NODE: ",ZI
     308        . ; -- now looking for the subject for the triples
     309        . S ZX=$G(@ZDOM@(ZI,"A","rdf:about"))
     310        . I ZX'="" D  ; we have the subject
     311        . . ;W " about: ",ZX
     312        . . S C0XSUB=ZX
     313        . E  D  ;
     314        . . S ZX=$G(@ZDOM@(ZI,"A","rdf:nodeID")) ; node id is another style of subject
     315        . . I ZX'="" D  ;
     316        . . . S C0XSUB=ZX
     317        . I C0XSUB="" S C0XSUB=$$ANONS ; DEFAULT TO BLANK SUBJECT
     318        . ;
     319        . ; -- we now have the subject. the children of this node have the rest
     320        . ;
     321        . S ZJ="" ; for the children of the rdf:Description nodes
     322        . F  S ZJ=$O(@ZDOM@(ZI,"C",ZJ)) Q:ZJ=""  D  ; for each child
     323        . . S C0XPRE=@ZDOM@(ZJ) ; the predicate without a prefix
     324        . . S ZX=$G(@ZDOM@(ZJ,"A","xmlns")) ; name space
     325        . . I ZX'="" S C0XPRE=ZX_C0XPRE ; add the namespace prefix
     326        . . I C0XPRE[":" D  ; expand using vocabulary
     327        . . . N ZB,ZA
     328        . . . S ZB=$P(C0XPRE,":",1)
     329        . . . S ZA=$P(C0XPRE,":",2)
     330        . . . I $G(C0XVOC(ZB))'="" D  ;
     331        . . . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
     332        . . S ZY=$G(@ZDOM@(ZJ,"A","rdf:resource")) ; potential object
     333        . . I ZY'="" D  Q ;
     334        . . . S C0XOBJ=$$EXT^C0XUTIL(ZY) ; object
     335        . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; finally. our first real triple
     336        . . ; -- this is an else because of the quit above
     337        . . S ZX=$G(@ZDOM@(ZJ,"A","rdf:nodeID")) ; fishing for nodeId object
     338        . . I ZX'="" D  Q  ; got one
     339        . . . S C0XOBJ=ZX ; we are using the incoming nodeIDs as object/subject
     340        . . . ; without change... this could be foolish .. look at it again later
     341        . . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
     342        . . S C0XOBJ=$G(@ZDOM@(ZJ,"T",1)) ; hopefully an object is here
     343        . . I C0XOBJ="" D  Q  ; not a happy situation
     344        . . . W !,"ERROR, NO OBJECT FOUND FOR NODE: ",ZJ
     345        . . S C0XOBJ=$$EXT^C0XUTIL(C0XOBJ) ; might be namespaced
     346        . . D ADD(ZGRF,C0XSUB,C0XPRE,C0XOBJ) ; go for it and add a node
     347        S C0XTRP=$$NOW^XLFDT ; PARSE COMPLETE
     348        W !,"TRIPLES COMPLETE AT ",C0XTRP
     349        S C0XDIFF=$$FMDIFF^XLFDT(C0XTRP,C0XPRS,2)
     350        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     351        I C0XDIFF'=0 D  ;
     352        . W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
     353        W !,"INSERTING ",C0XCNT," TRIPLES"
     354        I $D(C0XFDA) D  ;
     355        . I $G(BLKLOAD) D  ;
     356        . . D BULKLOAD(.C0XFDA)
     357        . E  D  ;
     358        . . D UPDIE(.C0XFDA) ; commit the updates to the file
     359        ; next, mark the graph as finished
     360        S C0XINS=$$NOW^XLFDT ; PARSE COMPLETE
     361        W !,"INSERTION COMPLETE AT ",C0XPRS
     362        S C0XDIFF=$$FMDIFF^XLFDT(C0XINS,C0XTRP,2)
     363        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     364        I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," NODES PER SECOND"
     365        S C0XEND=$$NOW^XLFDT
     366        W !," ENDED AT: ",C0XEND
     367        S C0XDIFF=$$FMDIFF^XLFDT(C0XEND,C0XSTART,2)
     368        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     369        I C0XDIFF'=0 W !," APPROXIMATELY ",$P(C0XCNT/C0XDIFF,".")," TRIPLES PER SECOND"
     370        Q
     371        ;
     372SHOW(ZN)        ;
     373        I '$D(C0XJOB) S C0XJOB=$J
     374        N ZD
     375        S ZD=$NA(^TMP("MXMLDOM",C0XJOB,1,ZN))
     376        W ZD,"=",@ZD
     377        F  S ZD=$Q(@ZD) Q:$QS(ZD,4)'=ZN  W !,ZD,"=",@ZD
     378        ;ZWR ^TMP("MXMLDOM",C0XJOB,1,ZN,*)
     379        Q
     380        ;
     381ANONS() ; RETURNS AN ANONOMOUS SUBJECT
     382        Q "iDPsDPss"_$$LKY9
     383        ;
     384NEWG(NGRAPH,NMETA)      ; CREATES A NEW META GRAPH, MARKS IT AS UNFINISHED
     385        ; THEN CREATES A NEW GRAPH AND POINTS THE METAGRAPH TO IT
     386        ; NGRAPH AND NMETA ARE PASSED BY REFERENCE AND ARE THE RETURN
     387        S NGRAPH="G"_$$LKY9
     388        S NMETA=NGRAPH_"A"
     389        Q
     390        ;
     391STARTADD        ; INITIALIZE C0XFDA AND BATCNT
     392        K C0XFDA
     393        K BATCNT
     394        Q
     395        ;
     396ADD(ZG,ZS,ZP,ZO,FARY)   ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
     397        ; THE FDA IS SET UP BUT THE FILES ARE NOT UPDATED. CALL UPDIE TO COMPLETE
     398        I '$D(FARY) D  ;
     399        . D INITFARY("C0XFARY")
     400        . S FARY="C0XFARY"
     401        D USEFARY(FARY)
     402        I '$D(C0XCNT) S C0XCNT=0
     403        N ZNODE
     404        S ZNODE="N"_$$LKY17
     405        N ZNARY ; GET READY TO CALL IENOFA
     406        I (ZG="")!(ZS="")!(ZP="")!(ZO="") D  Q  ;
     407        . I $G(DEBUG) W !,"Error Empty String ZG:"_ZG_" ZS:"_ZS_" ZP:"_ZP_" ZO"_ZO
     408        S ZNARY("ZG",ZG)=""
     409        S ZNARY("ZS",ZS)=""
     410        S ZNARY("ZP",ZP)=""
     411        S ZNARY("ZO",ZO)=""
     412        D IENOFA(.ZIENS,.ZNARY,FARY) ; RESOLVE/ADD STRINGS
     413        ;S ZGIEN=$$IENOF(ZG) ; LAYGO TO GET IEN
     414        ;S ZSIEN=$$IENOF(ZS)
     415        ;S ZPIEN=$$IENOF(ZP)
     416        ;S ZOIEN=$$IENOF(ZO)
     417        ;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED
     418        I '$D(BATCNT) S BATCNT=0
     419        S BATCNT=BATCNT+1
     420        S C0XCNT=C0XCNT+1
     421        I $G(BLKLOAD)=1 D  ; we are using bulk load
     422        . S C0XFDA(C0XTFN,BATCNT,.01)=ZNODE
     423        . S C0XFDA(C0XTFN,BATCNT,.02)=$O(ZIENS("IEN","ZG",""))
     424        . S C0XFDA(C0XTFN,BATCNT,.03)=$O(ZIENS("IEN","ZS",""))
     425        . S C0XFDA(C0XTFN,BATCNT,.04)=$O(ZIENS("IEN","ZP",""))
     426        . S C0XFDA(C0XTFN,BATCNT,.05)=$O(ZIENS("IEN","ZO",""))
     427        E  D  ;
     428        . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.01)=ZNODE
     429        . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.02)=$O(ZIENS("IEN","ZG",""))
     430        . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.03)=$O(ZIENS("IEN","ZS",""))
     431        . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.04)=$O(ZIENS("IEN","ZP",""))
     432        . S C0XFDA(C0XTFN,"?+"_BATCNT_",",.05)=$O(ZIENS("IEN","ZO",""))
     433        I '$D(BATMAX) S BATMAX=10000
     434        I BATCNT=BATMAX D  ; BATCH IS DONE
     435        . I $G(BLKLOAD) D  ; bulk load
     436        . . D BULKLOAD(.C0XFDA) ; bulk load the batch
     437        . E  D  ; no bulk load
     438        . . D UPDIE(.C0XFDA)
     439        . K C0XFDA
     440        . S BATCNT=0 ; RESET COUNTER
     441        ; REMEMBER TO CALL UPDIE WHEN YOU'RE DONE
     442        Q
     443        ;
     444LKY5()  ;EXTRINIC THAT RETURNS A RANDOM 5 DIGIT NUMBER. USED FOR GENERATING
     445        ; UNIQUE NODE AND GRAPH NAMES
     446        N ZN,ZI
     447        S ZN=""
     448        F ZI=1:1:5 D  ;
     449        . S ZN=ZN_$R(10)
     450        Q ZN
     451        ;
     452LKY9()  ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
     453        ; UNIQUE NODE AND GRAPH NAMES
     454        N ZN,ZI
     455        S ZN=""
     456        F ZI=1:1:9 D  ;
     457        . S ZN=ZN_$R(10)
     458        Q ZN
     459        ;
     460LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
     461        ; UNIQUE NODE AND GRAPH NAMES
     462        N ZN,ZI
     463        S ZN=""
     464        F ZI=1:1:17 D  ;
     465        . S ZN=ZN_$R(10)
     466        Q ZN
     467        ;
     468        ; these routines add the string if it is not found
     469        ;
     470IENOF(ZSTRING,FARY)     ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
     471        I '$D(FARY) D  ;
     472        . D INITFARY("C0XFARY")
     473        . S FARY="C0XFARY"
     474        N ZIEN
     475        I $G(ZSTRING)="" Q "" ; NO STRING
     476        S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
     477        I ZIEN="" D  ;
     478        . S C0XFDA2(C0XSFN,"+1,",.01)=ZSTRING
     479        . D UPDIE(.C0XFDA2)
     480        . S ZIEN=$O(@C0XSN@("B",ZSTRING,""))
     481        . K C0XFDA2
     482        Q ZIEN
     483        ;
     484IENOFA(ZOUTARY,INARY,FARY)      ; RESOLVE STRINGS TO IEN IN STRINGS FILE
     485        ; OR ADD THEM IF
     486        ; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE
     487        ; ZINARY LOOKS LIKE ZINARY("VAR","VAL")=""
     488        ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)=""
     489        I '$D(FARY) D  ;
     490        . D INITFARY("C0XFARY")
     491        . S FARY="C0XFARY"
     492        K ZOUTARY ; START WITH CLEAN RESULTS
     493        K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
     494        I '$D(C0XVOC) D VOCINIT^C0XUTIL
     495        N ZINARY
     496        N ZI S ZI=""
     497        F  S ZI=$O(INARY(ZI)) Q:ZI=""  D  ;
     498        . N ZK
     499        . S ZK=$O(INARY(ZI,""))
     500        . S ZINARY($$EXT^C0XUTIL(ZI),$$EXT^C0XUTIL(ZK))=""
     501        N ZV,ZIEN,ABORT
     502        S ABORT=0
     503        N ZCNT S ZCNT=0
     504        F  S ZI=$O(ZINARY(ZI)) Q:(ZI="")!+ABORT  D  ; LOOK FOR MISSING STRINGS
     505        . S ZV=$O(ZINARY(ZI,""))
     506        . I ZV="" S ABORT=1 Q  ; abandon quad -- missing an entry
     507        . I ZV["^" S ZV=$TR(ZV,"^","|")
     508        . I $O(@C0XSN@("B",ZV,""))="" D  ;
     509        . . S ZCNT=ZCNT+1
     510        . . S C0XFDA2(C0XSFN,"+"_ZCNT_",",.01)=ZV
     511        I +ABORT Q  ;
     512        I $D(C0XFDA2) D  ;
     513        . D UPDIE(.C0XFDA2) ; ADD MISSING STRINGS
     514        . K C0XFDA2 ; CLEAN UP
     515        F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; NOW GET ALL IENS
     516        . S ZV=$O(ZINARY(ZI,""))
     517        . I ZV["^" S ZV=$TR(ZV,"^","|")
     518        . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW
     519        . I ZIEN="" D  ;
     520        . . W !,"ERROR ADDING STRING: ",ZV
     521        . . B
     522        . S ZOUTARY("IEN",ZI,ZIEN)=""
     523        Q
     524        ;
     525ADDINN(ZG,ZS,ZARY)      ; ADD IF NOT NULL
     526        ; ZG IS THE GRAPH NAME, PASSED BY VALUE
     527        ; ZS IS THE SUBJECT, PASSED BY VALUE
     528        ; ZARY IS AN ARRAY, PASSED BY REFERENCE OF THE PREDICATE AND OBJECT
     529        ;  FORMAT IS ZARY(PRED)=OBJ
     530        N ZI S ZI=""
     531        F  S ZI=$O(ZARY(ZI)) Q:ZI=""  D  ;
     532        . ;I ZARY(ZI)="" S ZARY(ZI)="NULL"
     533        . I ZARY(ZI)'="" D  ;
     534        . . D ADD^C0XF2N(ZG,ZS,ZI,ZARY(ZI))
     535        . . I $D(DEBUG) W !,"ADDING",ZI," ",ZARY(ZI)
     536        ;ZWR ZARY
     537        Q
     538        ;
     539BULKLOAD(ZBFDA) ; BULK LOADER FOR LOADING TRIPLES INTO FILE 172.101
     540        ; USING GLOBAL SETS INSTEAD OF UPDATE^DIE
     541        ; QUITS IF FILE IS NOT 172.101
     542        ; EXPECTS AN FDA WITHOUT STRINGS FOR THE IENS, STARTING AT 1
     543        ; QUITS IF FIRST ENTRY IS NOT IENS 1
     544        ; ASSUMES THAT THE LAST IENS IS THE COUNT OF ENTRIES
     545        ; ZBFDA IS PASSED BY REFERENCE
     546        ;
     547        ; -- reserves a block of iens from file 172.101 by locking the zero node
     548        ; -- ^C0X(101,0) and adding the count of entries to piece 2 and 3
     549        ; -- then unlocking to minimize the duration of the lock
     550        ;
     551        I $D(DEBUG) W !,"USING BULKLOAD"
     552        I '$D(ZBFDA) Q  ; EMPTY FDA
     553        I $O(ZBFDA(""))'=172.101 Q  ; WRONG FILE
     554        N ZCNT,ZP3,ZP4
     555        ; -- find the number of nodes to insert
     556        S ZCNT=$O(ZBFDA(172.101,""),-1)
     557        I ZCNT="" D  Q  ;
     558        . W !,"ERROR IN BULK LOAD - INVALID NODE COUNT"
     559        . B
     560        ; -- lock the zero node and reserve a block of iens to insert
     561        I $D(DEBUG) W !,"LOCKING ZERO NODE"
     562        LOCK +^C0X(101,0)
     563        S ZP3=$P(^C0X(101,0),U,3)
     564        S ZP4=$P(^C0X(101,0),U,4)
     565        S $P(^C0X(101,0),U,3)=ZP3+ZCNT+1
     566        S $P(^C0X(101,0),U,4)=ZP4+ZCNT+1
     567        LOCK -^C0X(101,0)
     568        N ZI,ZN,ZG,ZS,ZP,ZO,ZIEN,ZBASE
     569        S ZBASE=ZP3 ; the last ien in the file
     570        I $D(DEBUG) W !,"ZERO NODE UNLOCKED, IENS RESERVED=",ZCNT
     571        I $D(DEBUG) W !,$$NOW^XLFDT
     572        S ZI=""
     573        F  S ZI=$O(ZBFDA(172.101,ZI)) Q:ZI=""  D  ;
     574        . S ZN=$G(ZBFDA(172.101,ZI,.01)) ; node name
     575        . I ZN="" D BLKERR Q  ;
     576        . S ZG=$G(ZBFDA(172.101,ZI,.02)) ; graph pointer
     577        . I ZG="" D BLKERR Q  ;
     578        . S ZS=$G(ZBFDA(172.101,ZI,.03)) ; subject pointer
     579        . I ZS="" D BLKERR Q  ;
     580        . S ZP=$G(ZBFDA(172.101,ZI,.04)) ; predicate pointer
     581        . I ZP="" D BLKERR Q  ;
     582        . S ZO=$G(ZBFDA(172.101,ZI,.05)) ; object pointer
     583        . I ZO="" D BLKERR Q  ;
     584        . S ZIEN=ZI+ZBASE ; the new ien
     585        . S ^C0X(101,ZIEN,0)=ZN_U_ZG_U_ZS_U_ZP_U_ZO ; set the zero node
     586        . D INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO)
     587        Q
     588        ;
     589INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO)      ; HARD SET THE INDEX FOR ONE ENTRY
     590        S ^C0X(101,"B",ZN,ZIEN)="" ; the B index
     591        S ^C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index
     592        S ^C0X(101,"SPO",ZS,ZP,ZO,ZIEN)=""
     593        S ^C0X(101,"SOP",ZS,ZO,ZP,ZIEN)=""
     594        S ^C0X(101,"OPS",ZO,ZP,ZS,ZIEN)=""
     595        S ^C0X(101,"OSP",ZO,ZS,ZP,ZIEN)=""
     596        S ^C0X(101,"PSO",ZP,ZS,ZO,ZIEN)=""
     597        S ^C0X(101,"POS",ZP,ZO,ZS,ZIEN)=""
     598        S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS,ZIEN)=""
     599        S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP,ZIEN)=""
     600        S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO,ZIEN)=""
     601        S ^C0X(101,"GPOS",ZG,ZP,ZO,ZS,ZIEN)=""
     602        S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO,ZIEN)=""
     603        S ^C0X(101,"GSOP",ZG,ZS,ZO,ZP,ZIEN)=""
     604        Q
     605        ;
     606REINDEX ; REINDEX THE ^C0X(101, TRIPLE STORE
     607        K ^C0X(101,"B")
     608        K ^C0X(101,"G")
     609        K ^C0X(101,"SPO")
     610        K ^C0X(101,"SOP")
     611        K ^C0X(101,"OPS")
     612        K ^C0X(101,"OSP")
     613        K ^C0X(101,"PSO")
     614        K ^C0X(101,"POS")
     615        K ^C0X(101,"GOPS")
     616        K ^C0X(101,"GOSP")
     617        K ^C0X(101,"GPSO")
     618        K ^C0X(101,"GPOS")
     619        K ^C0X(101,"GSPO")
     620        K ^C0X(101,"GSOP")
     621        N ZIEN,ZZ
     622        S ZIEN=0
     623        F  S ZIEN=$O(^C0X(101,ZIEN)) Q:+ZIEN=0  D  ; FOR EACH NODE
     624        . S ZZ=$G(^C0X(101,ZIEN,0))
     625        . I ZZ="" D  Q  ;
     626        . . W !,"ERROR REINDEXING NODE ",ZI
     627        . S ZN=$P(ZZ,"^",1)
     628        . S ZG=$P(ZZ,"^",2)
     629        . S ZS=$P(ZZ,"^",3)
     630        . S ZP=$P(ZZ,"^",4)
     631        . S ZO=$P(ZZ,"^",5)
     632        . D INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO)
     633        Q
     634        ;
     635BLKERR  ;
     636        W !,"ERROR IN BULK LOAD"
     637        S C0XERR="ERROR IN BULK LOAD"
     638        S C0XLOC=ZBFDA(ZI)
     639        D ^%ZTER ; report the error
     640        B
     641        Q
     642        ;
     643DELGRAPH(ZGRF,FARY)     ; delete a graph from the triplestore
     644        ; (doesn't delete strings)
     645        ;
     646        I '$D(FARY) D  ;
     647        . D INITFARY("C0XFARY")
     648        . S FARY="C0XFARY"
     649        D USEFARY(FARY)
     650        N ZGRAPH
     651        D TING(.ZGRAPH,ZGRF,FARY)
     652        I '$D(ZGRAPH) D  Q  ;
     653        . I $D(DEBUG) W !,"NO TRIPLES IN GRAPH"
     654        K C0XFDA
     655        N ZI S ZI=""
     656        F  S ZI=$O(ZGRAPH(ZI)) Q:ZI=""  D  ;
     657        . S C0XFDA(C0XTFN,ZI_",",.01)="@"
     658        D UPDIE(.C0XFDA)
     659        Q
     660        ;
     661TING(ZRTN,ZGRF,FARY)    ; return the iens for graph ZGRF
     662        ; ZRTN is passed by reference
     663        I '$D(FARY) D  ;
     664        . D INITFARY("C0XFARY")
     665        . S FARY="C0XFARY"
     666        D USEFARY(FARY)
     667        K ZRTN
     668        N ZI,ZG S ZI=""
     669        S ZG=$$IENOF^C0XGET1(ZGRF)
     670        I ZG="" D  Q  ;
     671        . I $D(DEBUG) W !,"ERROR GRAPH NOT FOUND"
     672        I '$D(@C0XTN@("G",ZG)) Q  ;
     673        F  S ZI=$O(@C0XTN@("G",ZG,ZI)) Q:ZI=""  D  ;
     674        . S ZRTN(ZI)=""
     675        Q
     676       
     677SWUPDIE(ZFDA)   ; SWITCH BETWEEN UPDIE AND BULKLOAD
     678        I $G(BLKLOAD)=1 D  ; bulk load
     679        . D BULKLOAD(.ZFDA) ; bulk load the batch
     680        E  D  ; no bulk load
     681        . D UPDIE(.ZFDA)
     682        K ZFDA
     683        Q
     684        ;
     685UPDIE(ZFDA)     ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
     686        ; ZFDA IS PASSED BY REFERENCE
     687        ;ZWR ZFDA
     688        ;B
     689        K ZERR
     690        D CLEAN^DILF
     691        D UPDATE^DIE("","ZFDA","","ZERR")
     692        I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST,
     693        ; INVOKE THE ERROR TRAP IF TASKED
     694        ;. W "ERROR",!
     695        ;. ZWR ZERR
     696        ;. B
     697        K ZFDA
     698        Q
     699        ;
  • fmts/trunk/p/C0XGET1.m

    r1532 r1539  
    1 C0XGET1 ; GPL - Fileman Triples entry point routine ;1/12/12  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    4  ;General Public License See attached copy of the License.
    5  ;
    6  ;This program is free software; you can redistribute it and/or modify
    7  ;it under the terms of the GNU General Public License as published by
    8  ;the Free Software Foundation; either version 2 of the License, or
    9  ;(at your option) any later version.
    10  ;
    11  ;This program is distributed in the hope that it will be useful,
    12  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  ;GNU General Public License for more details.
    15  ;
    16  ;You should have received a copy of the GNU General Public License along
    17  ;with this program; if not, write to the Free Software Foundation, Inc.,
    18  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    19  ;
    20  Q
    21  ;
    22 LSSUBJ(RTN,ZSUBJ,C0XFARY) ; LIST NODES WITH SUBJECT ZSUBJ
    23  ;
    24  I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
    25  D USEFARY^C0XF2N("C0XFARY")
    26  Q
    27  ;
    28 graph(sub,pred,obj,form,fary) ; extrinsic which returns a graph name
    29  I '$D(fary) D  ;
    30  . S fary="C0XFARY"
    31  . D INITFARY^C0XF2N(fary)
    32  D USEFARY^C0XF2N(fary)
    33  k triplertn ; start with a clean return
    34  n zsub,zpred,zobj,zgraph,tmprtn
    35  s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
    36  s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of predicate
    37  s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of object
    38  s zgraph=$$IENOF($g(graph),fary) ; ien of graph
    39  I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
    40  d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
    41  n ztmp
    42  d trip(.ztmp,$g(sub),$g(pred),$g(obj),"",$g(fary))
    43  n zi,zg,zrtn
    44  s zi=$o(tmprtn(""))
    45  s zg=$$GET1^DIQ(C0XTFN,zi,.02,"E") ;
    46  i zg="" q ""
    47  s zrtn=zg
    48  i $o(tmprtn(zi))'="" d 
    49  . s zrtn=""
    50  q zrtn
    51  ;
    52 GRAPHS(RTN,C0XFARY) ; LIST ALL GRAPHS
    53  ;
    54  I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
    55  D USEFARY^C0XF2N("C0XFARY")
    56  N ZI S ZI=""
    57  F  S ZI=$O(@C0XTN@("G",ZI)) Q:ZI=""  D  ;
    58  . S RTN(ZI,$$STR(ZI))=""
    59  Q
    60  ;
    61 STR(ZIN,C0XFARY) ; EXTRINSIC RETURNS A STRING
    62  I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
    63  Q $$GET1^DIQ(C0XSFN,ZIN,.01,"E")
    64  ;
    65 SPO(ZRTN,ZNODE,C0XFARY)
    66  I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
    67  N ZI S ZI=$$NXT(.ZRTN)
    68  S ZRTN(ZI,"S")=$$S(ZNODE)
    69  S ZRTN(ZI,"P")=$$P(ZNODE)
    70  S ZRTN(ZI,"O")=$$O(ZNODE)
    71  Q
    72  ;
    73 S(ZNODE,C0XFARY) ; EXTRINSIC RETURNING THE SUBJECT
    74  Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.03,"I")) ;
    75  ;
    76 P(ZNODE,C0XFARY) ; EXTRINSIC RETURNING THE PREDICATE
    77  Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.04,"I")) ;
    78  ;
    79 O(ZNODE,C0XFARY) ; EXTRINSIC RETURNING THE OBJECT
    80  Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.05,"I")) ;
    81  ;
    82 NXT(ZRTN) ;EXTRINSIC FOR THE NEXT NODE IN ARRAY ZRTN, PASSED BY REF
    83  I '$D(ZRTN) S ZRTN=""
    84  Q $O(ZRTN(""),-1)+1
    85  ;
    86 SING(ZRTN,ZG) ; SUBJECTS IN GRAPH
    87  ;
    88  I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
    89  I '$D(ZRTN) S ZRTN=""
    90  N ZI,ZN S ZI=""
    91  F  S ZI=$O(@C0XTN@("GSPO",ZG,ZI)) Q:ZI=""  D  ;
    92  . S ZRTN($$NXT(.ZRTN),"S")=$$STR(ZI)
    93  Q
    94  ;
    95 qparse(qrtn,zquery) ; parses the query
    96  ; want this to be able to handle the WHERE clause of SPARQL eventually
    97  ;
    98  n q1,q2,q3,qq
    99  ;s qq=$tr(zquery,"  ","^")
    100  s qq=query ; really want to remove whitespace here
    101  s q1=$p(qq," ",1)
    102  i q1["?" s q1=""
    103  s q2=$p(qq," ",2)
    104  i q2["?" s q2=""
    105  s q3=$p(qq," ",3)
    106  i q3["?" s q3=""
    107  s qrtn(1)=q1_"^"_q2_"^"_q3 ; more lines to come later
    108  q
    109  ;
    110 getGraph(zrtn,zgrf,form) ; get all triples in graph zgrf
    111  ; forms planned: "rdf" "json" "array" "turtle" "triples" "raw"
    112  ; forms supported: "rdf" "json" "array" "raw"
    113  I '$D(form) S form="rdf"
    114  N ZIENS,ZTRIP
    115  D TING^C0XF2N(.ZIENS,zgrf)
    116  I '$D(ZIENS) Q  ;
    117  D ien2tary(.ZTRIP,"ZIENS")
    118  I form="json" d jsonout(.zrtn,.ZTRIP) q  ; what follows is else
    119  i form="rdf" d rdfout^C0XRDF(.zrtn,.ZTRIP) q  ;
    120  i form="array" d arrayout^C0XGET1(.zrtn,.ZTRIP) q  ;
    121  i form="raw" d rawout^C0XGET1(.zrtn,.ZTRIP) q  ;
    122  W !,"Form not supported: ",form
    123  Q
    124  ;
    125 rpctrip(rtn,query,limit,offset) ; rpc to access triples with a query
    126  ;
    127  n zoff,zlim,zcount,zq
    128  k rtn
    129  i '$d(limit) s limit=250
    130  i '$d(offset) s offset=0
    131  d qparse(.zq,query) ; parse the query
    132  n qsub,qpred,qobj,qtmp
    133  W !,zq(1)
    134  s qsub=$p(zq(1),"^",1)
    135  s qpred=$p(zq(1),"^",2)
    136  s qobj=$p(zq(1),"^",3)
    137  d triples(.qtmp,qsub,qpred,qobj)
    138  f zcount=offset+1:1:offset+limit q:'$d(qtmp(zcount))  d  ;
    139  . s rtn(zcount)=qtmp(zcount)
    140  q
    141  ;
    142 triples(triplertn,sub,pred,obj,graph,form,fary) ; returns triples
    143  I '$D(fary) D  ;
    144  . D INITFARY^C0XF2N("C0XFARY")
    145  . S fary="C0XFARY"
    146  D USEFARY^C0XF2N(fary)
    147  I '$D(form) S form="json"
    148  k triplertn ; start with a clean return
    149  n zsub,zpred,zobj,zgraph,tmprtn
    150  s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
    151  s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of predicate
    152  s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of object
    153  s zgraph=$$IENOF($g(graph),fary) ; ien of graph
    154  I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
    155  d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
    156  d ien2tary(.zrary,"tmprtn") ; convert to triples
    157  ;
    158  i form="json" d jsonout(.triplertn,.zrary) q  ; what follows is 'else'
    159  i form="rdf" d rdfout^C0XRDF(.triplertn,.zrary) q  ;
    160  i form="array" d arrayout(.triplertn,.zrary) q  ;
    161  i form="raw" d rawout(.triplertn,.zrary) q  ;
    162  w !,"form not supported: ",form
    163  q
    164  ;
    165 subjects(listrtn,pred,obj,graph,form,fary) ; return list of subjects
    166  d onelist("S",,$g(pred),$g(obj),$g(fary)) ;subjects
    167  q
    168  ;
    169 subject(pred,obj,graph,form,fary) ; extrinsic which returns the first
    170  ; multiple of return from subjects - returns null if more than one
    171  ; subjects(.G,sub,pred)
    172  ; G("nodeID:1234") ==> "nodeID:1234"
    173  n zin,zrtn
    174  d subjects(.zin,$g(pred),$g(obj),$g(form),$g(fary))
    175  s zrtn=$o(zin(""))
    176  i $o(zin(zrtn))'="" s zrtn=""
    177  q zrtn
    178  ;
    179 preds(listrtn,sub,obj,graph,form,fary) ; return list of subjects
    180  d onelist("P",$g(sub),,$g(obj),$g(fary)) ;subjects
    181  q
    182  ;
    183 objects(listrtn,sub,pred,graph,form,fary) ; return list of subjects
    184  d onelist("O",$g(sub),$g(pred),"",$g(fary)) ;subjects
    185  q
    186  ;
    187 object(sub,pred,graph,form,fary) ; extrinsic which returns the first
    188  ; multiple of return from objects - returns null if more than one
    189  ; objects(.G,sub,pred)
    190  ; G("location") ==> "location"
    191  n zin,zrtn
    192  d objects(.zin,$g(sub),$g(pred),$g(form),$g(fary))
    193  s zrtn=$o(zin(""))
    194  i $o(zin(zrtn))'="" s zrtn=""
    195  q zrtn
    196  ;
    197 onelist(zw,sub,pred,obj,fary) ; returns list
    198  ; zw is S P or O depending on what should be returned
    199  I $g(fary)="" D  ;
    200  . D INITFARY^C0XF2N("C0XFARY")
    201  . S fary="C0XFARY"
    202  D USEFARY^C0XF2N(fary)
    203  I '$D(form) S form="json"
    204  k listrtn ; start with a clean return
    205  n zsub,zpred,zobj,zgraph,tmprtn
    206  s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of sub
    207  s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of pred
    208  s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of obj
    209  s zgraph=$$IENOF($g(graph),fary) ; ien of graph
    210  I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
    211  n c0xflag,zi,zx,zt
    212  s zt=$na(^C0X(101)) ;
    213  s c0xflag=$$mask(zsub,zpred,zobj) ; get mask flags
    214  k tmprtn
    215  n itbl,ii,ix
    216  s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"OSP") ; no constraint
    217  s itbl("I000",ii)="d zip(.tmprtn,zt,zi)"
    218  s ii=$s(zw="S":"OSP",zw="P":"OPS",zw="O":"OSP") ; obj constraint
    219  s ix=$s(zw="O":"d just(zobj)",1:"d zip1(.tmprtn,zt,zi,zobj)")
    220  s itbl("I001",ii)=ix
    221  s ii=$s(zw="S":"PSO",zw="P":"POS",zw="O":"POS") ; pred constraint
    222  s ix=$s(zw="P":"d just(zpred)",1:"d zip1(.tmprtn,zt,zi,zpred)")
    223  s itbl("I010",ii)=ix
    224  s ii=$s(zw="S":"POS",zw="P":"OPS",zw="O":"OSP") ; pred + obj constraint
    225  s ix=$s(zw="S":"d zip2(.tmprtn,zt,zi,zpred,zobj)",zw="P":"d just(zpred)",zw="O":"d just(zobj)",1:"d just(zobj)")
    226  s itbl("I011",ii)=ix
    227  s ii=$s(zw="S":"SPO",zw="P":"SPO",zw="O":"SOP") ; sub constraint
    228  s ix=$s(zw="S":"d just(zsub)",1:"d zip1(.tmprtn,zt,zi,zsub)")
    229  s itbl("I100",ii)=ix
    230  s ii=$s(zw="S":"SPO",zw="P":"SOP",zw="O":"OSP") ; sub + obj constraint
    231  s ix=$s(zw="P":"d zip2(.tmprtn,zt,zi,zsub,zobj)",zw="S":"d just(zsub)",zw="O":"d just(zobj)",1:"d just(zobj)")
    232  s itbl("I101",ii)=ix
    233  s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"SPO") ; sub + pred constraint
    234  s ix=$s(zw="O":"d zip2(.tmprtn,zt,zi,zsub,zpred)",zw="S":"d just(zsub)",zw="P":"d just(zpred)",1:"d just(zsub)")
    235  s itbl("I110",ii)=ix
    236  s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"OSP") ; sub + pred + obj constraint
    237  s ix=$s(zw="O":"d just(zobj)",zw="S":"d just(zsub)",zw="P":"d just(zpred)",1:"d just(zsub)")
    238  s itbl("I111",ii)=ix
    239  ; end itbl definition
    240  ;
    241  s zi=$o(itbl(c0xflag,"")) ; find index to use
    242  s zx=itbl(c0xflag,zi) ; executable instruction to run
    243  ;i $g(ngraph)'="" s zi="G"_zi ; this is wrong.. don't do graphs yet
    244  i $g(DEBUG) w !,c0xflag," ",zw," ",zt," ",zi," ",zx,!
    245  ;zwr itbl
    246  x zx
    247  k listrtn
    248  d strings(.listrtn,"tmprtn") ; convert pointer to strings
    249  q
    250  ;
    251 just(zin) ; add one element to tmprtn
    252  s tmprtn(zin)=""
    253  q
    254  ;
    255 zip(zrtn,zt,zi) ; pull out just the first element of the index
    256  ;
    257  n zii s zii=""
    258  f  s zii=$o(@zt@(zi,zii)) q:zii=""  d  ;
    259  . s zrtn(zii)=""
    260  q
    261  ;
    262 zip1(zrtn,zt,zi,zn) ; pull out just the first element of the index
    263  ;
    264  n zii s zii=""
    265  f  s zii=$o(@zt@(zi,zn,zii)) q:zii=""  d  ;
    266  . s zrtn(zii)=""
    267  q
    268  ;
    269 zip2(zrtn,zt,zi,zn,zn1) ; pull out just the first element of the index
    270  ;
    271  n zii s zii=""
    272  f  s zii=$o(@zt@(zi,zn,zn1,zii)) q:zii=""  d  ;
    273  . s zrtn(zii)=""
    274  q
    275  ;
    276 arrayout(rtn,zary) ; output an array of triples
    277  ;
    278  s zrsub=""
    279  s zcnt=1
    280  f  s zrsub=$o(zary(zrsub)) q:zrsub=""  d  ; organized by subject
    281  . s zzz=""
    282  . f  s zzz=$o(zary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
    283  . . s rtn(zcnt)=zrsub_"^"_zzz
    284  . . s zcnt=zcnt+1
    285  q
    286  ;
    287 rawout(rtn,zary) ; output a mumps array of triples
    288  ;
    289  s zrsub=""
    290  ;s zcnt=1
    291  f  s zrsub=$o(zary(zrsub)) q:zrsub=""  d  ; organized by subject
    292  . s zzz=""
    293  . f  s zzz=$o(zary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
    294  . . s rtn(zrsub,$p(zzz,"^",1))=$p(zzz,"^",2)
    295  . . ;s zcnt=zcnt+1
    296  q
    297  ;
    298 strings(zrary,zinary) ; convert pointers to strings
    299  ;
    300  k zrary
    301  n zzz s zzz=""
    302  f  s zzz=$o(@zinary@(zzz)) q:zzz=""  d  ;
    303  . n zs
    304  . ;s zs=$$GET1^DIQ(C0XSFN,zzz_",",.01)
    305  . s zs=$$NSP^C0XUTIL(zzz) ; get namespaced string
    306  . q:zs=""
    307  . s zrary(zs)="" ;
    308  q
    309  ;
    310 ien2tary(zrary,zinary) ; zinary is an array of iens passed by name
    311  ; zrary is passed by reference and is return array of triples
    312  ; format zrary(zsub,"zpred^zobj")=""
    313  ;
    314  k zrary ; start out clean
    315  n zzz,zrsub,zrpred,zrobj,zgraph,zcnt
    316  s zzz=""
    317  f  s zzz=$o(@zinary@(zzz)) q:zzz=""  d  ;
    318  . s zrsub=$$GET1^DIQ(C0XTFN,zzz_",",.03,"E")
    319  . s zrpred=$$GET1^DIQ(C0XTFN,zzz_",",.04,"E")
    320  . s zrobj=$$GET1^DIQ(C0XTFN,zzz_",",.05,"E")
    321  . s zrgraph=$$GET1^DIQ(C0XTFN,zzz_",",.02,"E")
    322  . s zrary(zrsub,zrpred_"^"_zrobj)=""
    323  q
    324  ;
    325 jsonout(jout,zary) ;
    326  d REPLYSTART^FMQLJSON("jout")
    327  d LISTSTART^FMQLJSON("jout","results")
    328  n zi s zi=""
    329  f  s zi=$o(zary(zi)) q:zi=""  d  ; for each subject
    330  . n zii s zii=""
    331  . D DICTSTART^FMQLJSON("jout",zi)
    332  . f  s zii=$o(zary(zi,zii)) q:zii=""  d  ; for each pred^obj pair
    333  . . d DASSERT^FMQLJSON("jout",$p(zii,"^",1),$p(zii,"^",2))
    334  . D DICTEND^FMQLJSON("jout")
    335  d LISTEND^FMQLJSON("jout")
    336  d REPLYEND^FMQLJSON("jout")
    337  q
    338  ;
    339 mask(zsub,zpred,zobj) ; function to return mask information
    340  ; about the inputs ie I100 for just a subject and no pred or obj
    341  n zf1,zf2,zf3,zflag
    342  s zf1=$s($g(zsub)="":0,1:1)
    343  s zf2=$s($g(zpred)="":0,1:1)
    344  s zf3=$s($g(zobj)="":0,1:1)
    345  s zflag="I"_zf1_zf2_zf3
    346  q zflag
    347  ;
    348 trip(triprtn,nsub,npred,nobj,ngraph,fary) ; returns triples iens
    349  ; nsub,npred,nobj are all optional
    350  ; graf is also optional, and will limit the search to a particular ngraph
    351  ; fary is which triple store (not implemented yet)
    352  n c0xflag,zi,zx,zt
    353  s zt=$na(^C0X(101)) ;
    354  s c0xflag=$$mask(nsub,npred,nobj) ; get mask flags
    355  n itbl
    356  s itbl("I000","SPO")="d do3(.triprtn,zt,zi)"
    357  s itbl("I001","OSP")="d do2(.triprtn,zt,zi,nobj)"
    358  s itbl("I010","PSO")="d do2(.triprtn,zt,zi,npred)"
    359  s itbl("I011","POS")="d do1(.triprtn,zt,zi,npred,nobj)"
    360  s itbl("I100","SPO")="d do2(.triprtn,zt,zi,nsub)"
    361  s itbl("I101","SOP")="d do1(.triprtn,zt,zi,nsub,nobj)"
    362  s itbl("I110","SPO")="d do1(.triprtn,zt,zi,nsub,npred)"
    363  s itbl("I111","SPO")="d do0(.triprtn,zt,zi,nsub,npred,nobj)"
    364  s zi=$o(itbl(c0xflag,""))
    365  s zx=itbl(c0xflag,zi) ; executable instruction to run
    366  i $g(ngraph)'="" s zi="G"_zi
    367  i $g(DEBUG) w !,zx
    368  x zx
    369  q
    370  ;
    371 do0(dortn,zt,zi,z1,z2,z3)
    372  ; looking for only one triple
    373  n zz
    374  s zz=$o(@zt@(zi,z1,z2,z3,""))
    375  i zz'="" s dortn(zz)=""
    376  q
    377  ;
    378 do1(dortn,zt,zi,z1,z2) ; have 2, looking for one
    379  n zr,zx1
    380  s zx1=""
    381  f  s zx1=$o(@zt@(zi,z1,z2,zx1)) q:zx1=""  d  ;
    382  . s zr=$o(@zt@(zi,z1,z2,zx1,""))
    383  . s dortn(zr)=""
    384  q
    385  ;
    386 do2(dortn,zt,zi,z1) ; have one, looking for 2
    387  n zr,zx1,zx2
    388  s (zx1,zx2)=""
    389  f  s zx1=$o(@zt@(zi,z1,zx1)) q:zx1=""  d  ;
    390  . f  s zx2=$o(@zt@(zi,z1,zx1,zx2)) q:zx2=""  d  ;
    391  . . s zr=$o(@zt@(zi,z1,zx1,zx2,""))
    392  . . s dortn(zr)=""
    393  q
    394  ;
    395 do3(dortn,zt,zi) ; have none, looking for three
    396  n zr,zx1,zx2,zx3
    397  s (zx1,zx2,zx3)=""
    398  f  s zx1=$o(@zt@(zi,zx1)) q:zx1=""  d  ;
    399  . f  s zx2=$o(@zt@(zi,zx1,zx2)) q:zx2=""  d  ;
    400  . . f  s zx3=$o(@zt@(zi,zx1,zx2,zx3)) q:zx3=""  d  ;
    401  . . . s zr=$o(@zt@(zi,zx1,zx2,zx3,""))
    402  . . . s dortn(zr)=""
    403  q
    404  ;
    405 IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
    406  I '$D(FARY) D  ;
    407  . D INITFARY^C0XF2N("C0XFARY")
    408  . S FARY="C0XFARY"
    409  N ZIEN
    410  I $G(ZSTRING)="" Q "" ; NO STRING
    411  S ZIEN=$O(@C0XSN@("B",$$EXT^C0XUTIL(ZSTRING),""))
    412  I ZIEN="" S ZIEN=-1
    413  Q ZIEN
    414  ;
    415 IENOFA(ZOUTARY,INARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
    416  ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)=""
    417  I '$D(FARY) D  ;
    418  . D INITFARY^C0XF2N("C0XFARY")
    419  . S FARY="C0XFARY"
    420  K ZOUTARY ; START WITH CLEAN RESULTS
    421  K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
    422  I '$D(C0XVOC) D VOCINIT^C0XUTIL
    423  N ZINARY
    424  N ZI S ZI=""
    425  F  S ZI=$O(INARY(ZI)) Q:ZI=""  D  ;
    426  . N ZK
    427  . S ZK=$O(INARY(ZI,""))
    428  . S ZINARY($$EXT^C0XUTIL(ZI),$$EXT^C0XUTIL(ZK))=""
    429  N ZV,ZIEN
    430  N ZCNT S ZCNT=0
    431  F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; LOOK FOR MISSING STRINGS
    432  . S ZV=$O(ZINARY(ZI,""))
    433  . I ZV["^" S ZV=$TR(ZV,"^","|")
    434  F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; NOW GET ALL IENS
    435  . S ZV=$O(ZINARY(ZI,""))
    436  . I ZV["^" S ZV=$TR(ZV,"^","|")
    437  . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW
    438  . I ZIEN="" S ZOUTARY("IEN",ZI)=""
    439  . E  S ZOUTARY("IEN",ZI,ZIEN)=""
    440  Q
    441  ;
    442 output(zwhat,zfname,zdir) ; function to write an array to a host file
    443  ; if zdir is ommitted, will output to the CCR directory
    444  ; ^TMP("C0CCCR","ODIR")
    445  ; if fname is ommitted, will output yyyy-mm-dd-hh-mm-ss-C0XOUT.out
    446  ; zwhat is passed by name
    447  ;
    448  i '$d(zdir) s zdir=$G(^TMP("C0CCCR","ODIR"))
    449  i '$d(zfname) d  ;
    450  . s zfname=$$FMTE^XLFDT($$NOW^XLFDT,7)
    451  . s zfname=$tr(zfname,"/","-")
    452  . s zfname=$tr(zfname,"@","-")
    453  . s zfname=$tr(zfname,":","-")
    454  . s zfname=zfname_".out"
    455  i $e(zwhat,1,1)'="^" d  ; not a global
    456  . k ^TMP("C0XOUT",$J)
    457  . m ^TMP("C0XOUT",$J)=@zwhat
    458  . s zwhat=$na(^TMP("C0XOUT",$J,1))
    459  n zout s zout=""
    460  s zout=$$OUTPUT^C0CXPATH(zwhat,zfname,zdir)
    461  K ^TMP("C0XOUT",$J)
    462  Q zout
    463  ;
    464 tagText(ztag) ; extrinsic which returns the location of the text
    465  ; associated with ztag
    466  n zs,zo
    467  s zs=$$subject("fmts:fileTag",ztag)
    468  i zs="" d  q "" ;
    469  . w !,"error, tag is either missing or there are more than one ",ztag
    470  s zo=$$object(zs,"fmts:fileSource")
    471  i zo="" d  q "" ;
    472  . w !,"error, tag source not found ",zs
    473  w !,zo
    474  q $$WHERETXT^C0XF2N(zo)
    475  ;
    476 tagRoot(ztag) ; extrinsic which returns the root for graphs and subjects
    477  ; associated with ztag
    478  n zs,zo
    479  s zs=$$subject("fmts:fileTag",ztag)
    480  i zs="" d  q "" ;
    481  . w !,"error, tag is either missing or there are more than one ",ztag
    482  s zo=$$object(zs,"fmts:root")
    483  i zo="" d  q "" ;
    484  . w !,"error, root not found ",zs
    485  ;w !,zo
    486  q zo
    487  ;
     1C0XGET1 ; GPL - Fileman Triples entry point routine ;1/12/12  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     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        ;
     22LSSUBJ(RTN,ZSUBJ,C0XFARY)       ; LIST NODES WITH SUBJECT ZSUBJ
     23        ;
     24        I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
     25        D USEFARY^C0XF2N("C0XFARY")
     26        Q
     27        ;
     28graph(sub,pred,obj,form,fary)   ; extrinsic which returns a graph name
     29        I '$D(fary) D  ;
     30        . S fary="C0XFARY"
     31        . D INITFARY^C0XF2N(fary)
     32        D USEFARY^C0XF2N(fary)
     33        k triplertn ; start with a clean return
     34        n zsub,zpred,zobj,zgraph,tmprtn
     35        s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
     36        s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of predicate
     37        s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of object
     38        s zgraph=$$IENOF($g(graph),fary) ; ien of graph
     39        I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
     40        d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
     41        n ztmp
     42        d trip(.ztmp,$g(sub),$g(pred),$g(obj),"",$g(fary))
     43        n zi,zg,zrtn
     44        s zi=$o(tmprtn(""))
     45        s zg=$$GET1^DIQ(C0XTFN,zi,.02,"E") ;
     46        i zg="" q ""
     47        s zrtn=zg
     48        i $o(tmprtn(zi))'="" d 
     49        . s zrtn=""
     50        q zrtn
     51        ;
     52GRAPHS(RTN,C0XFARY)     ; LIST ALL GRAPHS
     53        ;
     54        I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
     55        D USEFARY^C0XF2N("C0XFARY")
     56        N ZI S ZI=""
     57        F  S ZI=$O(@C0XTN@("G",ZI)) Q:ZI=""  D  ;
     58        . S RTN(ZI,$$STR(ZI))=""
     59        Q
     60        ;
     61STR(ZIN,C0XFARY)        ; EXTRINSIC RETURNS A STRING
     62        I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
     63        Q $$GET1^DIQ(C0XSFN,ZIN,.01,"E")
     64        ;
     65SPO(ZRTN,ZNODE,C0XFARY) 
     66        I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
     67        N ZI S ZI=$$NXT(.ZRTN)
     68        S ZRTN(ZI,"S")=$$S(ZNODE)
     69        S ZRTN(ZI,"P")=$$P(ZNODE)
     70        S ZRTN(ZI,"O")=$$O(ZNODE)
     71        Q
     72        ;
     73S(ZNODE,C0XFARY)        ; EXTRINSIC RETURNING THE SUBJECT
     74        Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.03,"I")) ;
     75        ;
     76P(ZNODE,C0XFARY)        ; EXTRINSIC RETURNING THE PREDICATE
     77        Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.04,"I")) ;
     78        ;
     79O(ZNODE,C0XFARY)        ; EXTRINSIC RETURNING THE OBJECT
     80        Q $$STR($$GET1^DIQ(C0XTFN,ZNODE,.05,"I")) ;
     81        ;
     82NXT(ZRTN)       ;EXTRINSIC FOR THE NEXT NODE IN ARRAY ZRTN, PASSED BY REF
     83        I '$D(ZRTN) S ZRTN=""
     84        Q $O(ZRTN(""),-1)+1
     85        ;
     86SING(ZRTN,ZG)   ; SUBJECTS IN GRAPH
     87        ;
     88        I '$D(C0XFARY) D INITFARY^C0XF2N("C0XFARY")
     89        I '$D(ZRTN) S ZRTN=""
     90        N ZI,ZN S ZI=""
     91        F  S ZI=$O(@C0XTN@("GSPO",ZG,ZI)) Q:ZI=""  D  ;
     92        . S ZRTN($$NXT(.ZRTN),"S")=$$STR(ZI)
     93        Q
     94        ;
     95qparse(qrtn,zquery)     ; parses the query
     96        ; want this to be able to handle the WHERE clause of SPARQL eventually
     97        ;
     98        n q1,q2,q3,qq
     99        ;s qq=$tr(zquery,"  ","^")
     100        s qq=query ; really want to remove whitespace here
     101        s q1=$p(qq," ",1)
     102        i q1["?" s q1=""
     103        s q2=$p(qq," ",2)
     104        i q2["?" s q2=""
     105        s q3=$p(qq," ",3)
     106        i q3["?" s q3=""
     107        s qrtn(1)=q1_"^"_q2_"^"_q3 ; more lines to come later
     108        q
     109        ;
     110getGraph(zrtn,zgrf,form)        ; get all triples in graph zgrf
     111        ; forms planned: "rdf" "json" "array" "turtle" "triples" "raw"
     112        ; forms supported: "rdf" "json" "array" "raw"
     113        I '$D(form) S form="rdf"
     114        N ZIENS,ZTRIP
     115        D TING^C0XF2N(.ZIENS,zgrf)
     116        I '$D(ZIENS) Q  ;
     117        D ien2tary(.ZTRIP,"ZIENS")
     118        I form="json" d jsonout(.zrtn,.ZTRIP) q  ; what follows is else
     119        i form="rdf" d rdfout^C0XRDF(.zrtn,.ZTRIP) q  ;
     120        i form="array" d arrayout^C0XGET1(.zrtn,.ZTRIP) q  ;
     121        i form="raw" d rawout^C0XGET1(.zrtn,.ZTRIP) q  ;
     122        W !,"Form not supported: ",form
     123        Q
     124        ;
     125rpctrip(rtn,query,limit,offset) ; rpc to access triples with a query
     126        ;
     127        n zoff,zlim,zcount,zq
     128        k rtn
     129        i '$d(limit) s limit=250
     130        i '$d(offset) s offset=0
     131        d qparse(.zq,query) ; parse the query
     132        n qsub,qpred,qobj,qtmp
     133        W !,zq(1)
     134        s qsub=$p(zq(1),"^",1)
     135        s qpred=$p(zq(1),"^",2)
     136        s qobj=$p(zq(1),"^",3)
     137        d triples(.qtmp,qsub,qpred,qobj)
     138        f zcount=offset+1:1:offset+limit q:'$d(qtmp(zcount))  d  ;
     139        . s rtn(zcount)=qtmp(zcount)
     140        q
     141        ;
     142triples(triplertn,sub,pred,obj,graph,form,fary) ; returns triples
     143        I '$D(fary) D  ;
     144        . D INITFARY^C0XF2N("C0XFARY")
     145        . S fary="C0XFARY"
     146        D USEFARY^C0XF2N(fary)
     147        I '$D(form) S form="json"
     148        k triplertn ; start with a clean return
     149        n zsub,zpred,zobj,zgraph,tmprtn
     150        s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
     151        s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of predicate
     152        s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of object
     153        s zgraph=$$IENOF($g(graph),fary) ; ien of graph
     154        I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
     155        d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
     156        d ien2tary(.zrary,"tmprtn") ; convert to triples
     157        ;
     158        i form="json" d jsonout(.triplertn,.zrary) q  ; what follows is 'else'
     159        i form="rdf" d rdfout^C0XRDF(.triplertn,.zrary) q  ;
     160        i form="array" d arrayout(.triplertn,.zrary) q  ;
     161        i form="raw" d rawout(.triplertn,.zrary) q  ;
     162        w !,"form not supported: ",form
     163        q
     164        ;
     165subjects(listrtn,pred,obj,graph,form,fary)      ; return list of subjects
     166        d onelist("S",,$g(pred),$g(obj),$g(fary)) ;subjects
     167        q
     168        ;
     169subject(pred,obj,graph,form,fary)       ; extrinsic which returns the first
     170        ; multiple of return from subjects - returns null if more than one
     171        ; subjects(.G,sub,pred)
     172        ; G("nodeID:1234") ==> "nodeID:1234"
     173        n zin,zrtn
     174        d subjects(.zin,$g(pred),$g(obj),$g(form),$g(fary))
     175        s zrtn=$o(zin(""))
     176        i $o(zin(zrtn))'="" s zrtn=""
     177        q zrtn
     178        ;
     179preds(listrtn,sub,obj,graph,form,fary)  ; return list of subjects
     180        d onelist("P",$g(sub),,$g(obj),$g(fary)) ;subjects
     181        q
     182        ;
     183objects(listrtn,sub,pred,graph,form,fary)       ; return list of subjects
     184        d onelist("O",$g(sub),$g(pred),"",$g(fary)) ;subjects
     185        q
     186        ;
     187object(sub,pred,graph,form,fary)        ; extrinsic which returns the first
     188        ; multiple of return from objects - returns null if more than one
     189        ; objects(.G,sub,pred)
     190        ; G("location") ==> "location"
     191        n zin,zrtn
     192        d objects(.zin,$g(sub),$g(pred),$g(form),$g(fary))
     193        s zrtn=$o(zin(""))
     194        i $o(zin(zrtn))'="" s zrtn=""
     195        q zrtn
     196        ;
     197onelist(zw,sub,pred,obj,fary)   ; returns list
     198        ; zw is S P or O depending on what should be returned
     199        I $g(fary)="" D  ;
     200        . D INITFARY^C0XF2N("C0XFARY")
     201        . S fary="C0XFARY"
     202        D USEFARY^C0XF2N(fary)
     203        I '$D(form) S form="json"
     204        k listrtn ; start with a clean return
     205        n zsub,zpred,zobj,zgraph,tmprtn
     206        s zsub=$$IENOF($$EXT^C0XUTIL($g(sub)),fary) ; ien of sub
     207        s zpred=$$IENOF($$EXT^C0XUTIL($g(pred)),fary) ; ien of pred
     208        s zobj=$$IENOF($$EXT^C0XUTIL($g(obj)),fary) ; ien of obj
     209        s zgraph=$$IENOF($g(graph),fary) ; ien of graph
     210        I $G(DEBUG) W !,"s:",zsub," p:",zpred," o:",zobj
     211        n c0xflag,zi,zx,zt
     212        s zt=$na(^C0X(101)) ;
     213        s c0xflag=$$mask(zsub,zpred,zobj) ; get mask flags
     214        k tmprtn
     215        n itbl,ii,ix
     216        s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"OSP") ; no constraint
     217        s itbl("I000",ii)="d zip(.tmprtn,zt,zi)"
     218        s ii=$s(zw="S":"OSP",zw="P":"OPS",zw="O":"OSP") ; obj constraint
     219        s ix=$s(zw="O":"d just(zobj)",1:"d zip1(.tmprtn,zt,zi,zobj)")
     220        s itbl("I001",ii)=ix
     221        s ii=$s(zw="S":"PSO",zw="P":"POS",zw="O":"POS") ; pred constraint
     222        s ix=$s(zw="P":"d just(zpred)",1:"d zip1(.tmprtn,zt,zi,zpred)")
     223        s itbl("I010",ii)=ix
     224        s ii=$s(zw="S":"POS",zw="P":"OPS",zw="O":"OSP") ; pred + obj constraint
     225        s ix=$s(zw="S":"d zip2(.tmprtn,zt,zi,zpred,zobj)",zw="P":"d just(zpred)",zw="O":"d just(zobj)",1:"d just(zobj)")
     226        s itbl("I011",ii)=ix
     227        s ii=$s(zw="S":"SPO",zw="P":"SPO",zw="O":"SOP") ; sub constraint
     228        s ix=$s(zw="S":"d just(zsub)",1:"d zip1(.tmprtn,zt,zi,zsub)")
     229        s itbl("I100",ii)=ix
     230        s ii=$s(zw="S":"SPO",zw="P":"SOP",zw="O":"OSP") ; sub + obj constraint
     231        s ix=$s(zw="P":"d zip2(.tmprtn,zt,zi,zsub,zobj)",zw="S":"d just(zsub)",zw="O":"d just(zobj)",1:"d just(zobj)")
     232        s itbl("I101",ii)=ix
     233        s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"SPO") ; sub + pred constraint
     234        s ix=$s(zw="O":"d zip2(.tmprtn,zt,zi,zsub,zpred)",zw="S":"d just(zsub)",zw="P":"d just(zpred)",1:"d just(zsub)")
     235        s itbl("I110",ii)=ix
     236        s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"OSP") ; sub + pred + obj constraint
     237        s ix=$s(zw="O":"d just(zobj)",zw="S":"d just(zsub)",zw="P":"d just(zpred)",1:"d just(zsub)")
     238        s itbl("I111",ii)=ix
     239        ; end itbl definition
     240        ;
     241        s zi=$o(itbl(c0xflag,"")) ; find index to use
     242        s zx=itbl(c0xflag,zi) ; executable instruction to run
     243        ;i $g(ngraph)'="" s zi="G"_zi ; this is wrong.. don't do graphs yet
     244        i $g(DEBUG) w !,c0xflag," ",zw," ",zt," ",zi," ",zx,!
     245        ;zwr itbl
     246        x zx
     247        k listrtn
     248        d strings(.listrtn,"tmprtn") ; convert pointer to strings
     249        q
     250        ;
     251just(zin)       ; add one element to tmprtn
     252        s tmprtn(zin)=""
     253        q
     254        ;
     255zip(zrtn,zt,zi) ; pull out just the first element of the index
     256        ;
     257        n zii s zii=""
     258        f  s zii=$o(@zt@(zi,zii)) q:zii=""  d  ;
     259        . s zrtn(zii)=""
     260        q
     261        ;
     262zip1(zrtn,zt,zi,zn)     ; pull out just the first element of the index
     263        ;
     264        n zii s zii=""
     265        f  s zii=$o(@zt@(zi,zn,zii)) q:zii=""  d  ;
     266        . s zrtn(zii)=""
     267        q
     268        ;
     269zip2(zrtn,zt,zi,zn,zn1) ; pull out just the first element of the index
     270        ;
     271        n zii s zii=""
     272        f  s zii=$o(@zt@(zi,zn,zn1,zii)) q:zii=""  d  ;
     273        . s zrtn(zii)=""
     274        q
     275        ;
     276arrayout(rtn,zary)      ; output an array of triples
     277        ;
     278        s zrsub=""
     279        s zcnt=1
     280        f  s zrsub=$o(zary(zrsub)) q:zrsub=""  d  ; organized by subject
     281        . s zzz=""
     282        . f  s zzz=$o(zary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
     283        . . s rtn(zcnt)=zrsub_"^"_zzz
     284        . . s zcnt=zcnt+1
     285        q
     286        ;
     287rawout(rtn,zary)        ; output a mumps array of triples
     288        ;
     289        s zrsub=""
     290        ;s zcnt=1
     291        f  s zrsub=$o(zary(zrsub)) q:zrsub=""  d  ; organized by subject
     292        . s zzz=""
     293        . f  s zzz=$o(zary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
     294        . . s rtn(zrsub,$p(zzz,"^",1))=$p(zzz,"^",2)
     295        . . ;s zcnt=zcnt+1
     296        q
     297        ;
     298strings(zrary,zinary)   ; convert pointers to strings
     299        ;
     300        k zrary
     301        n zzz s zzz=""
     302        f  s zzz=$o(@zinary@(zzz)) q:zzz=""  d  ;
     303        . n zs
     304        . ;s zs=$$GET1^DIQ(C0XSFN,zzz_",",.01)
     305        . s zs=$$NSP^C0XUTIL(zzz) ; get namespaced string
     306        . q:zs=""
     307        . s zrary(zs)="" ;
     308        q
     309        ;
     310ien2tary(zrary,zinary)  ; zinary is an array of iens passed by name
     311        ; zrary is passed by reference and is return array of triples
     312        ; format zrary(zsub,"zpred^zobj")=""
     313        ;
     314        k zrary ; start out clean
     315        n zzz,zrsub,zrpred,zrobj,zgraph,zcnt
     316        s zzz=""
     317        f  s zzz=$o(@zinary@(zzz)) q:zzz=""  d  ;
     318        . s zrsub=$$GET1^DIQ(C0XTFN,zzz_",",.03,"E")
     319        . s zrpred=$$GET1^DIQ(C0XTFN,zzz_",",.04,"E")
     320        . s zrobj=$$GET1^DIQ(C0XTFN,zzz_",",.05,"E")
     321        . s zrgraph=$$GET1^DIQ(C0XTFN,zzz_",",.02,"E")
     322        . s zrary(zrsub,zrpred_"^"_zrobj)=""
     323        q
     324        ;
     325jsonout(jout,zary)      ;
     326        d REPLYSTART^FMQLJSON("jout")
     327        d LISTSTART^FMQLJSON("jout","results")
     328        n zi s zi=""
     329        f  s zi=$o(zary(zi)) q:zi=""  d  ; for each subject
     330        . n zii s zii=""
     331        . D DICTSTART^FMQLJSON("jout",zi)
     332        . f  s zii=$o(zary(zi,zii)) q:zii=""  d  ; for each pred^obj pair
     333        . . d DASSERT^FMQLJSON("jout",$p(zii,"^",1),$p(zii,"^",2))
     334        . D DICTEND^FMQLJSON("jout")
     335        d LISTEND^FMQLJSON("jout")
     336        d REPLYEND^FMQLJSON("jout")
     337        q
     338        ;
     339mask(zsub,zpred,zobj)   ; function to return mask information
     340        ; about the inputs ie I100 for just a subject and no pred or obj
     341        n zf1,zf2,zf3,zflag
     342        s zf1=$s($g(zsub)="":0,1:1)
     343        s zf2=$s($g(zpred)="":0,1:1)
     344        s zf3=$s($g(zobj)="":0,1:1)
     345        s zflag="I"_zf1_zf2_zf3
     346        q zflag
     347        ;
     348trip(triprtn,nsub,npred,nobj,ngraph,fary)       ; returns triples iens
     349        ; nsub,npred,nobj are all optional
     350        ; graf is also optional, and will limit the search to a particular ngraph
     351        ; fary is which triple store (not implemented yet)
     352        n c0xflag,zi,zx,zt
     353        s zt=$na(^C0X(101)) ;
     354        s c0xflag=$$mask(nsub,npred,nobj) ; get mask flags
     355        n itbl
     356        s itbl("I000","SPO")="d do3(.triprtn,zt,zi)"
     357        s itbl("I001","OSP")="d do2(.triprtn,zt,zi,nobj)"
     358        s itbl("I010","PSO")="d do2(.triprtn,zt,zi,npred)"
     359        s itbl("I011","POS")="d do1(.triprtn,zt,zi,npred,nobj)"
     360        s itbl("I100","SPO")="d do2(.triprtn,zt,zi,nsub)"
     361        s itbl("I101","SOP")="d do1(.triprtn,zt,zi,nsub,nobj)"
     362        s itbl("I110","SPO")="d do1(.triprtn,zt,zi,nsub,npred)"
     363        s itbl("I111","SPO")="d do0(.triprtn,zt,zi,nsub,npred,nobj)"
     364        s zi=$o(itbl(c0xflag,""))
     365        s zx=itbl(c0xflag,zi) ; executable instruction to run
     366        i $g(ngraph)'="" s zi="G"_zi
     367        i $g(DEBUG) w !,zx
     368        x zx
     369        q
     370        ;
     371do0(dortn,zt,zi,z1,z2,z3)       
     372        ; looking for only one triple
     373        n zz
     374        s zz=$o(@zt@(zi,z1,z2,z3,""))
     375        i zz'="" s dortn(zz)=""
     376        q
     377        ;
     378do1(dortn,zt,zi,z1,z2)  ; have 2, looking for one
     379        n zr,zx1
     380        s zx1=""
     381        f  s zx1=$o(@zt@(zi,z1,z2,zx1)) q:zx1=""  d  ;
     382        . s zr=$o(@zt@(zi,z1,z2,zx1,""))
     383        . s dortn(zr)=""
     384        q
     385        ;
     386do2(dortn,zt,zi,z1)     ; have one, looking for 2
     387        n zr,zx1,zx2
     388        s (zx1,zx2)=""
     389        f  s zx1=$o(@zt@(zi,z1,zx1)) q:zx1=""  d  ;
     390        . f  s zx2=$o(@zt@(zi,z1,zx1,zx2)) q:zx2=""  d  ;
     391        . . s zr=$o(@zt@(zi,z1,zx1,zx2,""))
     392        . . s dortn(zr)=""
     393        q
     394        ;
     395do3(dortn,zt,zi)        ; have none, looking for three
     396        n zr,zx1,zx2,zx3
     397        s (zx1,zx2,zx3)=""
     398        f  s zx1=$o(@zt@(zi,zx1)) q:zx1=""  d  ;
     399        . f  s zx2=$o(@zt@(zi,zx1,zx2)) q:zx2=""  d  ;
     400        . . f  s zx3=$o(@zt@(zi,zx1,zx2,zx3)) q:zx3=""  d  ;
     401        . . . s zr=$o(@zt@(zi,zx1,zx2,zx3,""))
     402        . . . s dortn(zr)=""
     403        q
     404        ;
     405IENOF(ZSTRING,FARY)     ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
     406        I '$D(FARY) D  ;
     407        . D INITFARY^C0XF2N("C0XFARY")
     408        . S FARY="C0XFARY"
     409        N ZIEN
     410        I $G(ZSTRING)="" Q "" ; NO STRING
     411        S ZIEN=$O(@C0XSN@("B",$$EXT^C0XUTIL(ZSTRING),""))
     412        I ZIEN="" S ZIEN=-1
     413        Q ZIEN
     414        ;
     415IENOFA(ZOUTARY,INARY,FARY)      ; RESOLVE STRINGS TO IEN IN STRINGS FILE
     416        ; RETURNS IN ZOUTARY OF THE FORM ZOUTARY("IEN","VAR",IEN)=""
     417        I '$D(FARY) D  ;
     418        . D INITFARY^C0XF2N("C0XFARY")
     419        . S FARY="C0XFARY"
     420        K ZOUTARY ; START WITH CLEAN RESULTS
     421        K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
     422        I '$D(C0XVOC) D VOCINIT^C0XUTIL
     423        N ZINARY
     424        N ZI S ZI=""
     425        F  S ZI=$O(INARY(ZI)) Q:ZI=""  D  ;
     426        . N ZK
     427        . S ZK=$O(INARY(ZI,""))
     428        . S ZINARY($$EXT^C0XUTIL(ZI),$$EXT^C0XUTIL(ZK))=""
     429        N ZV,ZIEN
     430        N ZCNT S ZCNT=0
     431        F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; LOOK FOR MISSING STRINGS
     432        . S ZV=$O(ZINARY(ZI,""))
     433        . I ZV["^" S ZV=$TR(ZV,"^","|")
     434        F  S ZI=$O(ZINARY(ZI)) Q:ZI=""  D  ; NOW GET ALL IENS
     435        . S ZV=$O(ZINARY(ZI,""))
     436        . I ZV["^" S ZV=$TR(ZV,"^","|")
     437        . S ZIEN=$O(@C0XSN@("B",ZV,"")) ; THEY SHOULD BE THERE NOW
     438        . I ZIEN="" S ZOUTARY("IEN",ZI)=""
     439        . E  S ZOUTARY("IEN",ZI,ZIEN)=""
     440        Q
     441        ;
     442output(zwhat,zfname,zdir)       ; function to write an array to a host file
     443        ; if zdir is ommitted, will output to the CCR directory
     444        ; ^TMP("C0CCCR","ODIR")
     445        ; if fname is ommitted, will output yyyy-mm-dd-hh-mm-ss-C0XOUT.out
     446        ; zwhat is passed by name
     447        ;
     448        i '$d(zdir) s zdir=$G(^TMP("C0CCCR","ODIR"))
     449        i '$d(zfname) d  ;
     450        . s zfname=$$FMTE^XLFDT($$NOW^XLFDT,7)
     451        . s zfname=$tr(zfname,"/","-")
     452        . s zfname=$tr(zfname,"@","-")
     453        . s zfname=$tr(zfname,":","-")
     454        . s zfname=zfname_".out"
     455        i $e(zwhat,1,1)'="^" d  ; not a global
     456        . k ^TMP("C0XOUT",$J)
     457        . m ^TMP("C0XOUT",$J)=@zwhat
     458        . s zwhat=$na(^TMP("C0XOUT",$J,1))
     459        n zout s zout=""
     460        s zout=$$OUTPUT^C0CXPATH(zwhat,zfname,zdir)
     461        K ^TMP("C0XOUT",$J)
     462        Q zout
     463        ;
     464tagText(ztag)   ; extrinsic which returns the location of the text
     465        ; associated with ztag
     466        n zs,zo
     467        s zs=$$subject("fmts:fileTag",ztag)
     468        i zs="" d  q "" ;
     469        . w !,"error, tag is either missing or there are more than one ",ztag
     470        s zo=$$object(zs,"fmts:fileSource")
     471        i zo="" d  q "" ;
     472        . w !,"error, tag source not found ",zs
     473        w !,zo
     474        q $$WHERETXT^C0XF2N(zo)
     475        ;
     476tagRoot(ztag)   ; extrinsic which returns the root for graphs and subjects
     477        ; associated with ztag
     478        n zs,zo
     479        s zs=$$subject("fmts:fileTag",ztag)
     480        i zs="" d  q "" ;
     481        . w !,"error, tag is either missing or there are more than one ",ztag
     482        s zo=$$object(zs,"fmts:root")
     483        i zo="" d  q "" ;
     484        . w !,"error, root not found ",zs
     485        ;w !,zo
     486        q zo
     487        ;
  • fmts/trunk/p/C0XINIT.m

    r1365 r1539  
    1 C0XINIT ; GPL - Fileman Triples initialization routine ;10/13/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    4  ;General Public License See attached copy of the License.
    5  ;
    6  ;This program is free software; you can redistribute it and/or modify
    7  ;it under the terms of the GNU General Public License as published by
    8  ;the Free Software Foundation; either version 2 of the License, or
    9  ;(at your option) any later version.
    10  ;
    11  ;This program is distributed in the hope that it will be useful,
    12  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  ;GNU General Public License for more details.
    15  ;
    16  ;You should have received a copy of the GNU General Public License along
    17  ;with this program; if not, write to the Free Software Foundation, Inc.,
    18  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    19  ;
    20  Q
    21  ;
    22 CLEAR ; DELETE THE FILESTORE
    23  K ^C0X(101)
    24  K ^C0X(201)
    25  S ^C0X(101,0)="C0X TRIPLE^172.101I^^"
    26  S ^C0X(201,0)="C0X STRING^172.201I^^"
    27  Q
    28  ;
    29 INIT ; INITIALIZE THE TRIPLE STORE - THIS DELETES THE GLOBALS AND
    30  ; START ALL OVER... USE WITH CAUTION
    31  ;
    32  ; -- we should be more sophisticated here.. at least warn the user
    33  ; -- and give them a chance to cancel
    34  ;
    35  D CLEAR ; DELETE THE TRIPLESTORE
    36  ;
    37  ; -- we are assuming that FARY is set up properly in C0XF2N
    38  ; -- with repect to the default directory and the defaut fileman files
    39  ; -- here's what it is now: "/home/vista/gpl/fmts/trunk/samples/"
    40  ; -- that means that all the sample files will look like:
    41  ; --- qds/QDS_0001.rdf
    42  ; --- smart-rdf-in/small.rdf
    43  ;
    44  S FARY="C0XFARY"
    45  D INITFARY^C0XF2N(FARY)
    46  D USEFARY^C0XF2N(FARY)
    47  S C0XFARY("C0XDIR")="/home/vista/gpl/fmts/trunk/samples/smart-rdf-in/" ;
    48  D USEFARY^C0XF2N(FARY)
    49  S SMART(1)="cole-susan.rdf"
    50  S SMART(2)="jones-cynthia.rdf"
    51  S SMART(3)="small.rdf"
    52  S SMART(4)="collins-frank.rdf"
    53  S SMART(5)="kelly-david.rdf"
    54  S SMART(6)="smith-maria.rdf"
    55  S SMART(7)="ford-shirley.rdf"
    56  S SMART(8)="morgan-jason.rdf"
    57  S SMART(9)="west-lisa.rdf"
    58  S SMART(10)="gracia-paul.rdf"
    59  S SMART(11)="reed-richard.rdf"
    60  S SMART(12)="west-sandra.rdf"
    61  S SMART(13)="jackson-jessica.rdf"
    62  S SMART(14)="small-allergies.rdf"
    63  S SMART(15)="white-patricia.rdf"
    64  N ZI S ZI=""
    65  F  S ZI=$O(SMART(ZI)) Q:ZI=""  D  ; for each smart file
    66  . D IMPORT^C0XF2N(SMART(ZI),C0XDIR,,FARY) ; import to the triplestore
    67  S FARY="C0XFARY"
    68  S C0XFARY("C0XDIR")="/home/vista/gpl/fmts/trunk/samples/qds/"
    69  D USEFARY^C0XF2N(FARY)
    70  D IMPORT^C0XF2N("QDS_0001.rdf",C0XDIR,,FARY)
    71  D IMPORT^C0XF2N("QDS_0028b.rdf",C0XDIR,,FARY)
    72  D IMPORT^C0XF2N("QDS_0052.rdf",C0XDIR,,FARY)
    73  D IMPORT^C0XF2N("QDS_0073.rdf",C0XDIR,,FARY)
    74  D IMPORT^C0XF2N("QDS_0385.rdf",C0XDIR,,FARY)
    75  D IMPORT^C0XF2N("QDS_0002.rdf",C0XDIR,,FARY)
    76  D IMPORT^C0XF2N("QDS_0031.rdf",C0XDIR,,FARY)
    77  D IMPORT^C0XF2N("QDS_0055.rdf",C0XDIR,,FARY)
    78  D IMPORT^C0XF2N("QDS_0074.rdf",C0XDIR,,FARY)
    79  D IMPORT^C0XF2N("QDS_0387.rdf",C0XDIR,,FARY)
    80  D IMPORT^C0XF2N("QDS_0004.rdf",C0XDIR,,FARY)
    81  D IMPORT^C0XF2N("QDS_0032.rdf",C0XDIR,,FARY)
    82  D IMPORT^C0XF2N("QDS_0056.rdf",C0XDIR,,FARY)
    83  D IMPORT^C0XF2N("QDS_0075.rdf",C0XDIR,,FARY)
    84  D IMPORT^C0XF2N("QDS_0389.rdf",C0XDIR,,FARY)
    85  D IMPORT^C0XF2N("QDS_0012.rdf",C0XDIR,,FARY)
    86  D IMPORT^C0XF2N("QDS_0033.rdf",C0XDIR,,FARY)
    87  D IMPORT^C0XF2N("QDS_0059.rdf",C0XDIR,,FARY)
    88  D IMPORT^C0XF2N("QDS_0081.rdf",C0XDIR,,FARY)
    89  D IMPORT^C0XF2N("QDS_0421.rdf",C0XDIR,,FARY)
    90  D IMPORT^C0XF2N("QDS_0013.rdf",C0XDIR,,FARY)
    91  D IMPORT^C0XF2N("QDS_0034.rdf",C0XDIR,,FARY)
    92  D IMPORT^C0XF2N("QDS_0061.rdf",C0XDIR,,FARY)
    93  D IMPORT^C0XF2N("QDS_0083.rdf",C0XDIR,,FARY)
    94  D IMPORT^C0XF2N("QDS_0575.rdf",C0XDIR,,FARY)
    95  D IMPORT^C0XF2N("QDS_0014.rdf",C0XDIR,,FARY)
    96  D IMPORT^C0XF2N("QDS_0036.rdf",C0XDIR,,FARY)
    97  D IMPORT^C0XF2N("QDS_0062.rdf",C0XDIR,,FARY)
    98  D IMPORT^C0XF2N("QDS_0084.rdf",C0XDIR,,FARY)
    99  D IMPORT^C0XF2N("QDS_0018.rdf",C0XDIR,,FARY)
    100  D IMPORT^C0XF2N("QDS_0038.rdf",C0XDIR,,FARY)
    101  D IMPORT^C0XF2N("QDS_0064.rdf",C0XDIR,,FARY)
    102  D IMPORT^C0XF2N("QDS_0086.rdf",C0XDIR,,FARY)
    103  D IMPORT^C0XF2N("QDS_0024.rdf",C0XDIR,,FARY)
    104  D IMPORT^C0XF2N("QDS_0041.rdf",C0XDIR,,FARY)
    105  D IMPORT^C0XF2N("QDS_0067.rdf",C0XDIR,,FARY)
    106  D IMPORT^C0XF2N("QDS_0088.rdf",C0XDIR,,FARY)
    107  D IMPORT^C0XF2N("QDS_0027.rdf",C0XDIR,,FARY)
    108  D IMPORT^C0XF2N("QDS_0043.rdf",C0XDIR,,FARY)
    109  D IMPORT^C0XF2N("QDS_0068.rdf",C0XDIR,,FARY)
    110  D IMPORT^C0XF2N("QDS_0089.rdf",C0XDIR,,FARY)
    111  D IMPORT^C0XF2N("QDS_0028a.rdf",C0XDIR,,FARY)
    112  D IMPORT^C0XF2N("QDS_0047.rdf",C0XDIR,,FARY)
    113  D IMPORT^C0XF2N("QDS_0070.rdf",C0XDIR,,FARY)
    114  D IMPORT^C0XF2N("QDS_0105.rdf",C0XDIR,,FARY)
    115  ;D IMPORT^C0XF2N("qds.rdf",C0XDIR,,FARY)
    116  Q
    117  ;
     1C0XINIT ; GPL - Fileman Triples initialization routine ;10/13/11  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     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        ;
     22CLEAR   ; DELETE THE FILESTORE
     23        K ^C0X(101)
     24        K ^C0X(201)
     25        S ^C0X(101,0)="C0X TRIPLE^172.101I^^"
     26        S ^C0X(201,0)="C0X STRING^172.201I^^"
     27        Q
     28        ;
     29INIT    ; INITIALIZE THE TRIPLE STORE - THIS DELETES THE GLOBALS AND
     30        ; START ALL OVER... USE WITH CAUTION
     31        ;
     32        ; -- we should be more sophisticated here.. at least warn the user
     33        ; -- and give them a chance to cancel
     34        ;
     35        D CLEAR ; DELETE THE TRIPLESTORE
     36        ;
     37        ; -- we are assuming that FARY is set up properly in C0XF2N
     38        ; -- with repect to the default directory and the defaut fileman files
     39        ; -- here's what it is now: "/home/vista/gpl/fmts/trunk/samples/"
     40        ; -- that means that all the sample files will look like:
     41        ; --- qds/QDS_0001.rdf
     42        ; --- smart-rdf-in/small.rdf
     43        ;
     44        S FARY="C0XFARY"
     45        D INITFARY^C0XF2N(FARY)
     46        D USEFARY^C0XF2N(FARY)
     47        S C0XFARY("C0XDIR")="/home/vista/gpl/fmts/trunk/samples/smart-rdf-in/" ;
     48        D USEFARY^C0XF2N(FARY)
     49        S SMART(1)="cole-susan.rdf"
     50        S SMART(2)="jones-cynthia.rdf"
     51        S SMART(3)="small.rdf"
     52        S SMART(4)="collins-frank.rdf"
     53        S SMART(5)="kelly-david.rdf"
     54        S SMART(6)="smith-maria.rdf"
     55        S SMART(7)="ford-shirley.rdf"
     56        S SMART(8)="morgan-jason.rdf"
     57        S SMART(9)="west-lisa.rdf"
     58        S SMART(10)="gracia-paul.rdf"
     59        S SMART(11)="reed-richard.rdf"
     60        S SMART(12)="west-sandra.rdf"
     61        S SMART(13)="jackson-jessica.rdf"
     62        S SMART(14)="small-allergies.rdf"
     63        S SMART(15)="white-patricia.rdf"
     64        N ZI S ZI=""
     65        F  S ZI=$O(SMART(ZI)) Q:ZI=""  D  ; for each smart file
     66        . D IMPORT^C0XF2N(SMART(ZI),C0XDIR,,FARY) ; import to the triplestore
     67        S FARY="C0XFARY"
     68        S C0XFARY("C0XDIR")="/home/vista/gpl/fmts/trunk/samples/qds/"
     69        D USEFARY^C0XF2N(FARY)
     70        D IMPORT^C0XF2N("QDS_0001.rdf",C0XDIR,,FARY)
     71        D IMPORT^C0XF2N("QDS_0028b.rdf",C0XDIR,,FARY)
     72        D IMPORT^C0XF2N("QDS_0052.rdf",C0XDIR,,FARY)
     73        D IMPORT^C0XF2N("QDS_0073.rdf",C0XDIR,,FARY)
     74        D IMPORT^C0XF2N("QDS_0385.rdf",C0XDIR,,FARY)
     75        D IMPORT^C0XF2N("QDS_0002.rdf",C0XDIR,,FARY)
     76        D IMPORT^C0XF2N("QDS_0031.rdf",C0XDIR,,FARY)
     77        D IMPORT^C0XF2N("QDS_0055.rdf",C0XDIR,,FARY)
     78        D IMPORT^C0XF2N("QDS_0074.rdf",C0XDIR,,FARY)
     79        D IMPORT^C0XF2N("QDS_0387.rdf",C0XDIR,,FARY)
     80        D IMPORT^C0XF2N("QDS_0004.rdf",C0XDIR,,FARY)
     81        D IMPORT^C0XF2N("QDS_0032.rdf",C0XDIR,,FARY)
     82        D IMPORT^C0XF2N("QDS_0056.rdf",C0XDIR,,FARY)
     83        D IMPORT^C0XF2N("QDS_0075.rdf",C0XDIR,,FARY)
     84        D IMPORT^C0XF2N("QDS_0389.rdf",C0XDIR,,FARY)
     85        D IMPORT^C0XF2N("QDS_0012.rdf",C0XDIR,,FARY)
     86        D IMPORT^C0XF2N("QDS_0033.rdf",C0XDIR,,FARY)
     87        D IMPORT^C0XF2N("QDS_0059.rdf",C0XDIR,,FARY)
     88        D IMPORT^C0XF2N("QDS_0081.rdf",C0XDIR,,FARY)
     89        D IMPORT^C0XF2N("QDS_0421.rdf",C0XDIR,,FARY)
     90        D IMPORT^C0XF2N("QDS_0013.rdf",C0XDIR,,FARY)
     91        D IMPORT^C0XF2N("QDS_0034.rdf",C0XDIR,,FARY)
     92        D IMPORT^C0XF2N("QDS_0061.rdf",C0XDIR,,FARY)
     93        D IMPORT^C0XF2N("QDS_0083.rdf",C0XDIR,,FARY)
     94        D IMPORT^C0XF2N("QDS_0575.rdf",C0XDIR,,FARY)
     95        D IMPORT^C0XF2N("QDS_0014.rdf",C0XDIR,,FARY)
     96        D IMPORT^C0XF2N("QDS_0036.rdf",C0XDIR,,FARY)
     97        D IMPORT^C0XF2N("QDS_0062.rdf",C0XDIR,,FARY)
     98        D IMPORT^C0XF2N("QDS_0084.rdf",C0XDIR,,FARY)
     99        D IMPORT^C0XF2N("QDS_0018.rdf",C0XDIR,,FARY)
     100        D IMPORT^C0XF2N("QDS_0038.rdf",C0XDIR,,FARY)
     101        D IMPORT^C0XF2N("QDS_0064.rdf",C0XDIR,,FARY)
     102        D IMPORT^C0XF2N("QDS_0086.rdf",C0XDIR,,FARY)
     103        D IMPORT^C0XF2N("QDS_0024.rdf",C0XDIR,,FARY)
     104        D IMPORT^C0XF2N("QDS_0041.rdf",C0XDIR,,FARY)
     105        D IMPORT^C0XF2N("QDS_0067.rdf",C0XDIR,,FARY)
     106        D IMPORT^C0XF2N("QDS_0088.rdf",C0XDIR,,FARY)
     107        D IMPORT^C0XF2N("QDS_0027.rdf",C0XDIR,,FARY)
     108        D IMPORT^C0XF2N("QDS_0043.rdf",C0XDIR,,FARY)
     109        D IMPORT^C0XF2N("QDS_0068.rdf",C0XDIR,,FARY)
     110        D IMPORT^C0XF2N("QDS_0089.rdf",C0XDIR,,FARY)
     111        D IMPORT^C0XF2N("QDS_0028a.rdf",C0XDIR,,FARY)
     112        D IMPORT^C0XF2N("QDS_0047.rdf",C0XDIR,,FARY)
     113        D IMPORT^C0XF2N("QDS_0070.rdf",C0XDIR,,FARY)
     114        D IMPORT^C0XF2N("QDS_0105.rdf",C0XDIR,,FARY)
     115        ;D IMPORT^C0XF2N("qds.rdf",C0XDIR,,FARY)
     116        Q
     117        ;
  • fmts/trunk/p/C0XMAIN.m

    r1343 r1539  
    1 C0XMAIN ; GPL - Fileman Triples entry point routine ;10/13/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    4  ;General Public License See attached copy of the License.
    5  ;
    6  ;This program is free software; you can redistribute it and/or modify
    7  ;it under the terms of the GNU General Public License as published by
    8  ;the Free Software Foundation; either version 2 of the License, or
    9  ;(at your option) any later version.
    10  ;
    11  ;This program is distributed in the hope that it will be useful,
    12  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  ;GNU General Public License for more details.
    15  ;
    16  ;You should have received a copy of the GNU General Public License along
    17  ;with this program; if not, write to the Free Software Foundation, Inc.,
    18  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    19  ;
    20  Q
    21  ;
    22 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        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     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/C0XRDF.m

    r1499 r1539  
    1 C0XRDF ; GPL - Fileman Triples RDF out  ;11/07/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2012 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 REPLYSTART(ZARY);
    23  D ADD(ZARY,"<?xml version=""1.0"" encoding=""UTF-8""?>")
    24  D ADD(ZARY,"<rdf:RDF xmlns:rdf=""http://www.w3.org/1999/02/22-rdf-syntax-ns#"">")
    25  Q
    26  ;
    27 LISTSTART(ZARY,ZNAM)
    28  Q
    29  ;
    30 DICTSTART(ZARY,ZSUB)
    31  I ZSUB["http" D  Q  ;
    32  . D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
    33  I $E(ZSUB,1,1)="/" D  Q  ;
    34  . D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
    35  D ADD(ZARY,"<rdf:Description rdf:nodeID="""_ZSUB_""">")
    36  Q
    37  ;
    38 DASSERT(ZARY,ZPRED,ZOBJ)
    39  I ZPRED[":" D  Q  ;
    40  . I ZPRED="rdf:type" D  Q  ;
    41  . . D ADD(ZARY,"<rdf:type rdf:resource="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
    42  . N ZA,ZB,ZC
    43  . S ZA=$P(ZPRED,":",1)
    44  . S ZB=$P(ZPRED,":",2)
    45  . I $E(ZB,1,1)="/" D  ;
    46  . . S ZB=$P(ZB,"/",2) ; handling gpltest:/note situations
    47  . S ZC=C0XVOC(ZA)
    48  . I ZOBJ["nodeID:" D  Q  ;
    49  . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:nodeID="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
    50  . S ZOBJ=$$EXT^C0XUTIL(ZOBJ)
    51  . I ZOBJ["http" D  Q  ;
    52  . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:resource="""_ZOBJ_"""/>")
    53  . I $E(ZOBJ,1,1)="/" D  Q  ;
    54  . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:resource="""_ZOBJ_"""/>")
    55  . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""">"_$$EXT^C0XUTIL(ZOBJ)_"</"_ZB_">")
    56  Q
    57  ;
    58 DICTEND(ZARY)
    59  D ADD(ZARY,"</rdf:Description>")
    60  Q
    61  ;
    62 LISTEND(ZARY)
    63  Q
    64  ;
    65 REPLYEND(ZARY)
    66  D ADD(ZARY,"</rdf:RDF>")
    67  Q
    68  ;
    69 ADD(ZARY,ZELE)
    70  N ZI
    71  I '$D(ZARY) S @ZARY@(1)=ZELE Q  ;
    72  S ZI=$O(@ZARY@(""),-1)
    73  S @ZARY@(ZI+1)=ZELE
    74  Q
    75  ;
    76 rdfout(rdfout,zary) ;
    77  d REPLYSTART("rdfout")
    78  d LISTSTART("rdfout","results")
    79  n zi s zi=""
    80  f  s zi=$o(zary(zi)) q:zi=""  d  ; for each subject
    81  . n zii s zii=""
    82  . D DICTSTART("rdfout",$$EXT^C0XUTIL(zi))
    83  . f  s zii=$o(zary(zi,zii)) q:zii=""  d  ; for each pred^obj pair
    84  . . d DASSERT("rdfout",$p(zii,"^",1),$p(zii,"^",2))
    85  . D DICTEND("rdfout")
    86  d LISTEND("rdfout")
    87  d REPLYEND("rdfout")
    88  q
    89  ;
     1C0XRDF  ; GPL - Fileman Triples RDF out  ;11/07/11  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     3        ;Copyright 2012 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        ;
     22REPLYSTART(ZARY);       
     23        D ADD(ZARY,"<?xml version=""1.0"" encoding=""UTF-8""?>")
     24        D ADD(ZARY,"<rdf:RDF xmlns:rdf=""http://www.w3.org/1999/02/22-rdf-syntax-ns#"">")
     25        Q
     26        ;
     27LISTSTART(ZARY,ZNAM)   
     28        Q
     29        ;
     30DICTSTART(ZARY,ZSUB)   
     31        I ZSUB["http" D  Q  ;
     32        . D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
     33        I $E(ZSUB,1,1)="/" D  Q  ;
     34        . D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
     35        D ADD(ZARY,"<rdf:Description rdf:nodeID="""_ZSUB_""">")
     36        Q
     37        ;
     38DASSERT(ZARY,ZPRED,ZOBJ)       
     39        I ZPRED[":" D  Q  ;
     40        . I ZPRED="rdf:type" D  Q  ;
     41        . . D ADD(ZARY,"<rdf:type rdf:resource="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
     42        . N ZA,ZB,ZC
     43        . S ZA=$P(ZPRED,":",1)
     44        . S ZB=$P(ZPRED,":",2)
     45        . I $E(ZB,1,1)="/" D  ;
     46        . . S ZB=$P(ZB,"/",2) ; handling gpltest:/note situations
     47        . S ZC=C0XVOC(ZA)
     48        . I ZOBJ["nodeID:" D  Q  ;
     49        . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:nodeID="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
     50        . S ZOBJ=$$EXT^C0XUTIL(ZOBJ)
     51        . I ZOBJ["http" D  Q  ;
     52        . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:resource="""_ZOBJ_"""/>")
     53        . I $E(ZOBJ,1,1)="/" D  Q  ;
     54        . . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""" rdf:resource="""_ZOBJ_"""/>")
     55        . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""">"_$$EXT^C0XUTIL(ZOBJ)_"</"_ZB_">")
     56        Q
     57        ;
     58DICTEND(ZARY)   
     59        D ADD(ZARY,"</rdf:Description>")
     60        Q
     61        ;
     62LISTEND(ZARY)   
     63        Q
     64        ;
     65REPLYEND(ZARY) 
     66        D ADD(ZARY,"</rdf:RDF>")
     67        Q
     68        ;
     69ADD(ZARY,ZELE) 
     70        N ZI
     71        I '$D(ZARY) S @ZARY@(1)=ZELE Q  ;
     72        S ZI=$O(@ZARY@(""),-1)
     73        S @ZARY@(ZI+1)=ZELE
     74        Q
     75        ;
     76rdfout(rdfout,zary)     ;
     77        d REPLYSTART("rdfout")
     78        d LISTSTART("rdfout","results")
     79        n zi s zi=""
     80        f  s zi=$o(zary(zi)) q:zi=""  d  ; for each subject
     81        . n zii s zii=""
     82        . D DICTSTART("rdfout",$$EXT^C0XUTIL(zi))
     83        . f  s zii=$o(zary(zi,zii)) q:zii=""  d  ; for each pred^obj pair
     84        . . d DASSERT("rdfout",$p(zii,"^",1),$p(zii,"^",2))
     85        . D DICTEND("rdfout")
     86        d LISTEND("rdfout")
     87        d REPLYEND("rdfout")
     88        q
     89        ;
  • fmts/trunk/p/C0XTEST.m

    r1343 r1539  
    1 C0XTEST ; 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  ;
    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        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     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

    r1343 r1539  
    1 C0XTESTKSB ; GPL - Fileman Triples bulk load tester ;11/6/11  17:05
    2  ; KSB - modified to fix a minor bug and to use;;;;;Build 7
    3  ;       high resolution time if routines available ; 11/19/11 1410 EST
    4  ;;0.1;C0X;nopatch;noreleasedate;Build 1
    5  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    6  ;General Public License See attached copy of the License.
    7  ;
    8  ;This program is free software; you can redistribute it and/or modify
    9  ;it under the terms of the GNU General Public License as published by
    10  ;the Free Software Foundation; either version 2 of the License, or
    11  ;(at your option) any later version.
    12  ;
    13  ;This program is distributed in the hope that it will be useful,
    14  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  ;GNU General Public License for more details.
    17  ;
    18  ;You should have received a copy of the GNU General Public License along
    19  ;with this program; if not, write to the Free Software Foundation, Inc.,
    20  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    21  ;
    22  Q
    23  ;
    24 EN ; run the test
    25  ;
    26  k C0XFDA ; clear the node variable
    27  s U="^"  ; initialization - Bhaskar 20111119
    28  i '$d(^C0X(101,0)) d  ; global doesn't exist
    29  . s ^C0X(101,0)="C0X TRIPLE^172.101^1^1"
    30  n zg
    31  S zg="_:G"_$$LKY9 ; all nodes are in the same graph
    32  n zi
    33  f zi=1:1:10000 d  ; try a test of 10000 nodes
    34  . s C0XFDA(172.101,zi,.01)="N"_$$LKY17 ; node name
    35  . s C0XFDA(172.101,zi,.02)=zg
    36  . s C0XFDA(172.101,zi,.03)=$R(100000)
    37  . s C0XFDA(172.101,zi,.04)=$R(100000)
    38  . s C0XFDA(172.101,zi,.05)=$R(100000)
    39  S C0XST=$$H    ; start of the insertion test
    40  W !,"INSERTION STARTS AT ",$ZDATE(C0XST,"YEAR-MM-DD:24:60:SS"),!
    41  d BULKLOAD(.C0XFDA)
    42  s C0XEND=$$H    ; end of the insertion test
    43  W !,"INSERTION ENDS AT ",$ZDATE(C0XEND,"YEAR-MM-DD:24:60:SS")
    44  S C0XDIFF=(86400*($P(C0XEND,",",1)-$P(C0XST,",",1)))+$P(C0XEND,",",2)-$P(C0XST,",",2)
    45  W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
    46  W !
    47  W:C0XDIFF>0 " APPROXIMATELY ",$FN(10000/C0XDIFF,",",0)," NODES PER SECOND",!
    48  q
    49  ;
    50 LKY9() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
    51  ; UNIQUE NODE AND GRAPH NAMES
    52  N ZN,ZI
    53  S ZN=""
    54  F ZI=1:1:9 D  ;
    55  . S ZN=ZN_$R(10)
    56  Q ZN
    57  ;
    58 LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
    59  ; UNIQUE NODE AND GRAPH NAMES
    60  N ZN,ZI
    61  S ZN=""
    62  F ZI=1:1:17 D  ;
    63  . S ZN=ZN_$R(10)
    64  Q ZN
    65  ;
    66 BULKLOAD(ZBFDA) ; BULK LOADER FOR LOADING TRIPLES INTO FILE 172.101
    67  ; USING GLOBAL SETS INSTEAD OF UPDATE^DIE
    68  ; QUITS IF FILE IS NOT 172.101
    69  ; EXPECTS AN FDA WITHOUT STRINGS FOR THE IENS, STARTING AT 1
    70  ; QUITS IF FIRST ENTRY IS NOT IENS 1
    71  ; ASSUMES THAT THE LAST IENS IS THE COUNT OF ENTRIES
    72  ; ZBFDA IS PASSED BY REFERENCE
    73  ;
    74  ; -- reserves a block of iens from file 172.101 by locking the zero node
    75  ; -- ^C0X(101,0) and adding the count of entries to piece 2 and 3
    76  ; -- then unlocking to minimize the duration of the lock
    77  ;
    78  W !,"USING BULKLOAD"
    79  I '$D(ZBFDA) Q  ; EMPTY FDA
    80  I $O(ZBFDA(""))'=172.101 Q  ; WRONG FILE
    81  N ZCNT,ZP3,ZP4
    82  ; -- find the number of nodes to insert
    83  S ZCNT=$O(ZBFDA(172.101,""),-1)
    84  I ZCNT="" D  Q  ;
    85  . W !,"ERROR IN BULK LOAD - INVALID NODE COUNT"
    86  . B
    87  ; -- lock the zero node and reserve a block of iens to insert
    88  W !,"LOCKING ZERO NODE"
    89  LOCK +^C0X(101,0)
    90  S ZP3=$P(^C0X(101,0),U,3)
    91  S ZP4=$P(^C0X(101,0),U,4)
    92  S $P(^C0X(101,0),U,3)=ZP3+ZCNT+1
    93  S $P(^C0X(101,0),U,4)=ZP4+ZCNT+1
    94  LOCK -^C0X(101,0)
    95  N ZI,ZN,ZG,ZS,ZP,ZO,ZIEN,ZBASE
    96  S ZBASE=ZP3 ; the last ien in the file
    97  W !,"ZERO NODE UNLOCKED, IENS RESERVED=",ZCNT
    98  W !,$ZDATE($$H,"YEAR-MM-DD:24:60:SS")
    99  S ZI=""
    100  F  S ZI=$O(ZBFDA(172.101,ZI)) Q:ZI=""  D  ;
    101  . S ZN=$G(ZBFDA(172.101,ZI,.01)) ; node name
    102  . I ZN="" D BLKERR Q  ;
    103  . S ZG=$G(ZBFDA(172.101,ZI,.02)) ; graph pointer
    104  . I ZG="" D BLKERR Q  ;
    105  . S ZS=$G(ZBFDA(172.101,ZI,.03)) ; subject pointer
    106  . I ZS="" D BLKERR Q  ;
    107  . S ZP=$G(ZBFDA(172.101,ZI,.04)) ; predicate pointer
    108  . I ZP="" D BLKERR Q  ;
    109  . S ZO=$G(ZBFDA(172.101,ZI,.05)) ; object pointer
    110  . I ZO="" D BLKERR Q  ;
    111  . S ZIEN=ZI+ZBASE ; the new ien
    112  . S ^C0X(101,ZIEN,0)=ZN_U_ZG_U_ZS_U_ZP_U_ZO ; set the zero node
    113  . S ^C0X(101,"B",ZN,ZIEN)="" ; the B index
    114  . S ^C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index
    115  . S ^C0X(101,"SPO",ZS,ZP,ZO)=""
    116  . S ^C0X(101,"SOP",ZS,ZO,ZP)=""
    117  . S ^C0X(101,"OPS",ZO,ZP,ZS)=""
    118  . S ^C0X(101,"OSP",ZO,ZS,ZP)=""
    119  . S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS)=""
    120  . S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP)=""
    121  . S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO)=""
    122  . S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO)=""
    123  Q
    124  ;
    125 BLKERR ;
    126  W !,"ERROR IN BULK LOAD",! ZWR ZBFDA(ZI)
    127  B
    128  Q
    129  ;
    130 H()
    131  quit:$length($ztrnlnm("GTMXC_posix"))&$length($text(zhorolog^%POSIX)) $$zhorolog^%POSIX quit $horolog
     1C0XTESTKSB      ; GPL - Fileman Triples bulk load tester ;11/6/11  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012
     3        ; KSB - modified to fix a minor bug and to use;;;;;Build 10
     4        ;       high resolution time if routines available ; 11/19/11 1410 EST
     5        ;;0.1;C0X;nopatch;noreleasedate;Build 1
     6        ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
     7        ;General Public License See attached copy of the License.
     8        ;
     9        ;This program is free software; you can redistribute it and/or modify
     10        ;it under the terms of the GNU General Public License as published by
     11        ;the Free Software Foundation; either version 2 of the License, or
     12        ;(at your option) any later version.
     13        ;
     14        ;This program is distributed in the hope that it will be useful,
     15        ;but WITHOUT ANY WARRANTY; without even the implied warranty of
     16        ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17        ;GNU General Public License for more details.
     18        ;
     19        ;You should have received a copy of the GNU General Public License along
     20        ;with this program; if not, write to the Free Software Foundation, Inc.,
     21        ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     22        ;
     23        Q
     24        ;
     25EN      ; run the test
     26        ;
     27        k C0XFDA ; clear the node variable
     28        s U="^"  ; initialization - Bhaskar 20111119
     29        i '$d(^C0X(101,0)) d  ; global doesn't exist
     30        . s ^C0X(101,0)="C0X TRIPLE^172.101^1^1"
     31        n zg
     32        S zg="_:G"_$$LKY9 ; all nodes are in the same graph
     33        n zi
     34        f zi=1:1:10000 d  ; try a test of 10000 nodes
     35        . s C0XFDA(172.101,zi,.01)="N"_$$LKY17 ; node name
     36        . s C0XFDA(172.101,zi,.02)=zg
     37        . s C0XFDA(172.101,zi,.03)=$R(100000)
     38        . s C0XFDA(172.101,zi,.04)=$R(100000)
     39        . s C0XFDA(172.101,zi,.05)=$R(100000)
     40        S C0XST=$$H    ; start of the insertion test
     41        W !,"INSERTION STARTS AT ",$ZDATE(C0XST,"YEAR-MM-DD:24:60:SS"),!
     42        d BULKLOAD(.C0XFDA)
     43        s C0XEND=$$H    ; end of the insertion test
     44        W !,"INSERTION ENDS AT ",$ZDATE(C0XEND,"YEAR-MM-DD:24:60:SS")
     45        S C0XDIFF=(86400*($P(C0XEND,",",1)-$P(C0XST,",",1)))+$P(C0XEND,",",2)-$P(C0XST,",",2)
     46        W !," ELAPSED TIME: ",C0XDIFF," SECONDS"
     47        W !
     48        W:C0XDIFF>0 " APPROXIMATELY ",$FN(10000/C0XDIFF,",",0)," NODES PER SECOND",!
     49        q
     50        ;
     51LKY9()  ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
     52        ; UNIQUE NODE AND GRAPH NAMES
     53        N ZN,ZI
     54        S ZN=""
     55        F ZI=1:1:9 D  ;
     56        . S ZN=ZN_$R(10)
     57        Q ZN
     58        ;
     59LKY17() ;EXTRINIC THAT RETURNS A RANDOM 9 DIGIT NUMBER. USED FOR GENERATING
     60        ; UNIQUE NODE AND GRAPH NAMES
     61        N ZN,ZI
     62        S ZN=""
     63        F ZI=1:1:17 D  ;
     64        . S ZN=ZN_$R(10)
     65        Q ZN
     66        ;
     67BULKLOAD(ZBFDA) ; BULK LOADER FOR LOADING TRIPLES INTO FILE 172.101
     68        ; USING GLOBAL SETS INSTEAD OF UPDATE^DIE
     69        ; QUITS IF FILE IS NOT 172.101
     70        ; EXPECTS AN FDA WITHOUT STRINGS FOR THE IENS, STARTING AT 1
     71        ; QUITS IF FIRST ENTRY IS NOT IENS 1
     72        ; ASSUMES THAT THE LAST IENS IS THE COUNT OF ENTRIES
     73        ; ZBFDA IS PASSED BY REFERENCE
     74        ;
     75        ; -- reserves a block of iens from file 172.101 by locking the zero node
     76        ; -- ^C0X(101,0) and adding the count of entries to piece 2 and 3
     77        ; -- then unlocking to minimize the duration of the lock
     78        ;
     79        W !,"USING BULKLOAD"
     80        I '$D(ZBFDA) Q  ; EMPTY FDA
     81        I $O(ZBFDA(""))'=172.101 Q  ; WRONG FILE
     82        N ZCNT,ZP3,ZP4
     83        ; -- find the number of nodes to insert
     84        S ZCNT=$O(ZBFDA(172.101,""),-1)
     85        I ZCNT="" D  Q  ;
     86        . W !,"ERROR IN BULK LOAD - INVALID NODE COUNT"
     87        . B
     88        ; -- lock the zero node and reserve a block of iens to insert
     89        W !,"LOCKING ZERO NODE"
     90        LOCK +^C0X(101,0)
     91        S ZP3=$P(^C0X(101,0),U,3)
     92        S ZP4=$P(^C0X(101,0),U,4)
     93        S $P(^C0X(101,0),U,3)=ZP3+ZCNT+1
     94        S $P(^C0X(101,0),U,4)=ZP4+ZCNT+1
     95        LOCK -^C0X(101,0)
     96        N ZI,ZN,ZG,ZS,ZP,ZO,ZIEN,ZBASE
     97        S ZBASE=ZP3 ; the last ien in the file
     98        W !,"ZERO NODE UNLOCKED, IENS RESERVED=",ZCNT
     99        W !,$ZDATE($$H,"YEAR-MM-DD:24:60:SS")
     100        S ZI=""
     101        F  S ZI=$O(ZBFDA(172.101,ZI)) Q:ZI=""  D  ;
     102        . S ZN=$G(ZBFDA(172.101,ZI,.01)) ; node name
     103        . I ZN="" D BLKERR Q  ;
     104        . S ZG=$G(ZBFDA(172.101,ZI,.02)) ; graph pointer
     105        . I ZG="" D BLKERR Q  ;
     106        . S ZS=$G(ZBFDA(172.101,ZI,.03)) ; subject pointer
     107        . I ZS="" D BLKERR Q  ;
     108        . S ZP=$G(ZBFDA(172.101,ZI,.04)) ; predicate pointer
     109        . I ZP="" D BLKERR Q  ;
     110        . S ZO=$G(ZBFDA(172.101,ZI,.05)) ; object pointer
     111        . I ZO="" D BLKERR Q  ;
     112        . S ZIEN=ZI+ZBASE ; the new ien
     113        . S ^C0X(101,ZIEN,0)=ZN_U_ZG_U_ZS_U_ZP_U_ZO ; set the zero node
     114        . S ^C0X(101,"B",ZN,ZIEN)="" ; the B index
     115        . S ^C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index
     116        . S ^C0X(101,"SPO",ZS,ZP,ZO)=""
     117        . S ^C0X(101,"SOP",ZS,ZO,ZP)=""
     118        . S ^C0X(101,"OPS",ZO,ZP,ZS)=""
     119        . S ^C0X(101,"OSP",ZO,ZS,ZP)=""
     120        . S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS)=""
     121        . S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP)=""
     122        . S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO)=""
     123        . S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO)=""
     124        Q
     125        ;
     126BLKERR  ;
     127        W !,"ERROR IN BULK LOAD",! ZWR ZBFDA(ZI)
     128        B
     129        Q
     130        ;
     131H()     
     132        quit:$length($ztrnlnm("GTMXC_posix"))&$length($text(zhorolog^%POSIX)) $$zhorolog^%POSIX quit $horolog
  • fmts/trunk/p/C0XUTIL.m

    r1532 r1539  
    1 C0XUTIL ; GPL - Fileman Triples utilities ;11/07/11  17:05
    2  ;;0.1;C0X;nopatch;noreleasedate;Build 7
    3  ;Copyright 2011 George Lilly.  Licensed under the terms of the GNU
    4  ;General Public License See attached copy of the License.
    5  ;
    6  ;This program is free software; you can redistribute it and/or modify
    7  ;it under the terms of the GNU General Public License as published by
    8  ;the Free Software Foundation; either version 2 of the License, or
    9  ;(at your option) any later version.
    10  ;
    11  ;This program is distributed in the hope that it will be useful,
    12  ;but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  ;GNU General Public License for more details.
    15  ;
    16  ;You should have received a copy of the GNU General Public License along
    17  ;with this program; if not, write to the Free Software Foundation, Inc.,
    18  ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    19  ;
    20  Q
    21  ;
    22 NSP(ZX) ; OUTPUT TRANSFORM EXTRINSIC
    23  ;
    24  N ZR
    25  ; I WOULD REALLY LIKE TO NOT HAVE THE FILE NUMBER HARD CODED HERE
    26  ; ANYONE KNOW HOW I COULD DO THAT?  :) GPL
    27  S ZR=$$GET1^DIQ(172.201,ZX_",",.01)
    28  I '$D(C0XNSP) S C0XNSP=1 ; DEFAULT ON
    29  I C0XNSP=0 Q ZR ; SWITCHED OFF
    30  I '$D(C0XVOC) D VOCINIT ; INITIALIZE THE VOCABULARIES
    31  N ZI,ZJ,ZK S ZI=""
    32  N DONE S DONE=0
    33  F  S ZI=$O(C0XVOC(ZI)) Q:(DONE=1)!(ZI="")  D  ;
    34  . ;W !,ZI
    35  . S ZJ=C0XVOC(ZI)
    36  . S ZK=$P(ZR,ZJ,2)
    37  . ;W !,"ZK=",ZK
    38  . I ZK'="" D  ; BINGO
    39  . . S ZR=ZI_":"_ZK
    40  . . S DONE=1
    41  Q ZR
    42  ;
    43 VOCINIT ; INITIALIZE VOCABULARIES
    44  S C0XVOC("dcterms")="http://purl.org/dc/terms/"
    45  S C0XVOC("rdf")="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    46  S C0XVOC("sp")="http://smartplatforms.org/terms#"
    47  S C0XVOC("qds")="http://cms.gov/pqri/qds/"
    48  S C0XVOC("smart")="http://sandbox-api.smartplatforms.org/records/"
    49  S C0XVOC("snomed")="http://purl.bioontology.org/ontology/SNOMEDCT/"
    50  S C0XVOC("icd9")="http://purl.bioontology.org/ontology/ICD9/"
    51  S C0XVOC("rxnorm")="http://purl.bioontology.org/ontology/RXNORM/"
    52  S C0XVOC("loinc")="http://purl.bioontology.org/ontology/LNC/"
    53  S C0XVOC("file")="/home/glilly/fmts/trunk/samples/"
    54  S C0XVOC("foaf")="http://xmlns.com/foaf/0.1/"
    55  S C0XVOC("skos")="http://www.w3.org/2004/02/skos/core#"
    56  S C0XVOC("gpl")="http://georgetriples.org/"
    57  S C0XVOC("cg")="http://datasets.caregraf.org/"
    58  S C0XVOC("mv")="http://metavista.name/foundation#"
    59  S C0XVOC("rdfs")="http://www.w3.org/2000/01/rdf-schema#"
    60  S C0XVOC("vistaSmart")="https://smart2.vistaewd.net/vista/smart/records/"
    61  S C0XVOC("vmu")="http://vista.org/mu/"
    62  S C0XVOC("vq")="http://vista.org/quality/"
    63  S C0XVOC("nodeID")="iDPsDPss"
    64  S C0XVOC("fmts")="http://glilly.net/fmts#"
    65  S C0XVOC("oro")="http://oro.com/vista/sage" ;change to get URL from system
    66  S C0XVOC("sage")="http://oro.com/sage/schema#"
    67  S C0XVOC("v")="http://www.w3.org/2006/vcard/ns#"
    68  Q
    69  ;
    70 EXT(C0XIN) ; EXTRINSIC WHICH EXPANDS NAMESPACES
    71  ; SO skos:xxx would return http://www.w3.org/2004/02/skos/core#xxx
    72  N C0XPRE
    73  S C0XPRE=C0XIN
    74  I '$D(C0XVOC) D VOCINIT ; INITIALIZE NAME SPACE TABLE
    75  I C0XPRE[":" D  ; expand using vocabulary
    76  . N ZB,ZA
    77  . S ZB=$P(C0XPRE,":",1)
    78  . S ZA=$P(C0XPRE,":",2)
    79  . I $G(C0XVOC(ZB))'="" D  ;
    80  . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
    81  Q C0XPRE
    82  ;
     1C0XUTIL ; GPL - Fileman Triples utilities ;11/07/11  17:05
     2        ;;1.0;FILEMAN TRIPLE STORE;;Sep 26, 2012;Build 10
     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        ;
     22NSP(ZX) ; OUTPUT TRANSFORM EXTRINSIC
     23        ;
     24        N ZR
     25        ; I WOULD REALLY LIKE TO NOT HAVE THE FILE NUMBER HARD CODED HERE
     26        ; ANYONE KNOW HOW I COULD DO THAT?  :) GPL
     27        S ZR=$$GET1^DIQ(172.201,ZX_",",.01)
     28        I '$D(C0XNSP) S C0XNSP=1 ; DEFAULT ON
     29        I C0XNSP=0 Q ZR ; SWITCHED OFF
     30        I '$D(C0XVOC) D VOCINIT ; INITIALIZE THE VOCABULARIES
     31        N ZI,ZJ,ZK S ZI=""
     32        N DONE S DONE=0
     33        F  S ZI=$O(C0XVOC(ZI)) Q:(DONE=1)!(ZI="")  D  ;
     34        . ;W !,ZI
     35        . S ZJ=C0XVOC(ZI)
     36        . S ZK=$P(ZR,ZJ,2)
     37        . ;W !,"ZK=",ZK
     38        . I ZK'="" D  ; BINGO
     39        . . S ZR=ZI_":"_ZK
     40        . . S DONE=1
     41        Q ZR
     42        ;
     43VOCINIT ; INITIALIZE VOCABULARIES
     44        S C0XVOC("dcterms")="http://purl.org/dc/terms/"
     45        S C0XVOC("rdf")="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     46        S C0XVOC("sp")="http://smartplatforms.org/terms#"
     47        S C0XVOC("qds")="http://cms.gov/pqri/qds/"
     48        S C0XVOC("smart")="http://sandbox-api.smartplatforms.org/records/"
     49        S C0XVOC("snomed")="http://purl.bioontology.org/ontology/SNOMEDCT/"
     50        S C0XVOC("icd9")="http://purl.bioontology.org/ontology/ICD9/"
     51        S C0XVOC("rxnorm")="http://purl.bioontology.org/ontology/RXNORM/"
     52        S C0XVOC("loinc")="http://purl.bioontology.org/ontology/LNC/"
     53        S C0XVOC("file")="/home/glilly/fmts/trunk/samples/"
     54        S C0XVOC("foaf")="http://xmlns.com/foaf/0.1/"
     55        S C0XVOC("skos")="http://www.w3.org/2004/02/skos/core#"
     56        S C0XVOC("gpl")="http://georgetriples.org/"
     57        S C0XVOC("cg")="http://datasets.caregraf.org/"
     58        S C0XVOC("mv")="http://metavista.name/foundation#"
     59        S C0XVOC("rdfs")="http://www.w3.org/2000/01/rdf-schema#"
     60        S C0XVOC("vistaSmart")="https://smart2.vistaewd.net/vista/smart/records/"
     61        S C0XVOC("vmu")="http://vista.org/mu/"
     62        S C0XVOC("vq")="http://vista.org/quality/"
     63        S C0XVOC("nodeID")="iDPsDPss"
     64        S C0XVOC("fmts")="http://glilly.net/fmts#"
     65        S C0XVOC("oro")="http://oro.com/vista/sage" ;change to get URL from system
     66        S C0XVOC("sage")="http://oro.com/sage/schema#"
     67        S C0XVOC("v")="http://www.w3.org/2006/vcard/ns#"
     68        Q
     69        ;
     70EXT(C0XIN)      ; EXTRINSIC WHICH EXPANDS NAMESPACES
     71        ; SO skos:xxx would return http://www.w3.org/2004/02/skos/core#xxx
     72        N C0XPRE
     73        S C0XPRE=C0XIN
     74        I '$D(C0XVOC) D VOCINIT ; INITIALIZE NAME SPACE TABLE
     75        I C0XPRE[":" D  ; expand using vocabulary
     76        . N ZB,ZA
     77        . S ZB=$P(C0XPRE,":",1)
     78        . S ZA=$P(C0XPRE,":",2)
     79        . I $G(C0XVOC(ZB))'="" D  ;
     80        . . S C0XPRE=C0XVOC(ZB)_ZA ; expanded
     81        Q C0XPRE
     82        ;
Note: See TracChangeset for help on using the changeset viewer.