Changeset 1373 for fmts


Ignore:
Timestamp:
Mar 8, 2012, 1:37:26 AM (13 years ago)
Author:
George Lilly
Message:

added subjects query

File:
1 edited

Legend:

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

    r1372 r1373  
    137137 q
    138138 ;
     139subjects(listrtn,sub,pred,obj,graph,form,fary) ; return list of subjects
     140 d onelist("S") ;subjects
     141 q
     142 ;
     143preds(listrtn,sub,pred,obj,graph,form,fary) ; return list of subjects
     144 d onelist("P") ;subjects
     145 q
     146 ;
     147objects(listrtn,sub,pred,obj,graph,form,fary) ; return list of subjects
     148 d onelist("O") ;subjects
     149 q
     150 ;
     151onelist(zw) ; returns list
     152 ; zw is S P or O depending on what should be returned
     153 I '$D(fary) D  ;
     154 . D INITFARY^C0XF2N("C0XFARY")
     155 . S fary="C0XFARY"
     156 D USEFARY^C0XF2N(fary)
     157 I '$D(form) S form="json"
     158 k listrtn ; start with a clean return
     159 n zsub,zpred,zobj,zgraph,tmprtn
     160 s zsub=$$IENOF^C0XF2N($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
     161 s zpred=$$IENOF^C0XF2N($$EXT^C0XUTIL($g(pred)),fary) ; ien of predicate
     162 s zobj=$$IENOF^C0XF2N($$EXT^C0XUTIL($g(obj)),fary) ; ien of object
     163 s zgraph=$$IENOF^C0XF2N($g(graph),fary) ; ien of graph
     164 W !,"s:",zsub," p:",zpred," o:",zobj
     165 n c0xflag,zi,zx,zt
     166 s zt=$na(^C0X(101)) ;
     167 s c0xflag=$$meta(zsub,zpred,zobj) ; get meta flags
     168 k tmprtn
     169 n itbl,ii,ix
     170 s ii=$s(zw="S":"SPO",zw="P":"POS",zw="O":"OSP") ; no constraint
     171 s itbl("I000",ii)="d zip(.tmprtn,zt,zi)"
     172 s ii=$s(zw="S":"OSP",zw="P":"OPS",zw="O":"OSP") ; obj constraint
     173 s ix=$s(zw="O":"s tmprtn(zobj)=""""",1:"d zip1(.tmprtn,zt,zi,zobj)")
     174 s itbl("I001",ii)=ix
     175 s itbl("I010","PSO")="d zip1(.tmprtn,zt,zi,zpred)"
     176 s itbl("I011","POS")="d zip2(.tmprtn,zt,zi,zpred,zobj)"
     177 s itbl("I100","SPO")="d zip(.tmprtn,zt,zi)"
     178 s itbl("I101","OSP")="d zip1(.tmprtn,zt,zi,zobj)"
     179 s itbl("I110","PSO")="d zip1(.tmprtn,zt,zi,zpred)"
     180 s itbl("I111","POS")="d zip2(.tmprtn,zt,zi,zpred,zobj)"
     181 s zi=$o(itbl(c0xflag,""))
     182 s zx=itbl(c0xflag,zi) ; executable instruction to run
     183 i $g(ngraph)'="" s zi="G"_zi
     184 w !,zx
     185 x zx
     186 k listrtn
     187 d strings(.listrtn,"tmprtn") ; convert pointer to strings
     188 q
     189 ;
     190zip(zrtn,zt,zi) ; pull out just the first element of the index
     191 ;
     192 n zii s zii=""
     193 f  s zii=$o(@zt@(zi,zii)) q:zii=""  d  ;
     194 . s zrtn(zii)=""
     195 q
     196 ;
     197zip1(zrtn,zt,zi,zn) ; pull out just the first element of the index
     198 ;
     199 n zii s zii=""
     200 f  s zii=$o(@zt@(zi,zn,zii)) q:zii=""  d  ;
     201 . s zrtn(zii)=""
     202 q
     203 ;
     204zip2(zrtn,zt,zi,zn,zn1) ; pull out just the first element of the index
     205 ;
     206 n zii s zii=""
     207 f  s zii=$o(@zt@(zi,zn,zn1,zii)) q:zii=""  d  ;
     208 . s zrtn(zii)=""
     209 q
     210 ;
    139211arrayout(rtn,zary) ; output an array of triples
    140212 ;
     
    146218 . . s rtn(zcnt)=zrsub_"^"_zzz
    147219 . . s zcnt=zcnt+1
     220 q
     221 ;
     222strings(zrary,zinary) ; convert pointers to strings
     223 ;
     224 k zrary
     225 n zzz s zzz=""
     226 f  s zzz=$o(@zinary@(zzz)) q:zzz=""  d  ;
     227 . n zs
     228 . s zs=$$GET1^DIQ(C0XSFN,zzz_",",.01)
     229 . q:zs=""
     230 . s zrary(zs)=""
    148231 q
    149232 ;
     
    177260 q
    178261 ;
     262meta(zsub,zpred,zobj) ; function to return meta information
     263 ; about the inputs ie I100 for just a subject and no pred or obj
     264 n zf1,zf2,zf3,zflag
     265 s zf1=$s($g(zsub)="":0,1:1)
     266 s zf2=$s($g(zpred)="":0,1:1)
     267 s zf3=$s($g(zobj)="":0,1:1)
     268 s zflag="I"_zf1_zf2_zf3
     269 q zflag
     270 ;
    179271trip(triprtn,nsub,npred,nobj,ngraph,fary) ; returns triples iens
    180272 ; nsub,npred,nobj are all optional
     
    183275 n c0xflag,zi,zx,zt
    184276 s zt=$na(^C0X(101)) ;
    185  n zf1,zf2,zf3
    186  s zf1=$s($g(nsub)="":0,1:1)
    187  s zf2=$s($g(npred)="":0,1:1)
    188  s zf3=$s($g(nobj)="":0,1:1)
    189  s c0xflag="I"_zf1_zf2_zf3
     277 s c0xflag=$$meta(nsub,npred,nobj) ; get meta flags
    190278 n itbl
    191279 s itbl("I000","SPO")="d do3(.triprtn,zt,zi)"
Note: See TracChangeset for help on using the changeset viewer.