Changeset 1368 for fmts/trunk/p


Ignore:
Timestamp:
Feb 27, 2012, 11:51:28 PM (13 years ago)
Author:
George Lilly
Message:

changes for getGraph and rdf out

Location:
fmts/trunk/p
Files:
3 edited

Legend:

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

    r1367 r1368  
    596596 Q
    597597 ;
     598DELGRAPH(ZGRF,FARY) ; delete a graph from the triplestore
     599 ; (doesn't delete strings)
     600 ;
     601 I '$D(FARY) D  ;
     602 . D INITFARY("C0XFARY")
     603 . S FARY="C0XFARY"
     604 D USEFARY(FARY)
     605 N ZGRAPH
     606 D TING(.ZGRAPH,ZGRF,FARY)
     607 I '$D(ZGRAPH) D  Q  ;
     608 . W !,"NO TRIPLES IN GRAPH"
     609 K C0XFDA
     610 N ZI S ZI=""
     611 F  S ZI=$O(ZGRAPH(ZI)) Q:ZI=""  D  ;
     612 . S C0XFDA(C0XTFN,ZI_",",.01)="@"
     613 D UPDIE(.C0XFDA)
     614 Q
     615 ;
     616TING(ZRTN,ZGRF,FARY) ; return the iens for graph ZGRF
     617 ; ZRTN is passed by reference
     618 I '$D(FARY) D  ;
     619 . D INITFARY("C0XFARY")
     620 . S FARY="C0XFARY"
     621 D USEFARY(FARY)
     622 K ZRTN
     623 N ZI,ZG S ZI=""
     624 S ZG=$$IENOF(ZGRF)
     625 I ZG="" D  Q  ;
     626 . W !,"ERROR GRAPH NOT FOUND"
     627 I '$D(@C0XTN@("G",ZG)) Q  ;
     628 F  S ZI=$O(@C0XTN@("G",ZG,ZI)) Q:ZI=""  D  ;
     629 . S ZRTN(ZI)=""
     630 Q
     631 ; 
    598632SWUPDIE(ZFDA) ; SWITCH BETWEEN UPDIE AND BULKLOAD
    599633 . I $G(BLKLOAD) D  ; bulk load
  • fmts/trunk/p/C0XGET1.m

    r1367 r1368  
    8383 s qrtn(1)=q1_"^"_q2_"^"_q3 ; more lines to come later
    8484 q
     85 ;
     86getGraph(zrtn,zgrf,form) ; get all triples in graph zgrf
     87 ; forms planned: "rdf" "json" "array" "turtle" "triples"
     88 ; forms supported: "rdf" "json" "array"
     89 I '$D(form) S form="rdf"
     90 N ZIENS,ZTRIP
     91 D TING^C0XF2N(.ZIENS,zgrf)
     92 I '$D(ZIENS) Q  ;
     93 D ien2tary(.ZTRIP,"ZIENS")
     94 I form="json" d jsonout(.zrtn,.ZTRIP) q  ; what follows is else
     95 i form="rdf" d rdfout^C0XRDF(.zrtn,.ZTRIP) q  ;
     96 i form="array" d arrayout^C0XGET1(.zrtn,.ZTRIP) q  ;
     97 W !,"Form not supported: ",form
     98 Q
    8599 ;
    86100rpctrip(rtn,query,limit,offset) ; rpc to access triples with a query
     
    101115 q
    102116 ;
    103 triples(triplertn,sub,pred,obj,graph,fary) ; returns triples
     117triples(triplertn,sub,pred,obj,graph,form,fary) ; returns triples
    104118 I '$D(fary) D  ;
    105119 . D INITFARY^C0XF2N("C0XFARY")
    106120 . S fary="C0XFARY"
    107121 D USEFARY^C0XF2N(fary)
     122 I '$D(form) S form="json"
    108123 k triplertn ; start with a clean return
    109124 n zsub,zpred,zobj,zgraph,tmprtn
     
    116131 d ien2tary(.zrary,"tmprtn") ; convert to triples
    117132 ;
    118  d rdfout^C0XRDF(.triplertn,.zrary) q  ;
    119  i REPLYFMT="JSON" d jsonout(.triplertn,.zrary) q  ; what follows is 'else'
    120  ;
    121  ; if no reply format is found we just output an array of triples
     133 i form="json" d jsonout(.triplertn,.zrary) q  ; what follows is 'else'
     134 i form="rdf" d rdfout^C0XRDF(.triplertn,.zrary) q  ;
     135 i form="array" d arrayout(.triplertn,.zrary) q ;
     136 w !,"form not supported: ",form
     137 q
     138 ;
     139arrayout(rtn,zary) ; output an array of triples
    122140 ;
    123141 s zrsub=""
    124142 s zcnt=1
    125  f  s zrsub=$o(zrary(zrsub)) q:zrsub=""  d  ; organized by subject
     143 f  s zrsub=$o(zary(zrsub)) q:zrsub=""  d  ; organized by subject
    126144 . s zzz=""
    127  . f  s zzz=$o(zrary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
    128  . . s triplertn(zcnt)=zrsub_"^"_zzz
     145 . f  s zzz=$o(zary(zrsub,zzz)) q:zzz=""  d  ; pred and obj
     146 . . s rtn(zcnt)=zrsub_"^"_zzz
    129147 . . s zcnt=zcnt+1
    130148 q
  • fmts/trunk/p/C0XRDF.m

    r1367 r1368  
    3939 I ZPRED[":" D  Q  ;
    4040 . I ZPRED="rdf:type" D  Q  ;
    41  . . D ADD(ZARY,"rdf:type rdf:Resource="""_ZOBJ_"""/>")
    42  . N ZA,ZB
     41 . . D ADD(ZARY,"rdf:type rdf:Resource="""_$$EXT^C0XUTIL(ZOBJ)_"""/>")
     42 . N ZA,ZB,ZC
    4343 . S ZA=$P(ZPRED,":",1)
    4444 . S ZB=$P(ZPRED,":",2)
    45  . D ADD(ZARY,"<"_ZA_" xmlns="""_ZB_""">"_ZOBJ_"</"_ZA_">")
     45 . S ZC=C0XVOC(ZA)
     46 . D ADD(ZARY,"<"_ZB_" xmlns="""_ZC_""">"_$$EXT^C0XUTIL(ZOBJ)_"</"_ZB_">")
    4647 Q
    4748 ;
     
    7071 f  s zi=$o(zary(zi)) q:zi=""  d  ; for each subject
    7172 . n zii s zii=""
    72  . D DICTSTART("rdfout",zi)
     73 . D DICTSTART("rdfout",$$EXT^C0XUTIL(zi))
    7374 . f  s zii=$o(zary(zi,zii)) q:zii=""  d  ; for each pred^obj pair
    7475 . . d DASSERT("rdfout",$p(zii,"^",1),$p(zii,"^",2))
Note: See TracChangeset for help on using the changeset viewer.