changes for getGraph and rdf out
This commit is contained in:
parent
d2cf2f64d3
commit
e69365c76e
34
p/C0XF2N.m
34
p/C0XF2N.m
|
@ -595,6 +595,40 @@ BLKERR ;
|
|||
B
|
||||
Q
|
||||
;
|
||||
DELGRAPH(ZGRF,FARY) ; delete a graph from the triplestore
|
||||
; (doesn't delete strings)
|
||||
;
|
||||
I '$D(FARY) D ;
|
||||
. D INITFARY("C0XFARY")
|
||||
. S FARY="C0XFARY"
|
||||
D USEFARY(FARY)
|
||||
N ZGRAPH
|
||||
D TING(.ZGRAPH,ZGRF,FARY)
|
||||
I '$D(ZGRAPH) D Q ;
|
||||
. W !,"NO TRIPLES IN GRAPH"
|
||||
K C0XFDA
|
||||
N ZI S ZI=""
|
||||
F S ZI=$O(ZGRAPH(ZI)) Q:ZI="" D ;
|
||||
. S C0XFDA(C0XTFN,ZI_",",.01)="@"
|
||||
D UPDIE(.C0XFDA)
|
||||
Q
|
||||
;
|
||||
TING(ZRTN,ZGRF,FARY) ; return the iens for graph ZGRF
|
||||
; ZRTN is passed by reference
|
||||
I '$D(FARY) D ;
|
||||
. D INITFARY("C0XFARY")
|
||||
. S FARY="C0XFARY"
|
||||
D USEFARY(FARY)
|
||||
K ZRTN
|
||||
N ZI,ZG S ZI=""
|
||||
S ZG=$$IENOF(ZGRF)
|
||||
I ZG="" D Q ;
|
||||
. W !,"ERROR GRAPH NOT FOUND"
|
||||
I '$D(@C0XTN@("G",ZG)) Q ;
|
||||
F S ZI=$O(@C0XTN@("G",ZG,ZI)) Q:ZI="" D ;
|
||||
. S ZRTN(ZI)=""
|
||||
Q
|
||||
;
|
||||
SWUPDIE(ZFDA) ; SWITCH BETWEEN UPDIE AND BULKLOAD
|
||||
. I $G(BLKLOAD) D ; bulk load
|
||||
. . D BULKLOAD(.ZFDA) ; bulk load the batch
|
||||
|
|
32
p/C0XGET1.m
32
p/C0XGET1.m
|
@ -83,6 +83,20 @@ qparse(qrtn,zquery) ; parses the query
|
|||
s qrtn(1)=q1_"^"_q2_"^"_q3 ; more lines to come later
|
||||
q
|
||||
;
|
||||
getGraph(zrtn,zgrf,form) ; get all triples in graph zgrf
|
||||
; forms planned: "rdf" "json" "array" "turtle" "triples"
|
||||
; forms supported: "rdf" "json" "array"
|
||||
I '$D(form) S form="rdf"
|
||||
N ZIENS,ZTRIP
|
||||
D TING^C0XF2N(.ZIENS,zgrf)
|
||||
I '$D(ZIENS) Q ;
|
||||
D ien2tary(.ZTRIP,"ZIENS")
|
||||
I form="json" d jsonout(.zrtn,.ZTRIP) q ; what follows is else
|
||||
i form="rdf" d rdfout^C0XRDF(.zrtn,.ZTRIP) q ;
|
||||
i form="array" d arrayout^C0XGET1(.zrtn,.ZTRIP) q ;
|
||||
W !,"Form not supported: ",form
|
||||
Q
|
||||
;
|
||||
rpctrip(rtn,query,limit,offset) ; rpc to access triples with a query
|
||||
;
|
||||
n zoff,zlim,zcount,zq
|
||||
|
@ -100,11 +114,12 @@ rpctrip(rtn,query,limit,offset) ; rpc to access triples with a query
|
|||
. s rtn(zcount)=qtmp(zcount)
|
||||
q
|
||||
;
|
||||
triples(triplertn,sub,pred,obj,graph,fary) ; returns triples
|
||||
triples(triplertn,sub,pred,obj,graph,form,fary) ; returns triples
|
||||
I '$D(fary) D ;
|
||||
. D INITFARY^C0XF2N("C0XFARY")
|
||||
. S fary="C0XFARY"
|
||||
D USEFARY^C0XF2N(fary)
|
||||
I '$D(form) S form="json"
|
||||
k triplertn ; start with a clean return
|
||||
n zsub,zpred,zobj,zgraph,tmprtn
|
||||
s zsub=$$IENOF^C0XF2N($$EXT^C0XUTIL($g(sub)),fary) ; ien of subject
|
||||
|
@ -115,17 +130,20 @@ triples(triplertn,sub,pred,obj,graph,fary) ; returns triples
|
|||
d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
|
||||
d ien2tary(.zrary,"tmprtn") ; convert to triples
|
||||
;
|
||||
d rdfout^C0XRDF(.triplertn,.zrary) q ;
|
||||
i REPLYFMT="JSON" d jsonout(.triplertn,.zrary) q ; what follows is 'else'
|
||||
i form="json" d jsonout(.triplertn,.zrary) q ; what follows is 'else'
|
||||
i form="rdf" d rdfout^C0XRDF(.triplertn,.zrary) q ;
|
||||
i form="array" d arrayout(.triplertn,.zrary) q ;
|
||||
w !,"form not supported: ",form
|
||||
q
|
||||
;
|
||||
; if no reply format is found we just output an array of triples
|
||||
arrayout(rtn,zary) ; output an array of triples
|
||||
;
|
||||
s zrsub=""
|
||||
s zcnt=1
|
||||
f s zrsub=$o(zrary(zrsub)) q:zrsub="" d ; organized by subject
|
||||
f s zrsub=$o(zary(zrsub)) q:zrsub="" d ; organized by subject
|
||||
. s zzz=""
|
||||
. f s zzz=$o(zrary(zrsub,zzz)) q:zzz="" d ; pred and obj
|
||||
. . s triplertn(zcnt)=zrsub_"^"_zzz
|
||||
. f s zzz=$o(zary(zrsub,zzz)) q:zzz="" d ; pred and obj
|
||||
. . s rtn(zcnt)=zrsub_"^"_zzz
|
||||
. . s zcnt=zcnt+1
|
||||
q
|
||||
;
|
||||
|
|
|
@ -38,11 +38,12 @@ DICTSTART(ZARY,ZSUB)
|
|||
DASSERT(ZARY,ZPRED,ZOBJ)
|
||||
I ZPRED[":" D Q ;
|
||||
. I ZPRED="rdf:type" D Q ;
|
||||
. . D ADD(ZARY,"rdf:type rdf:Resource="""_ZOBJ_"""/>")
|
||||
. N ZA,ZB
|
||||
. . D ADD(ZARY,"rdf:type rdf:Resource="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
|
||||
. N ZA,ZB,ZC
|
||||
. S ZA=$P(ZPRED,":",1)
|
||||
. S ZB=$P(ZPRED,":",2)
|
||||
. D ADD(ZARY,"<"_ZA_" xmlns="""_ZB_""">"_ZOBJ_"</"_ZA_">")
|
||||
. S ZC=C0XVOC(ZA)
|
||||
. D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""">"_$$EXT^C0XUTIL(ZOBJ)_"</"_ZB_">")
|
||||
Q
|
||||
;
|
||||
DICTEND(ZARY)
|
||||
|
@ -69,7 +70,7 @@ rdfout(rdfout,zary) ;
|
|||
n zi s zi=""
|
||||
f s zi=$o(zary(zi)) q:zi="" d ; for each subject
|
||||
. n zii s zii=""
|
||||
. D DICTSTART("rdfout",zi)
|
||||
. D DICTSTART("rdfout",$$EXT^C0XUTIL(zi))
|
||||
. f s zii=$o(zary(zi,zii)) q:zii="" d ; for each pred^obj pair
|
||||
. . d DASSERT("rdfout",$p(zii,"^",1),$p(zii,"^",2))
|
||||
. D DICTEND("rdfout")
|
||||
|
|
Loading…
Reference in New Issue